MoveBaseAction server does not seem to be active

asked 2022-07-21 20:18:23 -0600

distro gravatar image

updated 2022-07-21 20:19:33 -0600

I'm creating my own exploration algorithm in unknown environments with turtlebot3. I am plan on :

-using turtlebot3 slam package for mapping(in order to get map info)

-have my custom algorithm use map info to create a target goals set in the known free space(according to the map data I'm getting fro slam)

-As the map data gets updated by slam I keep creating more target goals from the data.

I'm however having issues with the movebase action server. It doesnt seem to be active. This is my code(I just removed the script for my planner to be present it here for this question,but the rest of the code is what I'm trying to use):

#!/usr/bin/python2.7
import rospy
import math
import actionlib
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from geometry_msgs.msg import PoseStamped
from nav_msgs.msg import Odometry
from nav_msgs.msg import OccupancyGrid
from nav_msgs.msg import Path
import tf

def callback(msg):
    pass

def mapcall(msg):
    pass
rospy.init_node("control")
#pub = rospy.Publisher("goal", PoseStamped, queue_size=1, latch=True)
rospy.Subscriber("/odom", Odometry, callback)
rospy.Subscriber("/map", OccupancyGrid, mapcall)


#while not rospy.is_shutdown():
#    pub.publish(goal)
#    rospy.sleep(10.5)
#    goal.pose.position.x = 0.203
#    goal.pose.position.y = -0.4769
#    pub.publish(goal)
#    rospy.sleep(10.5)
def planner(A, B, C, v, x, y, z, X, Y, dt, index):
    ..............................

def movebase_client():
    client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
    listener = tf.TransformListener()
    listener.waitForTransform('map', 'base_footprint', rospy.Time(0), rospy.Duration(50))
    (trans, rot) = listener.lookupTransform('map', 'base_footprint', rospy.Time(0))
    target = planner(0.5,0.25,0.25,0.22,0,1,0,trans[0],trans[1],1.5,1)
    goal = MoveBaseGoal()
    goal.target_pose.header.stamp = rospy.get_rostime()
    goal.target_pose.header.frame_id = "map"
    goal.target_pose.pose.position.x = target[0]
    goal.target_pose.pose.position.y = target[1]
    goal.target_pose.pose.position.z = 0

    goal.target_pose.pose.orientation.x = 0
    goal.target_pose.pose.orientation.y = 0
    goal.target_pose.pose.orientation.z = 0
    goal.target_pose.pose.orientation.w = 1
    client.wait_for_server()



    client.send_goal(goal)
    wait = client.wait_for_result()

    if not wait:
            rospy.logerr("Action server not available!")
            rospy.signal_shutdown("Action server not available!")
    else:
        return client.get_result()

if __name__ == '__main__':
    try:
        result = movebase_client()
        if result:
            rospy.loginfo("Goal execution done!")
    except rospy.ROSInterruptException:
        rospy.loginfo("Navigation test finished.")

When I run it, nothing happens, is there some parameter in a config file for turtlebot3 that I'm supposed to set to something else. Is the code just wrong?

edit retag flag offensive close merge delete