ros常用命令
rostopic
rosservice
rosnode
rosparam
rosmsg
rossrv
rosbag(话题记录)
运行小海龟仿真器
roscore(启动ros master)
rosrun turtlesim turtlesim_node(启动小海龟仿真器)
rosrun turtlesim turtle_teleop_key(启动小海龟控制节点)
workspace:
src(source space)代码空间放置功能包
放后面功能包里面的源码
build 编译空间基本不用管
中间文件一些二进制 文件,基本上用不到
devel(opment)开发空间生成的可执行文件及库
install安装空间
放置编译生成的可执行文件
后两个相似一个是开发中一个是开发后
创建工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
编译工作空间
cd ~/catkin_ws/
catkin_make(install需要加上单独产生)
设置环境变量
source devel/setup.bash
检查环境变量
echo $ROS_PACKAGE_PATH
开发代码,创建代码时一定要创建功能包功能包是放置源码的最小单元必须要创建功能包不能直接放置src下面去编译
创建功能包指令
catkin_create_pkg[depend1][depend2][depend3]
创建功能包(一定要放置在src里面)
cd ~/catkin_ws/src
catkin_create_pkg test_pkg std_msgs rospy roscpp
功能包叫做test_pkg 后面三个依赖 ros定义标准消息结构std_msgs roscpp要写C++程序,rospy要写python程序
src放置功能包代码
include放置头文件
编译功能包
cd ~/catkin_ws (cd …回到catkin_ws)
catkin_make(发现功能包没有任何代码,没有实际编译效果)
source ~/catkin_ws/devel/setup.bash(设置 工作空间环境变量上面)
xml功能包名字版本号Email开源许可证功能包基本信息 依赖等
cmakelist功能包里面的编译规则
catkin_create_pkg learning_topic std_msgs rospy roscpp geometry_msgs turtlesim
add_executable(velocity_publisher src/velocity_publisher.cpp)
target_link_libraries(velocity_publisher ${catkin_LIBRARIES})
拷贝到cmakelists install上面
编译并运行发布者
cd ~/catkin_ws/
catkin_make
source devel/setup.bash
(在主文件夹里ctrl+h找出隐藏文件找到.bashrc拉到最后一行source /home/ros(用户名)/catkin_ws/devel/setup.bash
)这样不用每次在终端输入此条指令
roscore
rosrun turtlesim turtlesim_node
rosrun learning_topic velocity_publisher
(catkin_ws devel lib learning_topic得到的编译结果)
python 文件scripts src learning_topic 创建scripts文档点属性允许作为程序执行文件
!!!
编辑并运行订阅者
add_executable(pose_subscriber src/pose_subscriber.cpp)
target_link_libraries(pose_subscriber ${catkin_LIBRARIES})
拷贝到cmakelists install上面
cd ~/catkin_ws/
catkin_make
source devel/setup.bash
(在主文件夹里ctrl+h找出隐藏文件找到.bashrc拉到最后一行source /home/ros(用户名)/catkin_ws/devel/setup.bash
)这样不用每次在终端输入此条指令
roscore
rosrun turtlesim turtlesim_node
rosrun learning_topic pose_subscriber
(catkin_ws devel lib learning_topic得到的编译结果)
python
直接编译rosrun learning_topic pose_subscriber.py
learning_topic创建msg打开msg 再在终端打开
touch person.msg(创建了person.msg)
打开文件
33