Skip to content

Commit 0692726

Browse files
committed
Added ability to enable/disable the ROS controller
1 parent 09342f0 commit 0692726

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

mirte_robot/robot.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 = {}
@@ -330,6 +329,24 @@ def setMotorSpeed(self, motor, value):
330329
motor = self.motor_services[motor](value)
331330
return motor.status
332331

332+
def setMotorControl(self, status):
333+
"""Enables/disables the motor controller. This is enabled on boot, but can
334+
be disabled/enabled at runtime. This makes the ROS control node pause,
335+
so it will not respond to Twist messages anymore when disabled.
336+
337+
Parameters:
338+
status (bool): To which status the motor controller should be set.
339+
340+
Returns:
341+
none
342+
"""
343+
344+
if (status):
345+
self.start_controller_service()
346+
else:
347+
self.stop_controller_service()
348+
return
349+
333350
def stop(self):
334351
"""Stops all DC motors defined in the configuration
335352

0 commit comments

Comments
 (0)