ROS学习:turtle控制
turtle旋转
首先查看turtlesim里面的节点,使用rqt_graph查看节点流图
/*
* @Description: 这是一个让turtle旋转的ros publisher
* @Version:
* @Autor: copy
* @Date: 2022-03-12 17:28:55
* @LastEditors: copy
* @LastEditTime: 2022-03-12 17:42:00
*/
#include <ros/ros.h>
#include "geometry_msgs/Twist.h"
#define PI 3.141592653
int main(int argc,char** argv)
{
ros::init(argc,argv,"turtle_twist");
ros::NodeHandle nh;
ros::Publisher Pub = nh.advervise<geometry_msgs::Twist>("/turtle1/cmd_vel",10);
geometry_msgs::Twist twist;
twist.linear.x = 1;
twist.angular.z = PI;
ROS_INFO("\t现在的速度是%f,偏转速度是%f\t",twist.linear.x,twist.angular.z = PI);
ros::Rate rate(10);//10Hz
while(ros::OK)
{
Pub.publish(twist);
rate.sleep();
ros::spin(); //后面的代码不再执行ros::spinOnce();
}
return 0;
}
接收turtle位置
使用rostopic list 和rostopic info [topic]查看turtle的topic,
-
结果展示
跟踪turtle
使用rosservice list 和 rosservice info [service]查看turtle的service-----/Spawn。
-
rospackage
- rospy
- roscpp
- std_msgs
- turtlesim
- tf
-
turtle_tf_broadcaster.cpp
-
turtle_tf_listener.cpp
-
start_demo_with_listener.launch
-
结果展示
直接控制无超调,但是反应慢,稳态误差大
PID控制
超调量大,但是反应迅速,稳态误差较小
相关代码在我的github的turtle库中
标签:turtle,twist,ros,msgs,学习,初学,tf,ROS From: https://www.cnblogs.com/copy2000/p/17454969.html