Catch ctrl-C and Set value
I am developing a robot and I wrote some programs for that robot. In the robot's motor driving node, I subscribed the topic from /cmd_vel
topic. What the current issue is that when the motor is running and if I terminate the motor driving node with ctrl-C
, the motor is still running.
Is there any way to put the motor values with 0
before terminating the program? I am using ROS melodic
with python
as the following.
#!/usr/bin/env python
import ........
class main():
def __init__(self):
rospy.init_node("robot", anonymous=False)
rospy.Subscriber(..........)
self.pub=rospy.Publisher(..........)
rospy.Timer(rospy.Duration(0.2), self.main_callback)
while not rospy.is_shutdown():
rospy.sleep(0.2)
print("-----------------")
def main_callback(self, event):
......................
motor_1 = 50
....end.....
if __name__="__main__":
try: main()
except rospy.ROSInterruptException: pass
As with this example, some way to set the value motor_1=0
before terminating the node.