ROS: Sends a target location, the robot automatically plans the route, moves to that position.

Source: Internet
Author: User

Use the Action:move_base_msgs::movebaseaction (Move_base in world's goal)

New Send_goal.cpp

/* * send_goal.cpp * * Created On:aug, * author:unicorn * * * #include <ros/ros.h> #include <m ove_base_msgs/movebaseaction.h> #include <actionlib/client/simple_action_client.h>/*move_base_msgs::  Movebaseaction Move_base's goal in world * * typedef actionlib::simpleactionclient<move_base_msgs::movebaseaction>
Movebaseclient;

int main (int argc, char** argv) {ros::init (argc, argv, "Send_goals_node"); /*//Create the Action client//True causes the client to spin its own thread//don ' t need Ros::spin () creating action clients, Parameters 1:a
The ction name, parameter 2:true, does not require a manual call to Ros::spin () and is automatically invoked in its thread.
*/movebaseclient AC ("Move_base", true);
Wait seconds for the action server to become available ros_info ("Waiting for the Move_base Action Server");
Ac.waitforserver (Ros::D uration (60));
Ros_info ("Connected to move base server");
Send a goal to Move_base//target property settings Move_base_msgs::movebasegoal goal;
goal.target_pose.header.frame_id = "Map"; Goal.target_pose.header.stamp = Ros::tIme::now ();
goal.target_pose.pose.position.x = 21.174;
GOAL.TARGET_POSE.POSE.POSITION.Y = 10.876;
GOAL.TARGET_POSE.POSE.ORIENTATION.W = 1;
Ros_info ("");
Ros_info ("sending goal");
Ac.sendgoal (goal);
Wait for the action to return Ac.waitforresult ();
if (ac.getstate () = = actionlib::simpleclientgoalstate::succeeded) ros_info ("You have reached the goal!");
Else Ros_info ("The base failed for some reason");
return 0; }

CMakeList.txt

Add_executable (send_goal src/send_goal.cpp)
target_link_libraries (send_goal
   ${catkin_libraries}
 )

New launch File Goal_launch.launch

<launch>
  <master auto= "Start"/>
  <param name= "/use_sim_time" value= "true"/>
  < Include file= "$ (find navigation_stage)/move_base_config/move_base.xml"/>

  <node pkg= "Stage_ros" type= " Stageros "Name=" Stageros "args=" $ (find navigation_stage)/stage_config/worlds/willow-pr2-2.5cm.world "respawn=" False ">
    <param name=" base_watchdog_timeout "value=" 0.2 "/>
  </node>
  <include file=" $ ( Find navigation_stage)/move_base_config/amcl_node.xml "/>  
  <node name=" Rviz "pkg=" Rviz "type=" Rviz "args=" -D $ (Find navigation_stage)/single_robot.rviz "/>
  <node name=" Send_goal "pkg=" Navigation_example "type=" Send_goal "output=" screen "/>
</launch>

Nodes in the launch

<node name= "Map_server" pkg= "Map_server" type= "Map_server" args= "$ (find navigation_stage)/stage_config/maps/" Respawn= "false"/>

Using WILLOW-FULL-0.025.PGM 0.025, note to replace your own file directory, mine is in the navigation_stage/stage_config/maps/file.
Other nodes are similar.

Run launch.

Results:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.