赞
踩
//建立目标文件夹 chenxiya@chenxiya-virtual-machine:~$ mkdir catkin_ws //进入 chenxiya@chenxiya-virtual-machine:~$ cd catkin_ws //建立 src 文件夹 chenxiya@chenxiya-virtual-machine:~/catkin_ws$ mkdir src //进入 chenxiya@chenxiya-virtual-machine:~/catkin_ws$ cd src/ //初始化工作空间 chenxiya@chenxiya-virtual-machine:~/catkin_ws/src$ catkin_init_workspace Creating symlink "/home/chenxiya/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/melodic/share/catkin/cmake/toplevel.cmake" //返回工作空间根目录 chenxiya@chenxiya-virtual-machine:~/catkin_ws/src$ cd .. //使用 pwd 查看路径 chenxiya@chenxiya-virtual-machine:~/catkin_ws$ pwd /home/chenxiya/catkin_ws //使用 catkin_make 编译 chenxiya@chenxiya-virtual-machine:~/catkin_ws$ catkin_make ----结果 Base path: /home/chenxiya/catkin_ws Source space: /home/chenxiya/catkin_ws/src Build space: /home/chenxiya/catkin_ws/build Devel space: /home/chenxiya/catkin_ws/devel Install space: /home/chenxiya/catkin_ws/install ----结果
至此 一个空的工作空间创立并且初始化结束
//进入src 文件夹
chenxiya@chenxiya-virtual-machine:~/catkin_ws$ cd src/
//创建功能包 test_pkg 并且添加依赖 roscpp rospy std_msgs
chenxiya@chenxiya-virtual-machine:~/catkin_ws/src$ catkin_create_pkg test_pkg roscpp rospy std_msgs
//创建带 install 文件夹的工作空间
chenxiya@chenxiya-virtual-machine:~/catkin_ws$ catkin_make install
// src 里面是功能包
//设置工作空间环境变量--- 系统才能找到工作空间的功能包
chenxiya@chenxiya-virtual-machine:~/catkin_ws$ source devel/setup.bash
//使用 echo 打开 检查环境变量
chenxiya@chenxiya-virtual-machine:~/catkin_ws$ echo $ROS_PACKAGE_PATH
/home/chenxiya/catkin_ws/src:/opt/ros/melodic/share
3. 发布者
#add_executable(velocity_publisher src/learning_topic/src/velocity_publisher.cpp)
/*对比此行上下两句,这里为什么不是绝对路径;*/
add_executable(velocity_publisher src/velocity_publisher.cpp)
/*
这里费了老大的劲,
*/
target_link_libraries(velocity_publisher ${catkin_LIBRARIES})
此前错误一:找不到,把上面的路径修改就可以了;
-- Configuring done
CMake Error at learning_topic/CMakeLists.txt:154 (add_executable):
Cannot find source file:
src/learning_topic/src/velocity_publisher.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: velocity_publisher
CMake Error: Cannot determine link language for target "velocity_publisher".
接着就可以
问题2
chenxiya@chenxiya-virtual-machine:~$ rosrun lerarning_topic velocity_publisher
[rospack] Error: package 'lerarning_topic' not found
原因:在同一个终端里面同时进行环境配置和rosrun learning_topic velocity_publisher
解决办法:重新打开一个终端,并且输入
cd ~/catkin_ws
source devel/setup.bash
rosrun learning_topic velocity_publisher
问题三:设置全局环境变量:
1、根目录下:找到 隐藏文件 (ctrl+h 显示/隐藏文件)
2、在最后添加
原本安装ros的环境变量:
source /opt/ros/melodic/setup.bash
添加的当前功能包的环境变量:
source /home/chenxiya/catkin_ws/devel/setup.bash
setup.bash的文件路径 根据自己的文件使用 pwd 命令查看;
最后就可以再任意路径下发布功能包:
4. 订阅者
流程:
5. 话题消息的定义和使用
6. ros中的坐标管理系统
操作
chenxiya@chenxiya-virtual-machine:~$ roslaunch turtle-tf turtle_tf_demo.launch
错误表现:
RLException: [turtle_tf_demo.launch] is neither a launch file in package [turtle-tf] nor is [turtle-tf] a launch file name
The traceback for the exception was written to the log file
解决:roslaunch turtle-tf turtle_tf_demo.launch
改为 roslaunch turtle_tf turtle_tf_demo.launch
查看tf树坐标工具
rosrun tf view_frames
rosrun tf tf_echo turtle1 turtle2
rosrun rviz rviz -d `rospack find turtlef`/rviz/turtle_rviz.rviz
chenxiya@chenxiya-virtual-machine:~$ rostopic list /cmd_vel /person_info /rosout /rosout_agg /turtle1/color_sensor /turtle1/pose chenxiya@chenxiya-virtual-machine:~$ rost rostest rostopic chenxiya@chenxiya-virtual-machine:~$ rostopic pub -r 10 /turtle1/ /turtle1/color_sensor /turtle1/pose chenxiya@chenxiya-virtual-machine:~$ rostopic pub -r 10 /turtle1/ /turtle1/color_sensor /turtle1/pose chenxiya@chenxiya-virtual-machine:~$ rostopic pub -r 10 /turtle1/pose turtlesim/Pose "{x: 1.0, y: 1.0, theta: 0.0, linear_velocity: 0.0, angular_velocity: 0.0}" ^[[A^[[D^[[D^[[B^[[A^Cchenxiya@chenxiya-virtual-machine:~$ rostopic pub -r 10 /tPose "{x: 1.0, y: 1.0, theta: 0.0, linear_velocity: 1.0, angular_velocity: 1.0}" chenxiya@chenxiya-virtual-machine:~$ rostopic pub /cmd_vel geometry_msgs/Twist "linear: x: 1.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0" publishing and latching message. Press ctrl-C to terminate
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。