ros by examples learning

匿名 (未验证) 提交于 2019-12-03 00:19:01

1、rviz

rosrun tf static_transform_publisher 0.0 0.0 0.0 0.0 0.0 0.0 map my_frame 100

ros by example的所有的代码都是在rbx1上的。也就是在
catkin_ws/src/rbx1

arbotix是一个仿真器
1、sudo apt-get install ros-indigo-arbotix-*
2、roscore
3、cd catkin_ws
source devel/setup.bash
roslaunch rbx1_bringup fake_turtlebot.launch(使用turtlebot模型)
roslaunch rbx1_bringup fake_pi_robot.launch(pi模型)
4、rosrun rviz rviz -d rospack find rbx1_nav/sim.rviz

在rviz的add中订阅odometry这个话题,再把turtlebot的这个模型加入进来就可以了。

rostopic pub -r 10 /cmd_vel geometry_msgs/Twist ‘{linear: {x: 0.2, y:
0, z: 0}, angular: {x: 0, y: 0, z: 0.5}}’

这个时候小车会以一个圆圈的形式来走。

发现,如果下次再启动这个模型的话发现他还是会走,这个时候把速度都改为0就可以了。
或者在原来发布话题的终端中按ctrl+c,然后重新发布一个主题。
rostopic pub -1 /cmd_vel geometry_msgs/Twist ‘{}’

重要的是:你可以不使用turtlebot的模型,使用自己小车的URDF。
具体的看一下ros_by_example的具体的教程。

三、控制机器人的底座轮子的移动(controlling a mobile base)
For a mobile robot using ROS,the x-axis points forward, the y-axis points to the left and the z-axis points upward.

机器人中使用的是右手准则。

ROS uses the metric system so that linear velocities are always
specified in meters per second (m/s) and angular velocities are given in radians per second (rad/s).
For an indoor robot, I tend to keep the maximum linear speed at or below 0.2 m/s.

The base controller node typically publishes odometry data on the /odom topic and listens for motion commands on the /cmd_vel topic.
At the same time, the controller node typically (but not always) publishes a transform from the /odom frame to the base frame―either /base_link or /base_footprint

ros提供了一个move_base的包,允许我们设定目标点和机器人的源方向。move_base的包可以做到在达到目标的时候躲避障瑷物的功能。
move_base包是一个复杂的可以用于路径规划的,在选择机器人要走的路径的时候,结合视觉里程计创建本地和全局地图move_base combines odometry data with both local and global cost maps when selecting a path for the robot to follow.同时他还能控制机器人的速度和加速度。

建图:可以通过ROS中的slam的gmapping包创建一个环境地图。The mapping process works best using a laser scanner but can also be done using a Kinect or Asus Xtion depth camera to provide a simulated laser scan.

定位:在已经建图的基础上,ROS提供了amcl包,可以根据当前的扫描和里程计的数据来让机器人自动定位。Once a map of the environment is available, ROS provides the amcl package (adaptive Monte Carlo localization) for automatically localizing the robot based on its current scan and odometry data.

语意目标:比如说“go to the kitchen and bring me the beer”这个目标可以被分解为几个动作。
In this case, the semantic goal must be parsed and translated into a series of actions. For actions requiring the robot to move to a particular location, each location can be passed to the localization and path planning levels for implementation。

With the arrival of the Microsoft Kinect and Asus Xtion cameras, one can now do more affordable SLAM by using the 3D point cloud from the camera to generate a “fake” laser
scan.

In this chapter, we will cover the three essential ROS packages that make up the core of the Navigation Stack:
1、 move_base
for moving the robot to a goal pose within a given reference frame
2、 gmapping
for creating a map from laser scan data (or simulated laser data from
a depth camera)
3、amcl
for localization using an existing map

在move_base之前最好永久设置一下路径。参考David_Han的博客
http://blog.csdn.net/david_han008/article/details/53122075
1、echo “source /opt/ros/indigo/setup.bash” >> ~/.bashrc
2、echo “source ~/catkin_ws/devel/setup.bash” >> ~/.bashrc
3、source ~/.bashrc
第一句话是为了在执行rosrun,roslaunch的时候能够自动补全一些地方。
第二句将你工作区间的路径直接加入到到 .bashrc 文件当中,这样你就可以直接用catkin_ws这个工作空间下所有的包。
第三句就是让上面两条指令立即生效,就是说刷新了一下 .bashrc这个文件。

