@@ -50,7 +50,6 @@ def __init__(self):
5050 # the controller is needed, it will be enabled.
5151 self .stop_controller_service = rospy .ServiceProxy ('stop' , Empty , persistent = True )
5252 self .start_controller_service = rospy .ServiceProxy ('start' , Empty , persistent = True )
53- #self.stop_controller_service()
5453
5554 # Service for motor speed
5655 self .motors = {}
@@ -113,13 +112,20 @@ def __init__(self):
113112 for sensor in encoder_sensors :
114113 self .encoder_services [sensor ] = rospy .ServiceProxy ('/mirte/get_encoder_' + encoder_sensors [sensor ]["name" ], GetEncoder , persistent = True )
115114
116- # Services for keypad sensores
115+ # Services for keypad sensors
117116 if rospy .has_param ("/mirte/keypad" ):
118117 keypad_sensors = rospy .get_param ("/mirte/keypad" )
119118 self .keypad_services = {}
120119 for sensor in keypad_sensors :
121120 self .keypad_services [sensor ] = rospy .ServiceProxy ('/mirte/get_keypad_' + keypad_sensors [sensor ]["name" ], GetKeypad , persistent = True )
122121
122+ # Services for color sensors
123+ if rospy .has_param ("/mirte/color" ):
124+ color_sensors = rospy .get_param ("/mirte/color" )
125+ self .color_services = {}
126+ for sensor in color_sensors :
127+ self .color_services [sensor ] = rospy .ServiceProxy ('/mirte/get_color_' + color_sensors [sensor ]["name" ], GetColorHSL , persistent = True )
128+
123129 self .get_pin_value_service = rospy .ServiceProxy ('/mirte/get_pin_value' , GetPinValue , persistent = True )
124130 self .set_pin_value_service = rospy .ServiceProxy ('/mirte/set_pin_value' , SetPinValue , persistent = True )
125131
@@ -210,6 +216,19 @@ def getKeypad(self, keypad):
210216 value = self .keypad_services [keypad ]()
211217 return value .data
212218
219+ def getColor (self , sensor ):
220+ """Gets the value of the color sensor.
221+
222+ Parameters:
223+ sensor (str): The name of the sensor as defined in the configuration.
224+
225+ Returns:
226+ {h, s, l}: Hue (0-360), Saturation (0-1), Lightness.
227+ """
228+
229+ value = self .color_services [sensor ]()
230+ return {'h' : value .color .h , 's' : value .color .s , 'l' : value .color .l }
231+
213232 def getAnalogPinValue (self , pin ):
214233 """Gets the input value of an analog pin.
215234
@@ -330,6 +349,24 @@ def setMotorSpeed(self, motor, value):
330349 motor = self .motor_services [motor ](value )
331350 return motor .status
332351
352+ def setMotorControl (self , status ):
353+ """Enables/disables the motor controller. This is enabled on boot, but can
354+ be disabled/enabled at runtime. This makes the ROS control node pause,
355+ so it will not respond to Twist messages anymore when disabled.
356+
357+ Parameters:
358+ status (bool): To which status the motor controller should be set.
359+
360+ Returns:
361+ none
362+ """
363+
364+ if (status ):
365+ self .start_controller_service ()
366+ else :
367+ self .stop_controller_service ()
368+ return
369+
333370 def stop (self ):
334371 """Stops all DC motors defined in the configuration
335372
0 commit comments