ROS多点巡航cpp文件

ROS多点巡航cpp文件(在网上常见的是基于python写的,有时候需要用到基于cpp的巡航文件,提供参考,亲测可行,具体方法见github)

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

// Define a client for to send goal requests to the move_base server through a SimpleActionClient
typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;

int main(int argc, char** argv){
  // Initialize the pick_objects node
  ros::init(argc, argv, "pick_objects");

  //tell the action client that we want to spin a thread by default
  MoveBaseClient ac("move_base", true);
  ros::param::set("/Robot_pos", "Start_Point");

  // Wait 5 sec for move_base action server to come up
  while(!ac.waitForServer(ros::Duration(5.0))){
    ROS_INFO("Waiting for the move_base action server to come up");
  }

  move_base_msgs::MoveBaseGoal pick_up_goal;
  move_base_msgs::MoveBaseGoal drop_off_goal;

  // set up the frame parameters
  pick_up_goal.target_pose.header.frame_id = "map";
  pick_up_goal.target_pose.header.stamp = ros::Time::now();
  drop_off_goal.target_pose.header.frame_id = "map";
  drop_off_goal.target_pose.header.stamp = ros::Time::now();

  // Define a position and orientation for the robot to reach
  pick_up_goal.target_pose.pose.position.x = 1.0;
  pick_up_goal.target_pose.pose.orientation.w = 1.0;
  drop_off_goal.target_pose.pose.position.x = -0.31;
  drop_off_goal.target_pose.pose.position.y = -0.22;
  drop_off_goal.target_pose.pose.orientation.z = 0.99;
  drop_off_goal.target_pose.pose.orientation.w = 0.009;

  // Send the goal 1
  ROS_INFO("Sending pick_up_goal");
  ac.sendGoal(pick_up_goal);
  ros::param::set("/Robot_pos", "Moving");
  // Wait an infinite time for the results
  ac.waitForResult();

  // Check if the robot reached its goal
  if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) {
    ROS_INFO("Hooray, the base moved to the pick up goal");
    ros::param::set("/Robot_pos", "position_1");
  }
  else {
    ROS_INFO("The base failed to move to the pick up goal");
    return 0;
  }

  // wait for 5 seconds
  ros::param::set("/Robot_pos", "Moving");
  ros::Duration(5.0).sleep();
  // send the goal 2
  ROS_INFO("Sending drop_off_goal");
  ac.sendGoal(drop_off_goal);
  ac.waitForResult();

  if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) {
    ROS_INFO("Hooray, the base moved to the drop off goal");
    ros::param::set("/Robot_pos", "position_2");
  }
  else {
    ROS_INFO("The base failed to move to the drop off goal");
    return 0;
  }
  
  ros::param::set("/Robot_pos", "finish");


  return 0;
}

https://github.com/danibyay/pick_objects

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值