move_base
一、简单的运动
1、roslaunch rbx1_bringup fake_turtlebot.launch
2、roslaunch rbx1_nav fake_move_base_blank_map.launch
3、rosrun rviz rviz -d rospack find rbx1_nav/nav.rviz

下次可以在这个基础上在再加载让turtlebot运动的模型。
4、rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
‘{ header: { frame_id: “map” }, pose: { position: { x: 1.0, y: 0, z:
0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }’
让他向前前进1米
5、rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "map" }, pose: { position: { x: 0, y: 0, z:
0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'

让他回到原来的位置。

二、画正方形
在一的前三步数的基础上,
rosrun rbx1_nav move_base_square.py
会看到turtlebot小车开始走正方形了。

rosrun rqt_reconfigure rqt_reconfigure

这样可以调节本地地图和全局地图的比重,来优化路线。

三、带有避障功能的小车。(move_base的另外一个重要的功能是能够避障,无论是静态的还是动态的障碍物。)
1、roslaunch rbx1_bringup fake_turtlebot.launch
2、rosparam delete /move_base
3、roslaunch rbx1_nav fake_move_base_map_with_obstacles.launch
4、rosrun rviz rviz -drospack find rbx1_nav/nav_obstacles.rviz
5、rosrun rbx1_nav move_base_square.py

其中黄色的正方形的是障碍物,蓝色的是膨胀半径为0.3的椭圆形区域,为安全缓冲区。

在模拟的过程中,一条绿线是为了到达下一目的地的全局路径规划。在机器人前面短一点的红线是本地规划的路线。

8.4 用gmapping包
在ros中,地图只是一张位图,用来表示网格被占据的情况,白色像素点表示没有被占据的网格,黑色像素点代表障碍物,而灰色像素点代表“未知”。

10、ROS vision

1、rosrun image_view image_view image:=/camera/rgb/image_color
ros image_view 来查看RGB视频流。
2、rosrun image_view disparity_view image:=/camera/depth/disparity
用disparity节点来查看从摄像头传来的深度图像。

深度图像的颜色代表了距离摄像头远近不同的物体。红黄表示距离近的点,绿色代表中间距离的点,蓝紫表示距离更远的点。

10.1 test your usb-webcam
roslaunch rbx1_vision usb_cam.launch video_device:=/dev/video0
rosrun image_view image_view image:=/camera/rgb/image_raw

10.2test your kinect
roslaunch freenect_launch freenect-registered-xyzrgb.launch
rosrun image_view image_view image:=/camera/rgb/image_raw
rosrun image_view image_view image:=/camera/ depth_registered /image_rect

10.5 ROS to Opencv
采集的图像或者视频流若想通过opencv进行处理,比如说将彩色图转换为灰度图的,需要cv_bridge来处理。ROS provides the cv_bridge package to convert between
ROS and OpenCV and image formats
1、kinect
roslaunch freenect_launch freenect-registered-xyzrgb.launch
rosrun rbx1_vision cv_bridge_demo.py

2、USB
roslaunch rbx1_vision usb_cam.launch video_device:=/dev/video0
rosrun rbx1_vision cv_bridge_demo.py

可以看到对与kinect显示的图像变成了灰度图。

10.10 passthrough点云过滤器
1、roslaunch openni_launch openni.launch
2、roslaunch rbx1_vision passthrough.launch(launch the passthrough filter)
3、rosrun rviz rviz -drospack find rbx1_vision/pcl.rviz

10.10.3 VoxelGrid过滤器
1、 roslaunch openni_launch openni.launch
2、rosrun rviz rviz -d rospack find rbx1_vision/pcl.rviz
3、roslaunch rbx1_vision voxel.launch

这个滤波器的效果就是降低云中的采样点,图中的就是稀疏点云。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!