4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
热卖商品
新闻详情
ros 学习笔记 (三):入门学习_sinat_34506522的博客-CSDN博客
来自 : CSDN技术社区 发布时间:2021-03-25
//初始化工作空间chenxiya chenxiya-virtual-machine:~/catkin_ws/src$ catkin_init_workspaceCreating 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_wsSource space: /home/chenxiya/catkin_ws/srcBuild space: /home/chenxiya/catkin_ws/buildDevel space: /home/chenxiya/catkin_ws/develInstall space: /home/chenxiya/catkin_ws/install----结果

至此 一个空的工作空间创立并且初始化结束
\"在这里插入图片描述\"

创建功能包及设置环境变量
//进入src 文件夹chenxiya chenxiya-virtual-machine:~/catkin_ws$ cd src///创建功能包 test_pkg 并且添加依赖 roscpp rospy std_msgschenxiya 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 doneCMake 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 .txxCMake Error: CMake can not determine linker language for target: velocity_publisherCMake 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_wssource devel/setup.bashrosrun 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 命令查看

最后就可以再任意路径下发布功能包

\"原本是在catkin_ws路径下
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 nameThe 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/posechenxiya chenxiya-virtual-machine:~$ rostrostest 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.0angular: x: 0.0 y: 0.0 z: 0.0 publishing and latching message. Press ctrl-C to terminate

本文链接: http://wasros.immuno-online.com/view-750566.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616
官网:http://