Ubuntu20.04 ROS Noetic 编译运行Nav2d
前言
Ubuntu20.04 Noetic 下的利用rosbridge、roslib和ros2d等库实现的网页端Js Widget,以及运行PR2_Navigation和turtlebot_navigation教程。
- Js源码仓库地址:Nav2d
- 教程参考官方:CreatingABasicNav2DWidget
- 一共有两个案例:PR2_navigation和turtlebot_navigation
- 本文分为安装和运行两部分内容。
- 本文代码仓库:RosNavJs.git
文章目录
- Ubuntu20.04 ROS Noetic 编译运行Nav2d
- 前言
- 安装
- 1、安装map-server
- 2、下载编译安装pr2机器人
- 3、下载编译turtlebot和willow map等
- 4、下载nav2djs
- 运行
- 0.修改js文件
- 1.运行PR2_navigation
- 2.运行turtlebot_navigation
- 总结
- 附加
安装
1、安装map-server
sudo apt-get install ros-noetic-map-server
2、下载编译安装pr2机器人
(其实可以不安装)但是安装了才可以运行官方pr2_navigation的例子,但是这里面坑很多。
建议参考我的这篇博客:Ubuntu20.04+Noetic编译pr2和pr2_navigation
由于Noetic还不支持pr2很多package,所以参考kinetic版本进行自行编译,主要修改了一些CMakeList和参数和引用。脚本源码和修改后的库都在这里 ROS_Noetic_pr2
如果嫌编译整个pr2很麻烦,可以只运行其中的sh脚本安装ompl,而不进行catkin_make。
3、下载编译turtlebot和willow map等
二者安装方法类似,都是下载好ompl以后,把没支持noetic的package用catkin_make进行编译。
因为这几个包的坑没有pr2那么多,不需要做什么修改,可以直接编译。
sudo apt-get install ros-noetic-ecl-core ros-noetic-kobuki-msg ros-noetic-ecl-mobile-robot libftdi-dev
未支持的包,下载源码并编译:
git clone https://github.com/PR2/willow_maps.git
git clone https://github.com/turtlebot/turtlebot_simulator.git
git clone https://github.com/turtlebot/turtlebot.git
git clone https://github.com/turtlebot/turtlebot_apps.git
git clone https://github.com/yujinrobot/kobuki.git
git clone https://github.com/yujinrobot/kobuki_core.git
git clone https://github.com/yujinrobot/yujin_ocs.git
git clone https://github.com/yujinrobot/yocs_msgs.git
git clone https://github.com/ros-perception/ar_track_alvar.git
然后把这些包放在catkin_ws/src目录下:
mkdir catkin_ws catkin_ws/src
cp -r willow_map/ catkin_ws/src/
cp -r turtlebot_simulatorp/ catkin_ws/src/
...
cd catkin_ws
catkin_make
catkin_make install
如果编译willow maps时报错:
"/home/jillian/ROS/catkin_ws/build/willow_maps/willow-sans-whitelab-0.025.pgm":
No such file or directory.”
发现出错后,我搜索了一下git上面的commit,选择手动下载该文件然后放进build文件夹。最后再catkin_make install 一下就行。
- willow-sans-whitelab-0.025.pgm
- willow.tmap
如果编译ar_track_alvar时报错
手动把ar_track_alvar下ar_track_alvar子文件移除,只留下ar_track_alvar_msgs,因为只需要这个包。
如果想要安装到opt/ros/noetic里面:
catkin_make -DCMAKE_INSTALL_PREFIX=/opt/ros/noetic install --force-cmake
当然用户一般是没有权限安装到opt的。可以把catkin_ws/build/install 下面的share拷贝到相应文件去。
4、下载nav2djs
git clone https://github.com/GT-RAIL/nav2djs.git
运行
0.修改js文件
打开下载好的js代码:nav2djs,打开example文件下任意例子。
如occupancygrid.html为例子:
修改js脚本引用,上方四个js库都可以在网上搜索到,可以下载整个工程,也可以指下载min.js文件。
而src里面的Nav2d.js和其他文件要通过npm仓库下载的相应脚手架工具打包成一个js文件。但是考虑到很多人并没有安装Node,所以就无视,直接把js引入即可。
同时修改上面的localhost为你对应ros启动的虚拟机/Docker或者服务器ip:
ros = new ROSLIB.Ros({
url : 'ws://localhost:9090'
});
ros = new ROSLIB.Ros({
url : 'ws://192.168.1.139:9090'
});
虚拟机在建立的时候,在设置-网络里面选择 网络桥接模式 (Bridge Network ),这样才能保证虚拟机和主机可以相互访问,因为该模式下虚拟机在真实网络段中有独立IP,主机与虚拟机处于同一网络段中,彼此可以通过各自IP相互访问。局域网内其他主机也可以访问虚拟机。
同时记得开放9090端口:
sudo ufw status
sudo ufw allow 9090
sudo ufw enable
sudo ufw reload
1.运行PR2_navigation
运行机器人和gazebo
roslaunch pr2_gazebo pr2_empty_world.launch
原教程是加载pr2_wg_world,但是有bug无法运行
然后加载地图和导航模块:
export ROBOT=sim
rosrun map_server map_server /opt/ros/noetic/share/willow_maps/willow-sans-whitelab-0.025.pgm 0.025
roslaunch pr2_2dnav pr2_2dnav.launch
然后将机器人手臂收拢:roslaunch pr2_tuckarm tuck_arms.launch
如果报了python相关的错误,可以尝试直接用python启动该文件,查看错误并改正,有时候是python2和3之间的冲突。
发布机器人的姿势:rosrun robot_pose_publisher robot_pose_publisher
启动rosbridge 服务器:roslaunch rosbridge_server rosbridge_websocket.launch
最后打开HTML页面了,双击地图上所需的位置进行导航:
2.运行turtlebot_navigation
记得先:source ~/.bashrc 否则会定位到kinetic里面去。
开三个终端,分别运行:
export TURTLEBOT_STAGE_WORLD_FILE="/opt/ros/noetic/share/turtlebot_stage/maps/stage/maze.world"
export TURTLEBOT_STAGE_MAP_FILE="/opt/ros/noetic/share/turtlebot_stage/maps/maze.yaml"
roslaunch turtlebot_stage turtlebot_in_stage.launch
roslaunch rosbridge_server rosbridge_websocket.launch
rosrun robot_pose_publisher robot_pose_publisher
效果如下:
我修改了部分代码,使得轨迹也能被绘制出来,如果直接运行demo,是没有这条轨迹的。
总结
提示:这里对文章进行总结:
和编译模块比起来,这边坑少了很多,但我对ROS不太熟悉,还是在帮助下完成了这个。
对ROS的Topic和msg的了解更深入了。
附加
最新的更新,修改了一下界面,增添了所有Topic的显示,等我整理好就发到github上
代码:RosNavJs.git
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)