Ask Your Question
1

A rospy subscriber callback thread locking question

asked 2014-01-06 14:19:14 -0600

Pi Robot gravatar image

I have a rospy node that has both a main loop and a subscriber callback that both need to modify the same global variable and I'm wondering if I have to use thread locking to prevent weirdness. The following snippet exhibits what I mean. Does the variable self.move_cmd.angular.z need locking in this situation?

def __init__():
    rospy.init_node("test")

    rospy.subscriber('roi', RegionOfInterest, self.roi_callback)

    while not rospy.is_shutdown():
        if not target_visible:
            self.move_cmd.angular.z = 0

        rospy.sleep(1)

def roi_callback(self, msg):
    if msg.width !=0 and msg.height != 0:
       self.move_cmd.angular.z = 0.1 * msg.x_offset

Thanks!
patrick

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-01-07 10:45:58 -0600

ahendrix gravatar image

Since callbacks in rospy are processed in a separate thread, I'm pretty sure you need locking for a case like this.

edit flag offensive delete link more

Comments

Thanks Austin. I'll lock it up.

Pi Robot gravatar imagePi Robot ( 2014-01-07 13:17:38 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-01-06 14:19:14 -0600

Seen: 1,881 times

Last updated: Jan 07 '14