ros
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ros [2015/04/17 16:27] – [Summary] superstage | ros [2020/03/06 09:25] (current) – [ROS Configuration] tvandenbussche | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== ROS ====== | ||
+ | |||
+ | ===== ROS Installation ===== | ||
+ | |||
+ | ==== Easy way ==== | ||
+ | |||
+ | - **Choose a distribution** from the one available [[http:// | ||
+ | - Make sure you got **the right Ubuntu release** for the ROS distribution you chose, check that [[http:// | ||
+ | - **Follow the install step** from the ROS website for the ROS distribution you chose ([[http:// | ||
+ | |||
+ | ==== Other installations ==== | ||
+ | |||
+ | ROS can be install from source and on other operating systems, a list for ROS Indigo is available [[http:// | ||
+ | |||
+ | ===== ROS Configuration ===== | ||
+ | |||
+ | Once you have install ROS, you need [[http:// | ||
+ | <code bash> | ||
+ | # ROS Config | ||
+ | |||
+ | # Source ROS Config files | ||
+ | source / | ||
+ | |||
+ | mkdir -p ~/ | ||
+ | cd ~/ | ||
+ | catkin_make | ||
+ | source devel/ | ||
+ | |||
+ | # Choose editor for rosed command | ||
+ | export EDITOR=" | ||
+ | |||
+ | # Force ROS package database to update | ||
+ | rospack list > /dev/null | ||
+ | |||
+ | # Force rqt plugin database to update | ||
+ | rm -f .config/ | ||
+ | </ | ||
+ | You must replace < | ||
+ | |||
+ | ===== How to create a ROS Package ===== | ||
+ | Here is a simple way to create an empty ros package, follow the instructions. | ||
+ | <code bash> | ||
+ | cd ~/ | ||
+ | catkin_create_pkg NamePackage Dependency1 Dependency2 | ||
+ | cd .. | ||
+ | catkin_make | ||
+ | source ../.bashrc | ||
+ | </ | ||
+ | If you choose to create a package where you will use c++, **don' | ||
+ | ===== How to install a ROS Package ===== | ||
+ | To install new package use apt-get, for example for web_video_server package type this in a terminal : | ||
+ | <code bash> | ||
+ | sudo apt-get install ros-indigo-web-video-server | ||
+ | </ | ||
+ | Once apt-get finished, don't forget to source bashrc. | ||
+ | <code bash> | ||
+ | source ~/.bashrc | ||
+ | </ | ||
+ | |||
+ | ===== Some ROS Package ===== | ||
+ | |||
+ | You can have the whole list [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | ===== Useful commands ===== | ||
+ | ==== Navigate throught ROS file system ==== | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | ==== Launching ROS ==== | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | ==== Getting information ==== | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | See also the [[http:// | ||
+ | |||
+ | ===== Launch files ===== | ||
+ | The launch files are use to start multiple nodes at once. They use an [[http:// | ||
+ | |||
+ | |||
+ | ===== Description of the robot ===== | ||
+ | |||
+ | **ROS** and **GAZEBO** don't use same files to describe robots. **GAZEBO** is a stand alone and use **SDF** files whereas **ROS** use **URDF** files. They are both XML file. | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | ===== GAZEBO Simulator ===== | ||
+ | ROS and GAZEBO can work together only if you pick **the right version for each of them**, see [[http:// | ||
+ | |||
+ | |||
+ | GAZEBO is a stand alone now, but it can still communicate with ROS thanks to gazebo_ros_pkgs. Install it. | ||
+ | <code bash> | ||
+ | sudo apt-get install ros-indigo-gazebo-ros-pkgs | ||
+ | </ | ||
+ | In order for GAZEBO to work, you need to add some lines to your bashrc. | ||
+ | <code bash> | ||
+ | # Gazebo Config | ||
+ | source / | ||
+ | source / | ||
+ | </ | ||
+ | You can now launch gazebo with ROS. Start ROS Master in a terminal. | ||
+ | <code bash> | ||
+ | roscore | ||
+ | </ | ||
+ | In an other terminal, start gazebo with gazebo_ros. | ||
+ | <code bash> | ||
+ | rosrun gazebo_ros gazebo | ||
+ | </ | ||
+ | You can now use GAZEBO with ROS. For more information about the gazebo_ros_pkgs install check that [[http:// | ||
+ | |||
+ | |||
+ | ===== URDF Integration in GAZEBO ===== | ||
+ | ==== Setup the file hierarchy ==== | ||
+ | |||
+ | We are going to implement a simple robot in URDF and then spawn it into GAZEBO. | ||
+ | Let's call it MYROBOT. | ||
+ | |||
+ | First let's create all the packages. | ||
+ | <code bash> | ||
+ | cd ~/ | ||
+ | catkin_create_pkg MYROBOT_description | ||
+ | catkin_create_pkg MYROBOT_gazebo | ||
+ | source ~/.bashrc | ||
+ | </ | ||
+ | |||
+ | The file hierarchy for our packages should be like this. Catkin_create_pkg only create package.xml and CMakeLists.txt, | ||
+ | < | ||
+ | ../ | ||
+ | / | ||
+ | package.xml | ||
+ | CMakeLists.txt | ||
+ | /urdf | ||
+ | MYROBOT.urdf | ||
+ | /meshes | ||
+ | mesh1.dae | ||
+ | mesh2.dae | ||
+ | ... | ||
+ | /materials | ||
+ | /cad | ||
+ | / | ||
+ | package.xml | ||
+ | CMakeLists.txt | ||
+ | /launch | ||
+ | MYROBOT.launch | ||
+ | /worlds | ||
+ | MYROBOT.world | ||
+ | /models | ||
+ | world_object1.dae | ||
+ | world_object2.stl | ||
+ | world_object3.urdf | ||
+ | /materials | ||
+ | /plugins | ||
+ | </ | ||
+ | More information [[http:// | ||
+ | |||
+ | ==== Create the URDF file ==== | ||
+ | |||
+ | Create the file according with [[http:// | ||
+ | Once you have created the file, you can check it with this command. | ||
+ | <code bash> | ||
+ | check_urdf MYROBOT.urdf | ||
+ | </ | ||
+ | You can also print it as a graph to have a better view of your model. | ||
+ | <code bash> | ||
+ | urdf_to_graphiz MYROBOT.urdf | ||
+ | </ | ||
+ | For more information see [[http:// | ||
+ | |||
+ | In order to be GAZEBO compatible, you URDF file [[http:// | ||
+ | |||
+ | ==== Create the Launch file ==== | ||
+ | Create MYROBOT.launch and paste this. | ||
+ | <code xml> | ||
+ | < | ||
+ | <!-- We resume the logic in empty_world.launch, | ||
+ | <include file=" | ||
+ | <arg name=" | ||
+ | <!-- more default parameters can be changed here --> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | For a deep understanding of this launch file you can check / | ||
+ | |||
+ | ==== Create the World file ==== | ||
+ | Eventually, create MYROBOT.world and paste this. | ||
+ | <code xml> | ||
+ | <?xml version=" | ||
+ | <sdf version=" | ||
+ | <world name=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | Check the [[http:// | ||
+ | |||
+ | ==== Launching our world ==== | ||
+ | We can now launch the world. | ||
+ | <code bash> | ||
+ | roslaunch MYROBOT_gazebo MYROBOT.launch | ||
+ | </ | ||
+ | |||
+ | ==== Spawning MYROBOT in GAZEBO ==== | ||
+ | Add this line to MYROBOT.launch. | ||
+ | <code xml> | ||
+ | <!-- Spawn a robot into Gazebo --> | ||
+ | <node name=" | ||
+ | </ | ||
+ | Relaunch MYROBOT.launch. MYROBOT should be in GAZEBO. | ||
+ | |||
+ | ==== Improve URDF file using XACRO ==== | ||
+ | Xacro (XML Macros) is an XML macro language, it allows you to use variables, math operations and [[http:// | ||
+ | |||
+ | First, make sure that you have Xacro package install on your computer. | ||
+ | <code bash> | ||
+ | sudo apt-get install ros-indigo-xacro | ||
+ | </ | ||
+ | |||
+ | Then you need to make a modification in your MYROBOT.urdf. | ||
+ | <code xml> | ||
+ | <robot name=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | Become. | ||
+ | <code xml> | ||
+ | <?xml version=" | ||
+ | <robot xmlns: | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Finally, change the file extension by .xacro, it's just to remind you, that it's not an URDF file anymore. You can from now on add [[http:// | ||
+ | |||
+ | In order to use xacro file, we need to translate it in urdf again. One way to do that is by adding this lines at the top of your MYROBOT.launch. | ||
+ | |||
+ | <code xml> | ||
+ | <!-- ##### loading parameters ##### --> | ||
+ | <!-- This line convert the xacro file into urdf and stock it in ROS Parameter Server under the name / | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | And change the line that spawn MYROBOT in GAZEBO simulator. | ||
+ | <code xml> | ||
+ | <!-- Spawn a robot into Gazebo --> | ||
+ | <!-- We just change the argument file by param, to indicate that the URDF description file is in the ROS parameters server --> | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | You can relaunch your launch file now. | ||
+ | |||
+ | ==== Recapitulation ==== | ||
+ | The robot description go on further transformations. | ||
+ | | ^ Xacro -> Urdf ^ Urdf -> Sdf ^ | ||
+ | ^ Command Used | xacro.py | ||
+ | ^ When | Loading robot description in ROS parameters server | ||
+ | |||
+ | You can use gzsdf command to see the sdf file generated by GAZEBO when you spawn MYROBOT, useful for debugging. | ||
+ | ==== < | ||
+ | |||
+ | You can add the gazebo tag to specify gazebo properties in your URDF/XACRO file. The common way to do it, is to create a MYROBOT.gazebo in MYROBOT_description/ | ||
+ | <code xml> | ||
+ | <!-- Include --> | ||
+ | < | ||
+ | </ | ||
+ | [[http:// | ||
+ | |||
+ | Thus the file hierarchy look like this now. | ||
+ | < | ||
+ | ../ | ||
+ | / | ||
+ | package.xml | ||
+ | CMakeLists.txt | ||
+ | /urdf | ||
+ | MYROBOT.xacro | ||
+ | MYROBOT.gazebo | ||
+ | / | ||
+ | package.xml | ||
+ | CMakeLists.txt | ||
+ | /launch | ||
+ | MYROBOT.launch | ||
+ | /worlds | ||
+ | MYROBOT.world | ||
+ | </ | ||
+ | ===== GAZEBO plugins in ROS ===== | ||
+ | |||
+ | With the GAZEBO plugins, you can access sensors data and motor control using ROS messages and services. | ||
+ | The plugins are added using the < | ||
+ | |||
+ | |||
+ | For more information you can go to the [[http:// | ||
+ | ===== ROS_Control ===== | ||
+ | |||
+ | ==== Overview ==== | ||
+ | According to its creator, ROS_Control allows you to lower the ROS entry barrier to the driver level. It allow you to focus only on drivers and high level application. ROS_Control is made up by two elements, **controllers** and **a robot hardware abstraction**. They are linked by **hardware interface**. There is a picture. | ||
+ | |||
+ | {{roscontrol.png}} | ||
+ | |||
+ | This image is from the following presentation. | ||
+ | |||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | |||
+ | ==== Setup your URDF file ==== | ||
+ | You need to add in MYROBOT.xacro some transmission elements. One for each **hardware interfaces** you will use. Check the [[http:// | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | <joint name=" | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **MYJOINT** refer to one of your robot joints already define. They must have the **same name**. See the [[http:// | ||
+ | |||
+ | |||
+ | ==== Create the Robot Hardware Abstraction ==== | ||
+ | |||
+ | First make sure you have install ros control. | ||
+ | |||
+ | Then you need to create a new package with the **roscpp** and the **controller_manager** dependencies. | ||
+ | |||
+ | <code bath> | ||
+ | catkin_create_pkg MYPACKAGE roscpp controller_manager | ||
+ | </ | ||
+ | |||
+ | Then paste the following code in src/ | ||
+ | <code c++> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | |||
+ | |||
+ | using namespace transmission_interface; | ||
+ | |||
+ | class MyRobot : public hardware_interface:: | ||
+ | { | ||
+ | public: | ||
+ | MyRobot() | ||
+ | { | ||
+ | //HardWare Interfaces | ||
+ | //connect and register the joint state interface | ||
+ | hardware_interface:: | ||
+ | jnt_state_interface.registerHandle(state_handle_a); | ||
+ | |||
+ | registerInterface(& | ||
+ | |||
+ | //connect and register the joint position interface | ||
+ | hardware_interface:: | ||
+ | jnt_vel_interface.registerHandle(vel_handle_a); | ||
+ | |||
+ | registerInterface(& | ||
+ | } | ||
+ | |||
+ | void write(){ | ||
+ | } | ||
+ | |||
+ | void read(){ | ||
+ | } | ||
+ | |||
+ | private: | ||
+ | //Hardware Interfaces | ||
+ | hardware_interface:: | ||
+ | hardware_interface:: | ||
+ | |||
+ | double j_pos[1]; | ||
+ | double j_vel[1]; | ||
+ | double j_eff[1]; | ||
+ | |||
+ | double j_cmd_pos[1]; | ||
+ | double j_cmd_vel[1]; | ||
+ | double j_cmd_eff[1]; | ||
+ | }; | ||
+ | |||
+ | |||
+ | main(int argc, char **argv) | ||
+ | { | ||
+ | ros:: | ||
+ | |||
+ | ros:: | ||
+ | spinner.start(); | ||
+ | |||
+ | MyRobot robot; | ||
+ | |||
+ | ros:: | ||
+ | controller_manager:: | ||
+ | |||
+ | ros:: | ||
+ | |||
+ | while(ros:: | ||
+ | |||
+ | ROS_INFO(" | ||
+ | robot.read(); | ||
+ | cm.update(ros:: | ||
+ | robot.write(); | ||
+ | |||
+ | usleep(500000); | ||
+ | // | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | There are several things to care in this file. First in the MYROBOT Constructor, | ||
+ | |||
+ | ==== Choose a controller ==== | ||
+ | You can find and leverage a lot of controllers write by the ROS Community in the [[http:// | ||
+ | |||
+ | To understand the next example we will assume that you have create a package name MYROBOT_control with two sub-directories config and launch. | ||
+ | ==== Summary ==== | ||
+ | In your URDF file, take care : **MYJOINT** and **MYINTERFACE**. | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | <joint name=" | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | In your Robot Hardware Abstraction, | ||
+ | <code c++> | ||
+ | //HardWare Interfaces | ||
+ | //connect and register the joint state interface | ||
+ | hardware_interface:: | ||
+ | jnt_state_interface.registerHandle(state_handle_a); | ||
+ | |||
+ | registerInterface(& | ||
+ | |||
+ | //connect and register the joint position interface | ||
+ | hardware_interface:: | ||
+ | my_interface.registerHandle(my_handle_a); | ||
+ | </ | ||
+ | <code c++> | ||
+ | //Hardware Interfaces | ||
+ | hardware_interface:: | ||
+ | hardware_interface:: | ||
+ | </ | ||
+ | In your config file in MYROBOT_control/ | ||
+ | <code yaml> | ||
+ | MYROBOT: | ||
+ | mobile_base_controller: | ||
+ | type: " | ||
+ | left_wheel: ' | ||
+ | right_wheel: | ||
+ | pose_covariance_diagonal: | ||
+ | twist_covariance_diagonal: | ||
+ | </ | ||
+ | In your launch file in MYROBOT_control/ | ||
+ | <code xml> | ||
+ | <!-- Load joint controller configurations from YAML file to parameter server --> | ||
+ | < | ||
+ | |||
+ | < | ||
+ | <node name=" | ||
+ | |||
+ | <!-- load the controllers --> | ||
+ | <node name=" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Gazebo with ros_control ==== | ||
+ | |||
+ | You can use ros_control with GAZEBO, there is a tutorial [[http:// | ||
+ | <code xml> | ||
+ | < | ||
+ | <plugin name=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Ros_control debug tool ==== | ||
+ | You can install a rqt plugin named [[http:// | ||
+ | <code bash> | ||
+ | sudo apt-get install ros-indigo-rqt-controller-manager | ||
+ | </ | ||
+ | Don't forget to add this line to your .bashrc. | ||
+ | <code bash> | ||
+ | # Force rqt plugin database to update | ||
+ | rm -f .config/ | ||
+ | </ | ||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | Interesting links : | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
ros.txt · Last modified: 2020/03/06 09:25 by tvandenbussche