본문 바로가기
AI/python or ros_Webot

Webots Tutorial 8 - Using ROS ( 60 minutes )

by 몽돌리스트 2020. 6. 10.
반응형

Tutorial 8: Using ROS (60 Minutes)

This tutorial explains how to use the nodes from the webots_ros package provided with Webots.

These examples were tested with ROS melodic and kinetic on Linux.

There is no warranty they will work if you use a different platform or an ancient distribution of ROS.


1. Installing ROS and "webots_ros" Package Installation

In order to use these nodes, you will first need to install the ROS framework.

To install the latest version of ROS on Ubuntu use the following commands:

 

$ 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://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
$ sudo apt-get update sudo
$ apt-get install ros-melodic-desktop-full # takes time, get a coffee :)
$ sudo rosdep init
$ rosdep update
$ sudo apt-get install ros-melodic-webots-ros

For more information or to install it on another platform please read http://wiki.ros.org/ROS/Installation.

Unless you need older version for some other application,

you should choose the latest distribution (Melodic Morenia or Kinetic Kame).

 

The last line is to install the webots_ros package.

If you never used the ROS framework before, it is strongly recommended to follow some tutorials (Beginner Level) from: http://wiki.ros.org/ROS/Tutorials.

These tutorials will also help you set up your ROS environment and initialize your catkin workspace.

 

The minimum requirement is to follow these instructions (taken from the ROS tutorial 1.1.1).

1. Open a terminal

2. Check if the ROS environment is properly set-up:

$ printenv | grep ROS

3. If not, source the setup script - Check it again to be sure.

 $ source /opt/ros/melodic/setup.bash

4. Create a catkin_ws workspace for ROS:

        Create some folders: mkdir -p ~/catkin_ws/src

        Go back in the main folder: cd ~/catkin_ws/

        Generate files by compilation: catkin_make

        Source again the new files: source devel/setup.bash

5. To make sure your workspace is properly set-up by the setup script, make sure ROS_PACKAGE_PATH environment variable includes the directory you are in. The echo $ROS_PACKAGE_PATH command should return /home/youruser/catkin_ws/src:/opt/ros/melodic/share.

[ Workspace 를 꼭 확인해줘야 한다. -> 제대로 설정하지 않으면 정말 큰 에러가 생길 수 있다. (ex. 재설치 ) ]

 

6. The last step is to set the WEBOTS_HOME environment variable: export WEBOTS_HOME=/usr/local/webots. If you installed Webots in a different place, adapt the variable. This line can be added to your .bashrc file.

 

* Remember*: Each time you open a terminal, you have to source the environment with this command: source opt/ros/melodic/setup.bash or you can add this line in your .bashrc file.

 

2. Running the Nodes

You can start any simulation using ROS with the following commands (here the e_puck_line one for example):

source /opt/ros/melodic/setup.bash
$ roslaunch webots_ros e_puck_line.launch

This launch file will launch Webots (the WEBOTS_HOME environment variable should be set) and start the corresponding node.

The seed of Webots' random number generator is initialized at the beginning of the simulation and not when the ROS nodes connect. Webots has to be running for the ROS nodes to connect.

However, we cannot guarantee how long it will run before the ROS nodes connect.

Therefore, the sensor measurements and motor commands will slightly differ from one run to another, due to the noise being slightly different at the time of the connection of the ROS nodes.

[ ROS nodes 간의 연결 고리에서 noise 가 생길 수 있다는 점을 있지말자. ]

 

This may have consequences on the behavior of the robots, thus making such simulations non fully reproducible. You can use the --synchronize argument in order to make sure that Webots will not run before the ROS node connects. This is useful to make ROS-based simulation reproducible.

[ 해당 명령으르 통해서, ROS-base simulation reproducible을 만들어낼 수 있다. ]

 

If you want to use different computers for the ROS master, the Webots simulation and/or the nodes, you must be able to connect to each of them with SSH in both ways. The hostname and IP addresses of these computers should be listed in the known hosts list of each computer and the ROS_MASTER_URI variable should be adjusted accordingly.

 

3. Creating New Nodes

These examples only show a few possibilities for interfacing ROS and Webots, but you can build your own nodes to connect with Webots. The source code of these nodes can be found on the repository of the webots_ros package.

The robot_information_parser node is the most basic one and is a good base to start building your own node. The complete_test node doesn't show any particular application but contains an almost exhaustive list of the Webots API functions.

All the functions from the Webots API have their corresponding services or topics. You can find in the Reference Manual the definitions of all the services and topics associated to each device.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형

댓글