给move_base 发送 goal c++

使用 Action :move_base_msgs::MoveBaseAction(move_base在world中的目标)

新建send_goal.cpp

/*
 * send_goal.cpp
 *
 *  Created on: Aug 10, 2016
 *      Author: unicorn
 */

#include <ros/ros.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <actionlib/client/simple_action_client.h>
/*move_base_msgs::MoveBaseAction
 move_base在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()
	创建action客户端,参数1:action名,参数2:true,不需要手动调用ros::spin(),会在它的线程中自动调用。
	*/
	MoveBaseClient ac("move_base", true);
	// Wait 60 seconds for the action server to become available
	ROS_INFO("Waiting for the move_base action server");
	ac.waitForServer(ros::Duration(60));
	ROS_INFO("Connected to move base server");
	// Send a goal to move_base
	//目标的属性设置
	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

find_package(catkin REQUIRED COMPONENTS
        actionlib
)
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES navigation_goal
   CATKIN_DEPENDS roscpp rospy std_msgs actionlib
#  DEPENDS system_lib
)
add_executable(send_goal src/send_goal.cpp)
target_link_libraries(send_goal
   ${catkin_LIBRARIES}
 )

package.xml

  <build_depend>actionlib</build_depend>
  <exec_depend>actionlib</exec_depend>

move_base介绍:

在这里插入图片描述

Action Published Topics

move_base/feedback (move_base_msgs/MoveBaseActionFeedback)
Feedback含有基座当前位置信息
 
move_base/status (actionlib_msgs/GoalStatusArray)
携带目标执行的状态信息
 
move_base/result (move_base_msgs/MoveBaseActionResult)            
对于move_base action的result为空
状态返回的是数字,数字代表的含义在actionlib_msgs/GoalStatus.msg中定义了

     # uint8 PENDING         = 0   # The goal has yet to be processed by the action server
    # uint8 ACTIVE          = 1   # The goal is currently being processed by the action server
    # uint8 PREEMPTED       = 2   # The goal received a cancel request after it started executing
    #                             #   and has since completed its execution (Terminal State)
    # uint8 SUCCEEDED       = 3   # The goal was achieved successfully by the action server (Terminal State)
    # uint8 ABORTED         = 4   # The goal was aborted during execution by the action server due
    #                             #    to some failure (Terminal State)
    # uint8 REJECTED        = 5   # The goal was rejected by the action server without being processed,
    #                             #    because the goal was unattainable or invalid (Terminal State)
    # uint8 PREEMPTING      = 6   # The goal received a cancel request after it started executing
    #                             #    and has not yet completed execution
    # uint8 RECALLING       = 7   # The goal received a cancel request before it started executing,
    #                             #    but the action server has not yet confirmed that the goal is canceled
    # uint8 RECALLED        = 8   # The goal received a cancel request before it started executing
    #                             #    and was successfully cancelled (Terminal State)
    # uint8 LOST            = 9   # An action client can determine that a goal is LOST. This should not be
    #                             #    sent over the wire by an action server

在这里插入图片描述

文章来源:
https://blog.csdn.net/yiranhaiziqi/article/details/52891973
https://wenda.ncnynl.com/question/116423

  • 0
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值