除了自动驾驶汽车/人工智能外,还有一个火爆的科技热点就是虚拟现实/增强现实设备,这也是本书的第11章。
Leap Motion使用参考官网介绍和之前博文:
1 http://blog.csdn.net/zhangrelay/article/details/52356417
2 https://github.com/madratman/youbot_leapmotionteleop
ROS Android VR设备:
1 https://github.com/cloudspace/ros_cardboard
2 https://github.com/SPARbot/SPARbot-android-app
补充一个不相关内容:https://github.com/Nurgak/Virtual-Robot-Challenge
ROS+V-Rep
Virtual Robot Challenge
The goal of the Virtual Robot Challenge (VRC) is to introduce the Robotic Operating System (ROS) and V-REP simulation environment by performing autonomous tasks with a simulated robot.
This is to demonstrate the advantages of development using simulation, before eventually moving on to real robots. The advantages are that the code stays the same when moving from simulation to real robot, testing in simulation is much less time consuming (avoid mechanical failures, batteries, sensors failures/calibration...), cheaper and requires less effort in general.
All software used within the scope of this project is free to use.
Theory
ROS is composed of small stand-alone entities called "nodes". Nodes publish and subscribe to messages called "topics" to talk between each other. One can write nodes in C++ or Python, topics are language agnostic. A good introduction can be found on the ROS official website.
The ROS tutorials are well written and straight forward, it is recommended to follow them as least for installation and workspace setup, this provides a good overview on how ROS works and how it is organized.
Hardware
The robot has two wheels and a caster wheel in the back for locomotion. In the front it has six distance sensors, four pointing forwards and two pointing downwards under the robot, and a linear camera showing an image of 128 pixels wide and 1 pixel height.
The robot is based on the Robopoly demonstration robot and can be physically built, any type of robot can be adapted for the simulation.
Software
The whole installation process has been fully tested on Ubuntu 14.04 with ROS Indigo. One can use VirtualBox if such a computer is not available, however it will slow down the simulation speed.
Installation
Download and install the latest V-REP EDU, define the
VREP_ROOT
environment variable as the path to V-REPexport VREP_ROOT=<VREP path>
Install ROS Indigo
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' $ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net --recv-key 0xB01FA116 $ sudo apt-get update $ sudo apt-get install ros-indigo-desktop-full $ source /opt/ros/indigo/setup.bash
Install the catkin tools:
$ sudo apt-get install python-catkin-tools
Create the workspace for ROS in
~/catkin_ws
:$ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src $ catkin_init_workspace
Copy the ROS interface package contents from V-REP install folder to ROS workspace:
$ cp -r <VREP path>/programming/ros_packages/v_repExtRosInterface ~/catkin_ws/src
Clone this repository to somewhere and copy the contents the ROS package to the workspace:
$ git clone https://github.com/Nurgak/Virtual-Robot-Challenge.git $ cd Virtual-Robot-Challenge $ cp -r Software/ROS/vrc ~/catkin_ws/src
Build the packages (grab a coffee):
$ cd ~/catkin_ws $ catkin build
Copy the ROS interface plugin to the V-REP root folder
$ cp ~/catkin_ws/devel/lib/libv_repExtRosInterface.so <VREP path>
Source the setup file, this needs to be done in every new terminal:
$ cd ~/catkin_ws $ source devel/setup.bash
Export the
ROS_MASTER_URI
environment variable$ export ROS_MASTER_URI=http://localhost:11311
Programming
The code actuating the robot motors and publishing its sensor data is written in Lua language in V-REP. It is very simple and only used to exchange data with the ROS framework, not for actual behavior logic. This is the place to add new code if one wishes to add new sensors to the simulated robot. To view the code open the V-REP scene and on the left side double-click on the script icon next to the robot node.
The robot behavior is dictated by the Python scripts stored in ~/catkin_ws/src/vrc/src/
. The sample.py
script shows how to process the data from all the different sensors on the robot.
The launch files are used to start different nodes at the same time, they are stored in ~/catkin_ws/src/vrc/launch/
, think of them as shortcuts.
Follow the line
To goal is to follow a line. Very basic approach, however one can always optimize the system to make it faster.
Run ROS core in a terminal
$ roscore
From another terminal run V-REP, always start V-REP after ROS core
$ sh <VREP path>/vrep.sh
In V-REP open the
arena.ttt
from the/Simulation
folderClick on the play button in V-REP to launch the simulation
In a third terminal launch the
arena.launch
file which will starts some nodes$ roslaunch vrc arena.launch
Finally in a fourth terminal run the line follower program
$ rosrun vrc line_follower.py
The robot should start following the line marked on the floor.
Teleoperation
One can remotely operate the robot using the keyboard using the teleop_twist_keyboard
package:
$ sudo apt-get install ros-indigo-teleop-twist-keyboard
Stop the line follower script (ctrl+c) and run:
$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py
The terminal must be in focus for the commands to be executed.
Exploration and mapping
ROS can do mapping using the robot sensors and its position. First make sure the slam_gmapping
and pointcloud_to_laserscan
packages are installed:
$ sudo apt-get install ros-indigo-slam-gmapping
$ sudo apt-get install ros-indigo-pointcloud-to-laserscan
And launch the mapping scene with:
$ roslaunch vrc mapping.launch
$ rosrun vrc explorer.py
The launch file runs the gmapping
and the RVIZ visualization nodes. Accessible areas are marked in white and inaccessible areas are marked in black.
The explorer
node makes the robot go around the arena and avoid obstacles, whenever it encounters an obstacle it will turn on itself for a random amount of time and continue.
Physical robot
When the simulation yields satisfying results one can use a real robot that subscribes to and publishes the same ROS topics as the virtual robot, this way the same software running on the computer can be used. The implementation for this can be done in various ways and is left up to the reader.
----
本文同步分享在 博客“zhangrelay”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。