Hi,
this is a general question. Is there a way that can make a node stop within coding instead of giving ctrl+c with terminal from outside?
Jialei Li
If I understood correctly, you wanted to stop the robot, so in order to do that thereās no need to stop the node. You just need to publish a Twist message with 0 velocities in linear and angular variables.
In any case, if I didnāt solve your issue, would you mind to be a bit more precise about what you want to do?
In addition to what @ACTISA said, you can also stop the robot whenever ROS is shutting down. Have a look at this post for how to do that.
In general, to stop a robot in your code you just need to create a publisher to the applicable āvelocityā topic and publish a stop message as required in your code.
Hi @ACTISA ,
thanks for your advice. But I apologize that I actually mean how to stop ānodeā with code (sorry about the misleading in title). For example, is there any codes to function exactly the same with ctrl+c from terminal?
Jialei Li
Hi @bayodesegun ,
thanks for that. I made a mistake in titleā¦I actually wonder how to stop a ānodeā with code
Jialei Li
Hello @MeineLiebeAxt , itās fine
In order to stop the node you could use the method signal_shutdown() from rospy library, here is an example of its ussage:
rospy.init_node("node_name")
# do some stuff
if <condition>:
rospy.signal_shutdown('<reason_for_shutdown>')
If Iām not mistaken, I think you could also use a function that when called, it prompts the ctrl_c for you, I think you can check it out on the Lesson where they speak about OOP (Iām not 100% sure of this).
Also, remember that you can kill the node using /kill <node_name> from the terminal.
I hope I have helped you!
Hi,
it works! Thanks a lot for the advice!
Jialei Li
Hello!
Iām glad you solved your issue!
Feel free to ask again if you have any doubt!
Have a nice day.
Ćngel