Can't seem to move TurtleBot2 using Python in Gazebo
Hi,
I'm currently trying to move a TurtleBot model in Gazebo just by following the instructions on https://learn.turtlebot.com/2015/02/0...
So far I am able to successfully complete all of the previous tutorials on the site. Additionally, when I follow all of the instructions on the page prior to running the provided Python code, I can move the robot in simulation, both with the 2D Nav Goal in rviz and with a keyboard teleop terminal window. Also, I can run the actual TurtleBot2 with the same code; it is only simulation in Gazebo that does not seem to work.
I'm still very new to this so I am not sure how to approach debugging, but I have noticed that the exact point where the code fails to complete is:
success = self.move_base.wait_for_result(rospy.Duration(60))
Also, when I run the code, I noticed in rviz that the robot's local map doesn't appear visually and no navigation planning occurs (again, if I use 2D Nav Goal then the local map and planning occurs normally without issue). Is there any information I can provide that would be useful in diagnosing what the issue is? I am on Ubuntu 16.04 with ROS Kinetic and Gazebo 7. The full provided tutorial code is shown below:
import rospy
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
import actionlib
from actionlib_msgs.msg import *
class GoForwardAvoid():
def __init__(self):
rospy.init_node('nav_test', anonymous=False)
#what to do if shut down (e.g. ctrl + C or failure)
rospy.on_shutdown(self.shutdown)
#tell the action client that we want to spin a thread by default
self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)
rospy.loginfo("wait for the action server to come up")
#allow up to 5 seconds for the action server to come up
self.move_base.wait_for_server(rospy.Duration(5))
#we'll send a goal to the robot to move 3 meters forward
goal = MoveBaseGoal()
goal.target_pose.header.frame_id = 'base_link'
goal.target_pose.header.stamp = rospy.Time.now()
goal.target_pose.pose.position.x = 3.0 #3 meters
goal.target_pose.pose.orientation.w = 1.0 #go forward
#start moving
self.move_base.send_goal(goal)
#allow TurtleBot up to 60 seconds to complete task
success = self.move_base.wait_for_result(rospy.Duration(60))
if not success:
self.move_base.cancel_goal()
rospy.loginfo("The base failed to move forward 3 meters for some reason")
else:
# We made it!
state = self.move_base.get_state()
if state == GoalStatus.SUCCEEDED:
rospy.loginfo("Hooray, the base moved 3 meters forward")
def shutdown(self):
rospy.loginfo("Stop")
if __name__ == '__main__':
try:
GoForwardAvoid()
except rospy.ROSInterruptException:
rospy.loginfo("Exception thrown")