1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#This python file put up an interface to all other attached hardware equipment
from H3D import *
from H3DInterface import *
from Route import *
import thread
import threading
import pygame
from pygame import locals
#Max drillspeed is set if the button on the haptic unit is pressed (to simulate a Pedal)
#class DrillButton( AutoUpdate( SFBool ) ):
# def update( self, event ):
# button = event.getValue()
# if button==False:
# drillSpeedField.setValue(0)
# vibrationField.setValue(0)
# else:
# drillSpeedField.setValue(drillSpeedMaxField.getValue())
# vibrationField.setValue(1)
# return button
#drillButton = DrillButton()
#Max drillspeed is set if the button on the haptic unit is pressed (to simulate a Pedal)
#The deviceShape is set to 1 if the secondary button is enabled
#class SecondaryDrillButton( AutoUpdate( SFBool ) ):
# def update( self, event ):
# button = event.getValue()
# if button==False:
# drillSpeedField.setValue(0)
# vibrationField.setValue(0)
# deviceShapeField.setValue(0)
# else:
# drillSpeedField.setValue(0)
# vibrationField.setValue(0)
# deviceShapeField.setValue(1)
# return button
#secondaryDrillButton = SecondaryDrillButton()
pygame.init()
class TimerManager(object):
ops = []
def add_operation(self, operation, interval, args=[], kwargs={}):
op = Operation(interval, operation, args, kwargs)
self.ops.append(op)
thread.start_new_thread(op.run, ())
def stop(self):
for op in self.ops:
op.cancel()
self._event.set()
try:
j = pygame.joystick.Joystick(0) # instans av joystick
j.init()
print 'Enabled joystick: ' + j.get_name()
hasPedalField.setValue(True)
#timer = TimerManager()
#timer.add_operation(PedalManager, 0.1)
except pygame.error:
print 'No joystick'
def PedalManager():
#OBS the timer functionality is not used. Instead PedalManager() is called from traverseSG() in StateMachine.py.
#This can and should be moved since the state machine is now in C++ and thus stateManager.py not really used.
for e in pygame.event.get(): # loopa over eventstack
#print 'event : ' + str(e.type)
if e.type == pygame.locals.JOYAXISMOTION: # 7
x , y = j.get_axis(0), j.get_axis(1)
if y < -0.05:
drillSpeedField.setValue(abs(drillSpeedMaxField.getValue()*y))
vibrationField.setValue(1)
elif y > 0.05:
drillSpeedField.setValue(0)
deviceShapeField.setValue(1)
vibrationField.setValue(0)
else:
drillSpeedField.setValue(0)
deviceShapeField.setValue(0)
vibrationField.setValue(0)
pygame.event.clear()
def traverseSG():
#this is only needed for polling the PedalManager. Before this was also used for calling state machine.
if hasPedalField.getValue():
PedalManager()
|