资源简介
此文件包为控制ros中小海龟的定点移动,其中有两个程序,大同小异。一个需要输入目标点的xy坐标,一个是在程序中固定了xy的坐标。具体情感博客:note-ros-控制小海龟到达指定点 (https://blog.csdn.net/qq_33168256/article/details/82950222)
代码片段和文件信息
#include “ros/ros.h“
#include “std_msgs/String.h“
#include
#include
#include
#include
using namespace std;
#define ox 7
#define oy 7
#define pi 3.1415926
int irate=0;
ros::Publisher pub;
void Callback(const turtlesim::Pose& pose)
{
float xythetalvav;
float err_xerr_yerr_thetaerr_dis;
geometry_msgs::Twist out_ctrl;
turtlesim::Pose hope_pose;
//初始化
out_ctrl.linear.x=1.0;
out_ctrl.linear.y=0.0;
out_ctrl.linear.z=0.0;
out_ctrl.angular.x=0.0;
out_ctrl.angular.y=0.0;
out_ctrl.angular.z=0.0;
x = pose.x;
y = pose.y;
theta = pose.theta;
if(theta<0)theta=2*pi+theta;
lv = pose.linear_velocity;
av = pose.angular_velocity;
ROS_INFO(“\nThe pose:\n\tx:%f \n\ty:%f \n\ttheta:%f \n\tlv:%f \n\tav:%f“xythetalvav);
//计算
err_x=ox-x;
err_y=oy-y;
err_dis=err_x*err_x+err_y*err_y;
if (err_x==0&&err_y==0) hope_pose.theta=0;
else if(err_x>0&&err_y==0) hope_pose.theta=0;
else if(err_x>0&&err_y>0) hope_pose.theta=atan(err_y/err_x);
else if(err_x==0&&err_y>0) hope_pose.theta=pi/2;
else if(err_x<0&&err_y>0) hope_pose.theta=atan(err_y/err_x)+pi;
else if(err_x<0&&err_y==0) hope_pose.theta=pi;
else if(err_x<0&&err_y<0) hope_pose.theta=atan(err_y/err_x)+pi;
else if(err_x==0&&err_y<0) hope_pose.theta=pi/2+pi;
else if(err_x>0&&err_y<0) hope_pose.theta=atan(err_y/err_x)+2*pi;
err_theta=theta-hope_pose.theta;
if(err_theta>pi){
err_theta=-(2*pi-err_theta);
}
else if(err_theta<-pi){
err_theta=2*pi+err_theta;
}
//附值
if(err_theta<-0.05 && err_theta>-pi) out_ctrl.angular.z=pi;
else if(err_theta>0.05 && err_theta else out_ctrl.angular.z=0;
if(abs(err_dis)>0.01 && out_ctrl.angular.z==0)out_ctrl.linear.x=5;
else out_ctrl.linear.x=0.0;
ROS_INFO(“\nThe out_ctrl.linear.x:\n\t%f\nThe out_ctrl.angular.z:\n\t%f“out_ctrl.linear.xout_ctrl.angular.z);
pub.publish(out_ctrl);
irate=0;
}
int main(int argc char **argv)
{
ros::init(argc argv “turtlectrl“);
ros::NodeHandle n1;
ros::Subscriber sub = n1.subscribe(“turtle1/pose“ 1000 Callback);
pub = n1.advertise(“turtle1/cmd_vel“ 1000);
ros::spin();
return 0;
}
- 上一篇:Image Resizer
- 下一篇:Citavi5 中文教程
相关资源
- Rational Rose Common破解文件
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- 用VC 编写的仿QQ聊天室程序源代码
- 外点法程序
- 外罚函数程序
- 机器人单机械臂滑模控制程序
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
- c 程序判断离散数学中命题公式
- 多项式求和(数据结构C 版)
- vc 6.0开发的流程图编辑器
- VC 天空盒(skyBox)实现(附源代码)
- 智能寻迹机器人源程序及pcb图
评论
共有 条评论