玩转树莓派ROS自主导航机器人树莓派

ROS机器人底盘(13)-move_base(1)

2018-01-23  本文已影响183人  PIBOT导航机器人

概述

movebase利用actionlib包提供使得我们的机器人到达一个设置的目标点的包
先上一张官方经典的图


movebase

指定导航点

首先我们查看下MoveBaseActionGoal的定义
rosmsg show MoveBaseActionGoal

MoveBaseActionGoal

运行导航逻辑后,rostopic echo /move_base/goal, 点击2D Nav Goal,输出

image.png

结合上面2个输出可以看到geometry_msgs/PoseStamped

官方有个例子navigation_tutorials

#include <ros/ros.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <actionlib/client/simple_action_client.h>
#include <tf/transform_datatypes.h>

#include <boost/thread.hpp>

typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;

void spinThread(){
  ros::spin();
}

int main(int argc, char** argv){
  ros::init(argc, argv, "simple_navigation_goals");

  ros::NodeHandle n;

  boost::thread spin_thread = boost::thread(boost::bind(&spinThread));

  MoveBaseClient ac("pose_base_controller");

  //give some time for connections to register
  sleep(2.0);

  move_base_msgs::MoveBaseGoal goal;

  //we'll send a goal to the robot to move 2 meters forward
  goal.target_pose.header.frame_id = "base_link";
  goal.target_pose.header.stamp = ros::Time::now();

  goal.target_pose.pose.position.x = 2.0;
  goal.target_pose.pose.position.y = 0.2;
  goal.target_pose.pose.orientation = tf::createQuaternionMsgFromYaw(M_PI);

  ROS_INFO("Sending goal");
  ac.sendGoal(goal);

  ac.waitForResult();

  if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
    ROS_INFO("Hooray, the base moved 2 meters forward");
  else
    ROS_INFO("The base failed to move forward 2 meters for some reason");

  return 0;
}

base_link为参考坐标系, 目标就是前面2.0(x = 2.0),左0.2(y = 0.2),方向选择180°(orientation = tf::createQuaternionMsgFromYaw(M_PI))

上一篇 下一篇

猜你喜欢

热点阅读