From 2ca39239d743539eeabcdbd0120a4a80aabca694 Mon Sep 17 00:00:00 2001 From: locker98 Date: Sat, 14 Dec 2024 17:01:20 -0500 Subject: [PATCH] added simulation information --- .../{ => Building A Robot}/ROS 2 TF.md | 0 .../General ROS 2/Building A Robot/Sensors.md | 105 ++++++ .../Building A Robot/URDF With XACROs.md | 355 ++++++++++++++++++ .../{ => Building A Robot}/URDF.md | 109 +++++- .../ROS 2 Launch Files.md | 2 +- .../ROS 2 Nodes.md | 0 .../ROS 2 Topics.md | 0 docs/General ROS 2/Gazebo.md | 80 ++++ docs/General ROS 2/Rviz.md | 3 + 9 files changed, 650 insertions(+), 4 deletions(-) rename docs/General ROS 2/{ => Building A Robot}/ROS 2 TF.md (100%) create mode 100755 docs/General ROS 2/Building A Robot/Sensors.md create mode 100755 docs/General ROS 2/Building A Robot/URDF With XACROs.md rename docs/General ROS 2/{ => Building A Robot}/URDF.md (64%) rename docs/General ROS 2/{ => Building ROS 2 Packages}/ROS 2 Nodes.md (100%) rename docs/General ROS 2/{ => Building ROS 2 Packages}/ROS 2 Topics.md (100%) create mode 100755 docs/General ROS 2/Gazebo.md create mode 100755 docs/General ROS 2/Rviz.md diff --git a/docs/General ROS 2/ROS 2 TF.md b/docs/General ROS 2/Building A Robot/ROS 2 TF.md similarity index 100% rename from docs/General ROS 2/ROS 2 TF.md rename to docs/General ROS 2/Building A Robot/ROS 2 TF.md diff --git a/docs/General ROS 2/Building A Robot/Sensors.md b/docs/General ROS 2/Building A Robot/Sensors.md new file mode 100755 index 0000000..39575dc --- /dev/null +++ b/docs/General ROS 2/Building A Robot/Sensors.md @@ -0,0 +1,105 @@ +# Sensors + +## How to use Sensors in URDF and Gazebo +Adding sensors in a URDF for Gazebo is not to difficult if you know the command but it can be very time consuming if you get something wrong. Below is an example of how to setup a generic sensor. You can go [here](https://github.com/ros-simulation/gazebo_ros_pkgs/tree/ros2/gazebo_plugins/include/gazebo_plugins) for more help. +```xml + + + Gazebo/Red + + + 0 0 0 0 0 0 + + true + + 10.0 + + + sensor_link + + + +``` + +## Types of Sensors and configurations +There are many different sensors that can be used in gazebo and in a URDF file and a few of them are listed below. To find more sensor drivers go to the [ros_gazebo github page](https://github.com/ros-simulation/gazebo_ros_pkgs/tree/ros2/gazebo_plugins/include/gazebo_plugins) +### Cameras +To add a camera to a URDF robot and make it work in gazebo you will have to take advantage of the gazebo features in xacro files. below is a sample of how to setup a camera in gazebo. +```xml title="camera.xacro" linenums="1" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gazebo/Red + + + 0 0 0 0 0 0 + + true + + 10.0 + + + camera_link + + + + +- +``` +#### Opencv Camera Fix +In opencv, z is pointing into the image (the blue axis), x is right (the red axis), and y is down (green axis), while in the gazebo camera x is pointing into the image and z is up, y is right which is similar to the robot convention of x being forward and z up. To fix this we have to create a new link and rotate it so that everything lines up properly. To do this add the new link and joint as show below and then change the frame name to the new `camera_link_optical`. + +```xml linenums="1" hl_lines="1-2 4-11 20" + + + + + + + + + + + + Gazebo/Red + + 0 0 0 0 0 0 + true + 10.0 + + camera_link_optical + + + +``` diff --git a/docs/General ROS 2/Building A Robot/URDF With XACROs.md b/docs/General ROS 2/Building A Robot/URDF With XACROs.md new file mode 100755 index 0000000..6ce8a38 --- /dev/null +++ b/docs/General ROS 2/Building A Robot/URDF With XACROs.md @@ -0,0 +1,355 @@ +# URDF With XACRO +## What is XACRO +**URDF** (Unified Robot Description Format) files are often used to describe the physical configuration of a robot. **Xacro** (XML Macros) is an extension of URDF that allows for modularity and reuse of code through macros and parameters. Xacro simplifies complex URDF files by reducing repetition and enabling parameterization. + +When using Xacros in URDF is it important to remember to add it to the XML file at the beginning. +```xml linenums="1" + + + ... + +``` + +## XACRO Features +Below is a list of the common features of XACRO and how they can be used. +### Variables, Parameters, and Math +In XACRO use `xacro:property` to define variables that can be reused or parameterized in the Xacro file. Variables make the URDF more maintainable and flexible. You can math on these store values to help keep the robot dynamic. + +```xml linenums="1" + + + + + + + + + + + + + + + +``` + +### Macros +Xacro allows you to define reusable blocks of XML code using macros. Macros are defined with `` and given a name, then they can be used to repeat a section of XML code. + +```xml linenums="1" + + + + + + + + + + + + + + + +``` +### Conditionals +Xacro allows the use of `if` and `unless` for conditional logic. This is useful for enabling and disabling features or customizing configurations based on parameters. + +```xml linenums="1" + + + + + + + +``` + +### Loops +XACRO also supports looping with `xacro:for`, enabling dynamic generation of repeated elements like links or joints. +```xml linenums="1" + + + + + + + + + + + +``` + +### Include and Modularity +Xacro files can include other Xacro or URDF files using ``. This enables modularity, where different parts of a robot description can be stored in separate files. + +```xml linenums="1" + + +``` + +## Example XACRO File +Here is a example of a URDF file for a small robot that uses XACRO. + +This is the main file: +```xml title="my_robot.urdf.xacro" linenums="1" + + + + + + + +``` + +This is the file the contains the common properties: +```xml title="common_properties.xacro" linenums="1" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + +This is the file the contains the mobile base: +```xml title="mobile_base.xacro" linenums="1" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + + +This is the file the contains the gazebo configs: +```xml title="mobile_base.xacro" linenums="1" + + + + Gazebo/Blue + + + + Gazebo/Gray + + + + Gazebo/Gray + + + + Gazebo/Gray + + + + + + + + 50 + + base_left_wheel_joint + base_right_wheel_joint + + ${wheel_length + base_width} + ${wheel_radius} + + + cmd_vel + + true + true + true + odom + odom + base_footprint + + + +``` + +This is the file the contains the camera configs: +```xml title="mobile_base.xacro" linenums="1" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gazebo/Red + + + 0 0 0 0 0 0 + + true + + 10.0 + + + camera_link + + + + + +``` \ No newline at end of file diff --git a/docs/General ROS 2/URDF.md b/docs/General ROS 2/Building A Robot/URDF.md similarity index 64% rename from docs/General ROS 2/URDF.md rename to docs/General ROS 2/Building A Robot/URDF.md index c5557d7..b9f8bf5 100755 --- a/docs/General ROS 2/URDF.md +++ b/docs/General ROS 2/Building A Robot/URDF.md @@ -87,7 +87,7 @@ here is a sample: ``` ### Materials Materials allow color and other information to be added to a `` -```xml +```xml linenums="1" @@ -111,7 +111,7 @@ Materials allow color and other information to be added to a `` - **Color**: `` uses RGBA values (alpha for transparency). - **Texture**: `` for applying an image. -```xml +```xml linenums="1" @@ -123,6 +123,97 @@ Materials allow color and other information to be added to a `` ``` +#### Inertial +The inertia element is used to calculate the movement of the robot in gazebo. The inertia element is a requirement for the gazebo simulation. To get the 3D tensor for the inertia values use this [Wikipedia link](https://en.wikipedia.org/wiki/List_of_moments_of_inertia#List_of_3D_inertia_tensors). I is usually best to put these inertia calculations in xacro function to allow them to be use all over the robot like shown. + +```xml linenums="1" + + + + + + + + + + + + + + + + + + + + + + + + +``` + +##### Bug +Sometimes the inertial values have to be increased to fix drifting in gazebo. To do this usual you just multiply all the inertial input by `2` or `3`. +```xml linenums="1" + +``` +#### Collisions +The collision element is added inside the link element to give gazebo the information on the collision shape of the robot. This is usually a simplify shape to make the simulation easy on the computer. +```xml linenums="1" + + + + + + +``` + +### Gazebo +The gazebo element allows you to specifies information for gazebo. +#### Plugin +The plugin feature of URDF for gazebo lets you add ROS topics to URDF files so that you can simulate different inputs and outputs of values. + +```xml + + + + 50 + + base_left_wheel_joint + base_right_wheel_joint + + ${wheel_length + base_width} + ${wheel_radius} + + cmd_vel + + true + true + true + odom + odom + base_footprint + + +``` + +#### Material +Adding material to gazebo you have to add a custom gazebo material. +```xml + + + + Gazebo/Gray + + + + +``` ### Joints Joints are what old different objects together. There are many different types of joints as shown below. There are also different parts to a joint. The `` link tells the join what it is attached to while the `` link tells it what its child is. The `` section tells the joint where it is located with the `xyz`being the coordinates and the `rpy` being role, pitch, and yaw. The `` section indicates a 1 for allowed moment and a 0 for no movement. Finally the `` section gives a lower and upper bound. @@ -189,7 +280,19 @@ This joint allows motion in a plane perpendicular to the axis. ``` - +### Meshes +This allows you to import meshes into your URDF from CAD programs. This allows you to add complex parts to your robot. +```xml + + + + + + + + + +``` ## Links For Help Here are some links for help. - [ROS.org](https://wiki.ros.org/urdf/XML) \ No newline at end of file diff --git a/docs/General ROS 2/Building ROS 2 Packages/ROS 2 Launch Files.md b/docs/General ROS 2/Building ROS 2 Packages/ROS 2 Launch Files.md index bfd65e9..1edf477 100755 --- a/docs/General ROS 2/Building ROS 2 Packages/ROS 2 Launch Files.md +++ b/docs/General ROS 2/Building ROS 2 Packages/ROS 2 Launch Files.md @@ -5,7 +5,7 @@ ## Creating Launch File Package When creating a launch file in ROS 2 you have to use the `ros2 pkg create package_name`. Once the package is created delete all the folders in the package folder and create a folder called `launch` inside this folder you can put all the launch files. Finally edit the `CMakeLists.txt` so that it looks like the one below. -```cmake title="CMakeLists.txt" linenums="1" +```cmake linenums="1" cmake_minimum_required(VERSION 3.8) project(my_robot1_description) diff --git a/docs/General ROS 2/ROS 2 Nodes.md b/docs/General ROS 2/Building ROS 2 Packages/ROS 2 Nodes.md similarity index 100% rename from docs/General ROS 2/ROS 2 Nodes.md rename to docs/General ROS 2/Building ROS 2 Packages/ROS 2 Nodes.md diff --git a/docs/General ROS 2/ROS 2 Topics.md b/docs/General ROS 2/Building ROS 2 Packages/ROS 2 Topics.md similarity index 100% rename from docs/General ROS 2/ROS 2 Topics.md rename to docs/General ROS 2/Building ROS 2 Packages/ROS 2 Topics.md diff --git a/docs/General ROS 2/Gazebo.md b/docs/General ROS 2/Gazebo.md new file mode 100755 index 0000000..510239d --- /dev/null +++ b/docs/General ROS 2/Gazebo.md @@ -0,0 +1,80 @@ +# Gazebo +## Installing Gazebo +### Installing Gazebo Classic +To install gazebo classic: +```bash +sudo apt install ros-humble-gazebo-* +``` + +Sometimes gazebo has the wrong resource path and the correct one has to be added to the `~/.bashrc` file. +```bash +export GAZEBO_RESOURCE_PATH=/usr/share/gazebo-11 +``` + +### Installing Gazebo Latest +To install the latest version of gazebo go to the [official gazebo installation page](https://gazebosim.org/docs/latest/ros_installation/) and follow the instruction for the correct version of ROS. + + +## Launching Gazebo Classic +To launch gazebo classic simply run `gazebo`: +```bash +gazebo +``` + +If you want to launch gazebo with ROS2 you will have to use its launch file: +```bash +ros2 launch gazebo_ros gazebo.launch.py +``` + +It can be trick to use a the gazebo launch file in another launch file but it can be done with the following code: +```xml + +``` + +## Using a robot in Gazebo Classic +To get robot to appear in a Gazebo world first launch gazebo like show previously. Then use the following commands to advertise the robot description and spawn it in gazebo. + +Terminal: +```bash +# start gazebo +ros2 launch gazebo_ros gazebo.launch.py +# advertise the robot description +ros2 run robot_state_publisher robot_state_publisher --ros-args -p robot_description:="$(xacro /path/to/my_robot1.urdf.xacro)" +# spawn robot +ros2 run gazebo_ros spawn_entity.py -topic robot_description -entity my_robot1 +``` +launch file: +```xml + + + + + + + + + + + + + + + +``` + +## Building and Launching a World +To build a world in gazebo you can follow this [tutorial](https://youtu.be/9Q2IuoVbqYo) Once the world is build and save it can be launch with the following command. + +```bash +gazebo test_world.world.xml +``` +or +```bash +ros2 launch gazebo_ros gazebo.launch.py world:=test_world.world.xml +``` +or in an XML launch file +```xml + + + +``` \ No newline at end of file diff --git a/docs/General ROS 2/Rviz.md b/docs/General ROS 2/Rviz.md new file mode 100755 index 0000000..631f598 --- /dev/null +++ b/docs/General ROS 2/Rviz.md @@ -0,0 +1,3 @@ +# Rviz + +