ROS学习笔记-用程序发布导航目标点

 创建功能包

#打开一个终端,并进入到你的工作空间中的 src 目录下
cd your_workspace/src
#创建 ROS 功能包
catkin_create_pkg send_goals move_base_msgs actionlib roscpp

 新建 send_goals/src/send_goals_node.cpp 文件

#include <ros/ros.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <actionlib/client/simple_action_client.h>
#include <iostream>
using namespace std;

typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;
int main(int argc, char **argv)
{
    ros::init(argc, argv, "send_goals_node");
    MoveBaseClient ac("move_base", true);

    while (!ac.waitForServer(ros::Duration(5.0)))
    {
        ROS_INFO("Waiting for the move_base action server to come up");
    }
    move_base_msgs::MoveBaseGoal goal;

    //待发送的 目标点 在 map 坐标系下的坐标位置
    goal.target_pose.pose.position.x = 1.1;
    goal.target_pose.pose.position.y = -0.81178575134;
    goal.target_pose.pose.orientation.z = -0.00256;
    goal.target_pose.pose.orientation.w = 0.951839761956;

    ROS_INFO(" Init success!!! ");
    goal.target_pose.header.frame_id = "map";
    goal.target_pose.header.stamp = ros::Time::now();
    ac.sendGoal(goal);
    ROS_INFO("Send Goal !!!");

    ac.waitForResult();
    if (ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
    {
        ROS_INFO("The Goal achieved success !!!");
    }
    else
    {
        ROS_WARN("The Goal Planning Failed for some reason");
    }
    return 0;
}

 修改send_goals/CMakeLists.txt文件

cmake_minimum_required(VERSION 3.0.2)
project(send_goals)
# add_compile_options(-std=c++11)    # 需要手动去掉前面的 # 符号,
...

# add_executable(${PROJECT_NAME}_node src/send_goals_node.cpp) # 需要手动去掉前面的 # 符号,

# target_link_libraries(${PROJECT_NAME}_node  # 需要手动去掉前面的 # 符号,
#   ${catkin_LIBRARIES}  # 需要手动去掉前面的 # 符号,
# )    # 需要手动去掉前面的 # 符号,

...

 编译及运行

cd your_workspace
catkin_make
rosrun send_goals send_goals_node

参考资料:

https://zhuanlan.zhihu.com/p/413587126

  • 8
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值