ROS1 in 5 Days Python - Real Robot Project Error : :signal_shutdown hook error[cannot join current thread]"

Hello I was testing my code on the real robot and my control script kept exiting with this error:

shutdown request: user request
signal_shutdown hook error[cannot join current thread]

I assume it has something to do with threads not exiting fast enough or something but I have not had this issue in the past or in Gazebo
My code is as follows:

#! /usr/bin/env python3

import rospy
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist

cmd = Twist()


# control logic
def callback(data):
    print(f"F: {data.ranges[360]}/nR: {data.ranges[180]}/nL: {data.ranges[540]}")

    if data.ranges[360] > 0.5 and data.ranges[180] < 0.3 and data.ranges[180] > 0.2:
        cmd.angular.z = 0.0
        cmd.linear.x = 0.1
        print("F")
    elif data.ranges[360] > 0.5 and data.ranges[180] > 0.275:
        cmd.angular.z = -0.125
        cmd.linear.x = 0.1
        print("R")
    elif data.ranges[360] > 0.5 and data.ranges[180] < 0.225:
        cmd.angular.z = 0.125
        cmd.linear.x = 0.1
        print("L")
    elif data.ranges[360] < .5:
        cmd.angular.z = 1.6


rospy.init_node("robo_control_node")
pub = rospy.Publisher("/cmd_vel", Twist, queue_size=6)
sub = rospy.Subscriber("/scan", LaserScan,  callback)

rate = rospy.Rate(12)
while not rospy.is_shutdown():
    pub.publish(cmd)
    rate.sleep()

Any insight would be greatly appreciated!
-Brennan

This error indicates that the system ran out memory. You need to see way to optimize memory use. Suggestion:

  1. Reduce the publisher’s queue size to 1 or eliminate it if possible. You don’t need a (large) queue for this.
  2. Move your pub.publish(cmd) inside the callback loop, discard the rate object and the loop and just put a rospy.spin() after the sub object definition.
1 Like

Thank you for the response, I implemented your suggestions and it behaves the exact same way. I was sure to catkin_make and source after my changes as well. Is this my machine’s memory, as I am running this with 32gb of RAM? I had it output a string and found that it always runs the callback 60 times before throwing the error. Do you think it could be opening threads and not closing them out which uses up all memory?
Thank You!
-Brennan

My code after suggestions:

#! /usr/bin/env python3

import rospy
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist

cmd = Twist()

control logic

def callback(data):
if data.ranges[360] > 0.5 and data.ranges[180] < 0.3 and data.ranges[180] > 0.2:
cmd.angular.z = 0.0
cmd.linear.x = 0.1
#print(“F”)
elif data.ranges[360] > 0.5 and data.ranges[180] > 0.275:
cmd.angular.z = -0.125
cmd.linear.x = 0.1
#print(“R”)
elif data.ranges[360] > 0.5 and data.ranges[180] < 0.225:
cmd.angular.z = 0.125
cmd.linear.x = 0.1
#print(“L”)
elif data.ranges[360] < .5:
cmd.angular.z = 1.6
pub.publish(cmd)

rospy.init_node(“robo_control_node”)
pub = rospy.Publisher(“/cmd_vel”, Twist)
sub = rospy.Subscriber(“/scan”, LaserScan, callback)
rospy.spin()

You said you were testing in a real robot…is it your own robot and does it have 32GB of memory?

In any case, it is clearly a memory problem. I don’t know the setup of your machine or robot, but the memory is running out for some reason (poor memory management).

Sorry, me saying “my machine” was a bit vague, I should have said my PC. This was running the real robot lab teleoperating the Turtlebot 3. In any case, thank you for the help in identifying that it is a memory management problem.

You mean you are running the code on our real robot?

If that’s the case, let me refer you to our expert on that @roalgoal @rodrigo55, because a number of students have successfully done this under his supervision.

Correct, Thank you for your help!
I have previously used the real robot lab working on the ROS2 in 5 days course in the spring with no issue as well so I don’t know what other factors could affect that.
-Brennan

Hi @Carvinaxe3, I think this comes because there is a speed limit in the real robot. I see that you send an angular velocity of 1.6 but the limit is 1.0. Please let me know if those limits are not specified in the project’s notebook so I can add them

Ohhhh ok yes that is stated. I appreciate the quick response!

In this jupyter notebook for ROS Basics in 5 Days: Course Project the limit is shown as linear of 0.19 and angular of 0.49 in the appendix for “security reasons”. I did not see that there was an appendix when going through part 1 so you may want to mention it.

2 Likes

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