ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Reading bump sensors on simulated turtlebot

asked 2016-10-01 07:29:37 -0600

RobB gravatar image

This must have been dealt with many times before, but as beginner with ROS I can't find an answer I understand.

Here's my code adapted from Mark Silliman

import rospy
from kobuki_msgs.msg import BumperEvent 
from geometry_msgs.msg import Twist

def processBump(data):
            print ("Bump")
            global bump
            if (data.state == BumperEvent.PRESSED):
                bump = True
                bump = False
            rospy.loginfo("Bumper Event")

def GoForward():

        # initiliaze
        rospy.init_node('GoForward', anonymous=False)

        # tell user how to stop TurtleBot
        rospy.loginfo("To stop TurtleBot CTRL + C")

        # What function to call when you ctrl + c    
        # Create a publisher which can "talk" to TurtleBot and tell it to move
        # Tip: You may need to change cmd_vel_mux/input/navi to /cmd_vel if you're not using TurtleBot2
        cmd_vel = rospy.Publisher('cmd_vel_mux/input/navi', Twist, queue_size=10)
        sub = rospy.Subscriber('mobile_base/events/bumper', BumperEvent, processBump)
        #TurtleBot will stop if we don't keep telling it to move.  How often should we tell it to move? 10 HZ
        r = rospy.Rate(10);

        # Twist is a datatype for velocity
        move_cmd = Twist()
        # let's go forward at 0.2 m/s
        move_cmd.linear.x = 0.2
        # let's turn at 0 radians/s
        move_cmd.angular.z = 0.0
        # as long as you haven't ctrl + c keeping doing...
        while not rospy.is_shutdown():
            # publish the velocity
            # wait for 0.1 seconds (10 HZ) and publish again

def shutdown(self):
        # stop turtlebot
        rospy.loginfo("Stop TurtleBot")
        # a default Twist has linear.x of 0 and angular.z of 0.  So it'll stop TurtleBot
        # sleep just makes sure TurtleBot receives the stop command prior to shutting down the script

if __name__ == '__main__':
    except rospy.ServiceException as exc:
      rospy.loginfo("GoForward node terminated.")
      print("Service did not process request: " + str(exc))

The issue is that processBump() never gets called, even though the turtlebot is moving and then clearly runs into to something.

I guess I'm not understanding the Subscriber functionality, but isn't like a listener i.e in this case, when a BumperEvent occurs the specified function, processBump() is called?

Excuse my newbieness and any clues greatly appreciated.



Similar to this topic: Help on my basic turtlbot node

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-10-03 10:59:47 -0600

zhibo gravatar image

Hello Rob, the callback function is working, the problem is what do you do when the bump occurs, it is only outputting informations.

edit flag offensive delete link more


Thanks for answering. Yes, it's true, the code only outputs a trace. The problem is I don't see the trace when I run the program (and the turtlebot collides with something), so I have to conclude that the processBump() function is not being called.

RobB gravatar image RobB  ( 2016-10-04 00:32:33 -0600 )edit

i tried your code, and when i push the bumper, I can see the 'bump' message, maybe your bumper is not working, try to rostopic echo the bumper to see if it is working or not.

zhibo gravatar image zhibo  ( 2016-10-04 03:07:50 -0600 )edit

what launch file are you using? When you say "the bumper is not working" what does that mean on a simulated turtlebot?

RobB gravatar image RobB  ( 2016-10-04 03:58:49 -0600 )edit

I tested on a real one. I just tested in the simulation, it is working as well with turtlebot_gazebo turtlebot_world.launch

zhibo gravatar image zhibo  ( 2016-10-04 04:38:36 -0600 )edit

OK I'll try again. Thanx

RobB gravatar image RobB  ( 2016-10-04 04:59:12 -0600 )edit

Still doesn't work. So I have three terminals open: 1) roscore 2) roslaunch turtlebot_gazebo turtlebot_world.launch -- which brings up gazebo 3) nav to my script directory and run the program . python

RobB gravatar image RobB  ( 2016-10-04 05:06:23 -0600 )edit

The bot moves but when it runs into one of the objects in the world, I do not see the trace. How else can I check what the sensor is detecting? Rviz is giving me something (pointCloud?) but I'm having difficulty interpreting it.

RobB gravatar image RobB  ( 2016-10-04 05:08:22 -0600 )edit

Any ideas zhibo? I'm really stuck with this.

RobB gravatar image RobB  ( 2016-10-05 06:55:05 -0600 )edit

Question Tools

1 follower


Asked: 2016-10-01 07:29:37 -0600

Seen: 2,862 times

Last updated: Oct 03 '16