------ROS学习记录-----古月居ROS21讲----1-14讲
1.roscore
2.rosrun turtlesim turtlesim_node
3.rosrun turtlesim turtle_teleop_key
4.rqt_graph
5.rosnode list
6.rosnode info /turtlesim
7.rostopic pub /turtle1/cmd_vel TAB键
8.rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear: x: 8.0 y: 2.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0"
9.rosmsg show geometry_msgs/Twist
10.rosservice list
11.rosservice call /spawn "x:1.0 y:1.0 theta: 10.0 name: ''"
12. rosbag record -a -o cmd_record(默认保存在Home)
13.rosbag play cmd_record_2020-08-21-10-36-45.bag (先1再2)
-----------------------------------------------------------我是分割线--------------------------------------------------------------
1.创建工作空间
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ src下:catkin_init_workspace src文件夹中会出现cmakelists文件,表示已经成为一个ROS包文件
2.编译工作空间
$ cd ~/catkin_ws/
$ catkin_make或者catkin_make install(出现install文件夹-开发后文件),devel文件夹存放开发过程中产生的文件,库。build文件夹中是存放编译过程中的中间文件。
3.设置环境变量
$ source devel/setup.bash
4.检查环境变量
$ echo $ROS_PACKAGE_PATH
5.创建功能包:
$ cd ~/catkin_ws/src
$ catkin_create_pkg test_pkg std_msgs rospy roscpp
6.编译功能包:
$ cd ~/catkin_ws
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash
!!!同一个工作空间下,不允许存在同名功能包!不同工作空间下,允许存在同名功能包。
package.xml: 存放功能包基本信息及依赖信息
-----------------------------------------------------------我是分割线--------------------------------------------------------------
发布者publisher的编程实现:(我们发布,turtlesim接收)
1.创建功能包:
$ cd catkin_ws/src
$ catkin_create_pkg learning_topic std_msgs roscpp rospy geometry_msgs turtlesim
2.编写代码
$ cd learning_topic/src
$ touch velocity_publisher.cpp
$ sudo gedit velocity_publisher.cpp
如下代码:
/*
*该例程将发布turtle1/cmd_vel话题,消息类型geometry_msgs::Twist
*/
#include<ros/ros.h>
#include<geometry_msgs/Twist.h>
int main(int argc,char **argv)
{
//ROS节点初始化
ros::init(argc,argv,"velocity_publisher");//节点名字:velocity_publisher
//创建节点句柄
ros::Nodehandle n;
//创建一个publisher,发布名为turtle1/cmd_vel的topic,消息类型为geometry_msgs::Twist,队列长度为10
ros::Publisher turtle_vel_pub =n.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel",10);//<>里面是消息类型,()里是往哪个话题发布消息
//设置循环的频率
ros::Rate loop_rate(10);
int count = 0;
while(ros::ok())
{
//初始化geometry_msgs::Twist类型的消息
geometry_msgs::Twist vel_msg;
vel_msg.linear.x = 0.5;
vel_msg.angular.z = 0.2;
//发布消息
turtle_vel_pub.publish(vel_msg);
ROS_INFO("Publish turtle velocity command[%0.2f m/s,%0.2f rad/s]",vel_msg.linear.x,vel_msg.angular