MoffKalast / vizanti

A mission planner and visualizer for controlling outdoor ROS robots.
https://wiki.ros.org/vizanti
BSD 3-Clause "New" or "Revised" License
133 stars 26 forks source link

Not following Plan #86

Open ValkyrX opened 3 weeks ago

ValkyrX commented 3 weeks ago

[Problem description]

Server Platform(s):

Client Platform(s):

So , if i use the 2d nav goal then the robot will go where i tell it, if i set a plan using a few waypoints and then ensure the correct topic is selected and press go , nothing happens ? is this featire working at present ? i am using an slamtec athena 2.0 robot , the topic selected is the path plan topic , i select the map as frame and the base_link as teh robot , in fact i have tried them all :-)

Thanks K

MoffKalast commented 3 weeks ago

Ah yes, well the problem is that the waypoints publisher isn't actually a standard thing and more of a way to send your backend some points that can be processed further.

I can't find any good documentation on the Athena so I'll presume it uses move_base or at least something that mimics it in the interface part.

In ROS 1 move_base only accepts single goals so there needs to be a node that takes the path, sends each one of them to move_base sequentially and check for completion, and if the robot can't actually get there, perform some kind of failsafe, e.g. return to the first point, or stop and abort, or call for help, or something else entirely. It's hard to build a general solution for it since it depends on the application.

For autonomous boats I've mainly used the waypoints publisher with the line_planner which does navigation without move_base entirely and supports Paths natively. Most of the wiki demo videos were done using that one. You could also try that as a test, but I don't think it'll be a good fit for your use case.

Overall implementing this is relatively simple so here's an untested sample from chatgpt that looks about right but doesn't include any exception handling 😄:

#!/usr/bin/env python

import rospy
import actionlib
from nav_msgs.msg import Path
from geometry_msgs.msg import PoseStamped
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal

class WaypointFollower:
    def __init__(self):
        rospy.init_node('waypoint_follower')

        # Subscribe to the /waypoints topic
        rospy.Subscriber('/waypoints', Path, self.waypoints_callback)

        # Create a SimpleActionClient for move_base
        self.client = actionlib.SimpleActionClient('move_base', MoveBaseAction)

        # Wait for the move_base action server to start
        rospy.loginfo("Waiting for move_base action server...")
        self.client.wait_for_server()
        rospy.loginfo("Connected to move_base action server")

        self.waypoints = []
        self.current_goal_index = 0

    def waypoints_callback(self, msg):
        rospy.loginfo("Received waypoints")
        self.waypoints = msg.poses
        self.current_goal_index = 0
        self.send_next_goal()

    def send_next_goal(self):
        if self.current_goal_index < len(self.waypoints):
            goal = MoveBaseGoal()
            goal.target_pose = self.waypoints[self.current_goal_index]
            goal.target_pose.header.stamp = rospy.Time.now()
            rospy.loginfo(f"Sending goal {self.current_goal_index + 1}/{len(self.waypoints)}: {goal.target_pose.pose}")
            self.client.send_goal(goal, done_cb=self.done_callback)
        else:
            rospy.loginfo("All waypoints reached")

    def done_callback(self, state, result):
        rospy.loginfo(f"Goal {self.current_goal_index + 1} reached")
        self.current_goal_index += 1
        self.send_next_goal()

if __name__ == '__main__':
    try:
        WaypointFollower()
        rospy.spin()
    except rospy.ROSInterruptException:
        rospy.loginfo("Waypoint follower node terminated.")

For obvious reasons, this shouldn't be implemetned in the browser client, since the robot will stop navigating if you ever drop the connection which may be uh... problematic.

In ROS 2 and nav2 there is the navigate through poses functionality and a short demo node on how to pass the Path message to it, which is conceptually very similar to the code above. I suppose we should add a similar demo to Noetic as well.

ValkyrX commented 3 weeks ago

ps if it help here is the docs on the athena 2.0 ros implimentation and topics it uses

https://wiki.slamtec.com/pages/viewpage.action?pageId=36208700

MoffKalast commented 3 weeks ago

Oh interesting, that seems to be something else indeed. They've got this move_to_locations topic that seems to be conceptually similar.

So to use that you'd just need a node similar to the one above that takes the Poses given by the Path and only keeps the positions, shoves them into a Point array and publishes that with that message type. Then presumably it would do the whole path and handle all the goal completions internally.

But since they also implement the standard /move_base_simple/goal topic, the code above should also work fine I think. Unless they don't implement the action server, in which case it would need some slight modifications to work with simple goals instead.

ValkyrX commented 2 weeks ago

So i added the script above and ran it, however it doesn't move the bot so I guess I'm missing something else, like how-to pass that to the actual robot itself

MoffKalast commented 2 weeks ago

Yeah I guess the action server isn't implemented on their end. Maybe using the sdk message would work, though not sure:

#!/usr/bin/env python

import rospy
from nav_msgs.msg import Path
from geometry_msgs.msg import Point
from slamware_ros_sdk.msg import MoveToLocationsRequest, MoveOptions

class PathToMoveToLocations:
    def __init__(self):
        rospy.init_node('path_to_move_to_locations')

        self.publisher = rospy.Publisher('/move_to_locations', MoveToLocationsRequest, queue_size=10)

        rospy.Subscriber('/path', Path, self.path_callback)

        rospy.loginfo("Path to MoveToLocations node initialized.")

    def path_callback(self, path_msg):
        move_request = MoveToLocationsRequest()

        # Convert the Path waypoints to Point[]
        move_request.locations = [pose.pose.position for pose in path_msg.poses]

        # Set default MoveOptions
        move_request.options = MoveOptions()

        # Set end yaw
        move_request.yaw = 0.0

        # Publish the MoveToLocationsRequest message
        self.publisher.publish(move_request)

if __name__ == '__main__':
    try:
        PathToMoveToLocations()
        rospy.spin()
    except rospy.ROSInterruptException:
        pass