1
2
3
4 '''
5 This software is part of the raspibrick module.
6 It is Open Source Free Software, so you may
7 - run the code for any purpose
8 - study how the code works and adapt it to your needs
9 - integrate all or parts of the code in your own programs
10 - redistribute copies of the code
11 - improve the code and release your improvements to the public
12 However the use of the code is entirely your responsibility.
13 '''
14
15 from Tools import Tools
16 import SharedConstants
17 from RobotInstance import RobotInstance
18
19
25
26
28 '''
29 Class that represents a motor.
30 '''
45
47 robot.sendCommand(self.device + ".create")
48 robot.sendCommand(self.device + ".setSpeed." + str(self.speed))
49 self.robot = robot
50
52 '''
53 Starts the forward rotation with preset speed.
54 The method returns immediately, while the rotation continues.
55 '''
56 self._checkRobot()
57 if self.state == MotorState.FORWARD:
58 return
59 self.robot.sendCommand(self.device + ".forward")
60 self.state = MotorState.FORWARD
61
63 '''
64 Starts the backward rotation with preset speed.
65 The method returns immediately, while the rotation continues.
66 '''
67 self._checkRobot()
68 if self.state == MotorState.BACKWARD:
69 return
70 self.robot.sendCommand(self.device + ".backward")
71 self.state = MotorState.BACKWARD
72
83
85 '''
86 Sets the speed to the given value (arbitrary units).
87 The speed will be changed to the new value at the next movement call only.
88 The speed is limited to 0..100.
89 @param speed: the new speed 0..100
90 '''
92 self._checkRobot()
93 speed = int(speed)
94 if self.speed == speed:
95 return
96 self.speed = speed
97 self.robot.sendCommand(self.device + ".setSpeed." + str(speed))
98 self.state = MotorState.UNDEFINED
99
103