三轮全向轮底盘SLAM挖坑系列-正方形算法

在《ROS机器人程序设计》第二版后面send_goal.cpp的基础上改过来的,这里给出正方形的代码,其他的弓字型可以在这基础上改进。不过这容错性并没有那么好,不像小米扫地机器人那么智能。

#include <ros/ros.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <actionlib/client/simple_action_client.h>
#include <tf/transform_broadcaster.h>
#include <sstream>
#include <cmath>
#include <vector>

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

MoveBaseClient* ac;

move_base_msgs::MoveBaseGoal goal;

void setPose(move_base_msgs::MoveBaseGoal &goal, double p_x, double p_y, double theta)
{
    goal.target_pose.header.frame_id = "map";
    goal.target_pose.header.stamp = ros::Time::now();

    goal.target_pose.pose.position.x = p_x;
    goal.target_pose.pose.position.y = p_y;
    goal.target_pose.pose.orientation.z = sin(theta/2);
    goal.target_pose.pose.orientation.w = cos(theta/2);

    ac->sendGoal(goal);
    ac->waitForResult();
}

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

    ac = new MoveBaseClient("move_base", true);

    while (!ac->waitForServer(ros::Duration(5.0)))
    {
       ROS_INFO("Waiting for the move_base action server");
    }

    ROS_INFO("Sending goal");

    setPose(goal, 1.0, 0.0, 0.0);
    setPose(goal, 3.0, 0.0, 90.0);
    setPose(goal, 3.0, 2.0, 180.0);
    setPose(goal, 1.0, 2.0, 270.0);
    setPose(goal, 1.0, 0.0, 0.0);

    if (ac->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
    {
       ROS_INFO("You have arrived to the goal position");
    }

    else
    {
       ROS_INFO("The base failed for some reason");
    }

    return 0;

}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值