rosserial Arduino not stopping while pressing ctrl +c or ctrl +z
Hello ,i have raspberry pi model 3 b+ in which i run my launch file which contains rosserial commandrosrun rosserial_python serial_node.py _port:=/dev/ttyACM1 _baud:=115200
,rplidar and my node a program for moving my robot forward ,while stopping means while i press ctlr+c or ctlr+z on terminal rosserial wont stop and robot moves continously . is there any solution for stopping rosserial as i see it is only which make robot moving
Asked by kallivalli on 2019-09-25 02:45:05 UTC
Answers
There is a good chance that your problem is caused because the code on your micro controller doesn't terminate when the nodes running on your raspberry pi are shutdown. This is causing your robot to continue moving at the final velocity it was commanded to.
There is a convention and a strong safety reason why you should write your micro-controller code so this is impossible. The serial connection could be lost for many reasons, computer crashes, serial cable unplugged, etc. In all these cases you want your robot to stop moving as quickly as possible.
This is achieved by writing code which sets the target velocity to zero if a cmd_vel
message hasn't been received within a set period of time. If your cmd_vel
topic usually runs at 100 Hz then a half second limit should allow it to ignore brief gaps in messages but also stop quickly enough if the serial connection is lost. Using this approach your robot will always stop whenever the rosserial
node is closed.
Hope this helps.
Asked by PeteBlackerThe3rd on 2019-09-27 03:58:51 UTC
Comments
im having teleop code which uses cmd_vel
and which stops while target velocity is set to zero,i have wall following code using lidar thats the one which dont stop
Asked by kallivalli on 2019-09-27 23:10:10 UTC
Can you clarify two things. using ps -A
can you check if any of your ROS nodes on the pi are not being shutdown? Does your micro controller code stop the robot if it doesn't receive a cmd_vel message after a certain period of time (if not this needs to be added)?
Asked by PeteBlackerThe3rd on 2019-09-28 05:01:57 UTC
ps -A doesn't contain rosserial but the machine is still moving and should I change my code in ros node to do that rather than in microcontroller? like if I press ctrl + c
it should send the d signal to both motors as 0,0 pwm values ?
Asked by kallivalli on 2019-09-30 06:35:28 UTC
No you should change the code on the microcontroller so that if it doesn't receive a cmd_vel
message within half a second it stops all motors. This is very important because you want it to fail safe in a range of situations, not just when you press ctrl + c
Asked by PeteBlackerThe3rd on 2019-09-30 06:40:41 UTC
thank you very much ,i will check on that
Asked by kallivalli on 2019-09-30 06:54:18 UTC
Comments
Are you sure it's the only node staying alive ? After a
CTRL+C
(which send aSIGINT
signal) if the node is still alive after 15 seconds (the default timeout) then aSIGTERM
signal should be sent and the node should exit. Is this what happen ?Asked by Delb on 2019-09-25 03:09:56 UTC
In addition to what @Delb has said, are you sure the robot isn't continuing to move because the hardware is stuck in a particular state and the rosserial node has actually been shut down. Or can you still see the rosserial node when you list running processes using the
ps -A
command?Asked by PeteBlackerThe3rd on 2019-09-25 06:15:45 UTC
i have attached screenshot and its look like that ,sometimes it will print wrong topic id and msgs and sometimes it wont but my robot moves continously
Asked by kallivalli on 2019-09-26 23:50:01 UTC
Please don't use an image to display text. Images are not searchable and people cannot copy and paste the text from the image. Please update your question with a copy and paste of the text instead. See the support page
Asked by jayess on 2019-09-27 01:20:00 UTC