Giter VIP home page Giter VIP logo

Comments (5)

MoffKalast avatar MoffKalast commented on July 23, 2024

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.

from vizanti.

ValkyrX avatar ValkyrX commented on July 23, 2024

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

from vizanti.

MoffKalast avatar MoffKalast commented on July 23, 2024

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.

from vizanti.

ValkyrX avatar ValkyrX commented on July 23, 2024

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

from vizanti.

MoffKalast avatar MoffKalast commented on July 23, 2024

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

from vizanti.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.