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 code777
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 RobotInstance import RobotInstance
16 from Tools import Tools
17
19 '''
20 Class that represents a servo motor.
21 '''
23 '''
24 Creates a servo motor instance and sets it at home position. For most servos:
25 home = 300, inc = 2. Id 0: S12 header, 1: S13 header, 2: S14 header, 3: S15 header.
26 @param id: the id of the motor (0..3)
27 @param home: the PWM duty cycle for the home position (0..4095)
28 @param inc: the increment factor (inc_duty/inc_position)
29 '''
30 self.id = id
31 self.device = "svo" + str(id)
32 robot = RobotInstance.getRobot()
33 self.home = home
34 self.inc = inc
35 if robot == None:
36 RobotInstance._partsToRegister.append(self)
37 else:
38 self._setup(robot)
39
41 robot.sendCommand(self.device + ".create." + str(self.home) + "." + str(self.inc))
42
44 '''
45 Sets the relative position of the servo motor.
46 @param position: the position with respect to home and using the inc_duty/inc_position factor
47 For most servo motors in range -200 .. 200
48 '''
49 self._checkRobot()
50 RobotInstance.getRobot().sendCommand(self.device + ".setPos" + "." + str(position))
51
53 '''
54 Sets the absolute position of the servo motor.
55 @param position: the position in arbitrary units in range 0..4095 (determines PWM duty cycle)
56 For most servo motors in range 100..500
57 '''
58 self._checkRobot()
59 RobotInstance.getRobot().sendCommand(self.device + ".setPosAbs" + "." + str(position))
60
64