Unit 3 Exercise 3.1 Robot moving after Ctrl+C

Hi,
After running the launch file using roslaunch for the program below, the rbot starts moving. After pressing Ctrl+C, it still keeps moving. I tried to stop it killing the node but it did not work like below:
rosnode kill move_robot
But it did not work. Please help!

The program code:
#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist

rospy.init_node(‘move_robot_node’)
pub = rospy.Publisher(‘/cmd_vel’, Twist, queue_size=1)
rate = rospy.Rate(2)
move = Twist()
move.linear.x = 0.5 #Move the robot with a linear velocity in the x axis
move.angular.z = 0.5 #Move the with an angular velocity in the z axis

while not rospy.is_shutdown():
pub.publish(move)
rate.sleep()

Let me share my thought on it:

You can try to use the “ctrl+z” command. To stop the process using this command, you need to find out the PID number. You can find the PID number using the command “ps faux|grep test process 2”. Here test process 2 is the name of the file/folder which you want to terminate. After that use “kill 2804”. Here 2804 is the PID number. All of this you need to do it in second terminal. After that use command “bg” on the first terminal. Then you can try to use “ctrl+z”

1 Like

When working with simulations, the robot does not stop just because you have stopped the node that was moving it. The robot continues to work on the last “twist” message published to its “command vel”.

To ensure that your robot will stop when the node stops (ROS shutdown), please have a look at this post:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.