added simulation information
This commit is contained in:
parent
9a6115be31
commit
2ca39239d7
105
docs/General ROS 2/Building A Robot/Sensors.md
Executable file
105
docs/General ROS 2/Building A Robot/Sensors.md
Executable file
@ -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 reference="sensor_link">
|
||||||
|
<!-- Set the material for the sensor -->
|
||||||
|
<material>Gazebo/Red</material>
|
||||||
|
<sensor name="sensor_name" type="sensor_type">
|
||||||
|
<!-- Pose of the sensor: x y z r p y -->
|
||||||
|
<pose>0 0 0 0 0 0</pose>
|
||||||
|
<!-- Visualize the sensor in Gazebo -->
|
||||||
|
<visualize>true</visualize>
|
||||||
|
<!-- Update rate in Hz -->
|
||||||
|
<update_rate>10.0</update_rate>
|
||||||
|
<plugin name="sensor_controller" filename="libgazebo_ros_sensor.so">
|
||||||
|
<!-- Reference link for the sensor -->
|
||||||
|
<frame_name>sensor_link</frame_name>
|
||||||
|
</plugin>
|
||||||
|
</sensor>
|
||||||
|
</gazebo>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
|
||||||
|
<xacro:property name="camera_length" value="0.01"/>
|
||||||
|
<xacro:property name="camera_width" value="0.1"/>
|
||||||
|
<xacro:property name="camera_height" value="0.05"/>
|
||||||
|
|
||||||
|
|
||||||
|
<link name="camera_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<box size="${camera_length} ${camera_width} ${camera_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
<material name="gray" />
|
||||||
|
</visual>
|
||||||
|
<collision>
|
||||||
|
<geometry>
|
||||||
|
<box size="${camera_length} ${camera_width} ${camera_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
</collision>
|
||||||
|
<xacro:box_inertia m="0.1" l="${camera_length}" w="${camera_width}" h="${camera_height}" xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
</link>
|
||||||
|
|
||||||
|
<joint name="base_camera_joint" type="fixed">
|
||||||
|
<parent link="base_link"/>
|
||||||
|
<child link="camera_link"/>
|
||||||
|
<origin xyz="${(base_length + camera_length)/ 2} 0 ${base_height/2}" rpy="0 0 0"/>
|
||||||
|
</joint>
|
||||||
|
|
||||||
|
<gazebo reference="camera_link">
|
||||||
|
<material>Gazebo/Red</material>
|
||||||
|
<sensor name="camera_sensor" type="camera">
|
||||||
|
<!-- x y z r p y-->
|
||||||
|
<pose>0 0 0 0 0 0</pose>
|
||||||
|
<!-- whether you can see projection in gazebo or not-->
|
||||||
|
<visualize>true</visualize>
|
||||||
|
<!-- update rate in hz-->
|
||||||
|
<update_rate>10.0</update_rate>
|
||||||
|
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
|
||||||
|
<!-- camera link -->
|
||||||
|
<frame_name>camera_link</frame_name>
|
||||||
|
</plugin>
|
||||||
|
</sensor>
|
||||||
|
</gazebo>
|
||||||
|
|
||||||
|
</robot>-
|
||||||
|
```
|
||||||
|
#### 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"
|
||||||
|
<link name="camera_link_optical">
|
||||||
|
</link>
|
||||||
|
|
||||||
|
<joint name="camera_optical_joint" type="fixed">
|
||||||
|
<!-- these values have to be these values otherwise the gazebo camera
|
||||||
|
image won't be aligned properly with the frame it is supposedly
|
||||||
|
originating from -->
|
||||||
|
<origin xyz="0 0 0" rpy="${-pi/2} 0 ${-pi/2}"/>
|
||||||
|
<parent link="camera_link"/>
|
||||||
|
<child link="camera_link_optical"/>
|
||||||
|
</joint>
|
||||||
|
|
||||||
|
<gazebo reference="camera_link">
|
||||||
|
<material>Gazebo/Red</material>
|
||||||
|
<sensor name="camera_sensor" type="camera">
|
||||||
|
<pose>0 0 0 0 0 0</pose>
|
||||||
|
<visualize>true</visualize>
|
||||||
|
<update_rate>10.0</update_rate>
|
||||||
|
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
|
||||||
|
<frame_name>camera_link_optical</frame_name>
|
||||||
|
</plugin>
|
||||||
|
</sensor>
|
||||||
|
</gazebo>
|
||||||
|
```
|
355
docs/General ROS 2/Building A Robot/URDF With XACROs.md
Executable file
355
docs/General ROS 2/Building A Robot/URDF With XACROs.md
Executable file
@ -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"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot name="my_robot1" xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
...
|
||||||
|
</robot>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot name="my_robot1" xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
<xacro:property name="base_length" value="0.6"/>
|
||||||
|
<xacro:property name="base_width" value="0.4"/>
|
||||||
|
<xacro:property name="base_height" value="0.2"/>
|
||||||
|
|
||||||
|
<link name="base_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<box size="${base_length} ${base_width} ${base_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0.1" rpy="${pi / 2} 0 0"/>
|
||||||
|
</visual>
|
||||||
|
</link>
|
||||||
|
</robot>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Macros
|
||||||
|
Xacro allows you to define reusable blocks of XML code using macros. Macros are defined with `<xacro:macro>` and given a name, then they can be used to repeat a section of XML code.
|
||||||
|
|
||||||
|
```xml linenums="1"
|
||||||
|
<xacro:macro name="example_macro" params="prefix">
|
||||||
|
<link name="${prefix}_wheel_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<cylinder radius="${wheel_radius}" length="${wheel_length}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="${pi / 2.0} 0 0"/>
|
||||||
|
<material name="gray"/>
|
||||||
|
</visual>
|
||||||
|
</link>
|
||||||
|
</xacro:macro>
|
||||||
|
|
||||||
|
<xacro:example_macro prefix="right" />
|
||||||
|
<xacro:example_macro prefix="left" />
|
||||||
|
|
||||||
|
```
|
||||||
|
### 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"
|
||||||
|
<xacro:property name="use_lidar" value="true" />
|
||||||
|
|
||||||
|
<xacro:if value="${use_lidar}">
|
||||||
|
<link name="lidar_link">
|
||||||
|
<!-- Lidar geometry -->
|
||||||
|
</link>
|
||||||
|
</xacro:if>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Loops
|
||||||
|
XACRO also supports looping with `xacro:for`, enabling dynamic generation of repeated elements like links or joints.
|
||||||
|
```xml linenums="1"
|
||||||
|
<xacro:property name="num_wheels" value="4" />
|
||||||
|
|
||||||
|
<xacro:for each="i" end="${num_wheels - 1}">
|
||||||
|
<link name="wheel_${i}">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<cylinder radius="0.1" length="0.05" />
|
||||||
|
</geometry>
|
||||||
|
</visual>
|
||||||
|
</link>
|
||||||
|
</xacro:for>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Include and Modularity
|
||||||
|
Xacro files can include other Xacro or URDF files using `<xacro:include>`. This enables modularity, where different parts of a robot description can be stored in separate files.
|
||||||
|
|
||||||
|
```xml linenums="1"
|
||||||
|
<xacro:include filename="common_parts.xacro" />
|
||||||
|
<xacro:call macro="common_part" />
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot name="my_robot1" xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
<xacro:include filename="common_properties.xacro" />
|
||||||
|
<xacro:include filename="mobile_base.xacro" />
|
||||||
|
<xacro:include filename="mobile_base_gazebo.xacro" />
|
||||||
|
<xacro:include filename="camera.xacro" />
|
||||||
|
</robot>
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the file the contains the common properties:
|
||||||
|
```xml title="common_properties.xacro" linenums="1"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
|
||||||
|
<material name="blue">
|
||||||
|
<color rgba="0 0 0.5 1"/>
|
||||||
|
</material>
|
||||||
|
|
||||||
|
<material name="gray">
|
||||||
|
<color rgba="0.5 0.5 0.5 1.0"/>
|
||||||
|
</material>
|
||||||
|
|
||||||
|
<xacro:macro name="box_inertia" params="m l w h xyz rpy">
|
||||||
|
<inertial>
|
||||||
|
<mass value="${m}"/>
|
||||||
|
<origin xyz="${xyz}" rpy="${rpy}"/>
|
||||||
|
<inertia ixx="${(m/12) * (h*h + l*l)}" ixy="0" ixz="0"
|
||||||
|
iyy="${(m/12) * (w*w + l*l)}" iyz="0"
|
||||||
|
izz="${(m/12) * (w*w + h*h)}" />
|
||||||
|
</inertial>
|
||||||
|
</xacro:macro>
|
||||||
|
|
||||||
|
<xacro:macro name="cylinder_inertia" params="m r h xyz rpy">
|
||||||
|
<inertial>
|
||||||
|
<mass value="${m}"/>
|
||||||
|
<origin xyz="${xyz}" rpy="${rpy}"/>
|
||||||
|
<inertia ixx="${(m/12) * (3*r*r + h*h)}" ixy="0" ixz="0"
|
||||||
|
iyy="${(m/12) * (3*r*r + h*h)}" iyz="0"
|
||||||
|
izz="${(2/m) * (r*r)}" />
|
||||||
|
</inertial>
|
||||||
|
</xacro:macro>
|
||||||
|
|
||||||
|
<xacro:macro name="sphere_inertia" params="m r xyz rpy">
|
||||||
|
<inertial>
|
||||||
|
<mass value="${m}"/>
|
||||||
|
<origin xyz="${xyz}" rpy="${rpy}"/>
|
||||||
|
<inertia ixx="${(2/5) * m * r * r}" ixy="0" ixz="0"
|
||||||
|
iyy="${(2/5) * m * r * r}" iyz="0"
|
||||||
|
izz="${(2/5) * m * r * r}" />
|
||||||
|
</inertial>
|
||||||
|
</xacro:macro>
|
||||||
|
|
||||||
|
</robot>
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the file the contains the mobile base:
|
||||||
|
```xml title="mobile_base.xacro" linenums="1"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
|
||||||
|
<xacro:property name="base_length" value="0.6"/>
|
||||||
|
<xacro:property name="base_width" value="0.4"/>
|
||||||
|
<xacro:property name="base_height" value="0.2"/>
|
||||||
|
<xacro:property name="wheel_radius" value="0.1"/>
|
||||||
|
<xacro:property name="wheel_length" value="0.05"/>
|
||||||
|
|
||||||
|
|
||||||
|
<xacro:macro name="wheel_macro" params="prefix">
|
||||||
|
<link name="${prefix}_wheel_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<cylinder radius="${wheel_radius}" length="${wheel_length}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="${pi / 2.0} 0 0"/>
|
||||||
|
<material name="gray"/>
|
||||||
|
</visual>
|
||||||
|
<collision>
|
||||||
|
<geometry>
|
||||||
|
<cylinder radius="${wheel_radius}" length="${wheel_length}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="${pi / 2.0} 0 0"/>
|
||||||
|
</collision>
|
||||||
|
<xacro:cylinder_inertia m="1.0" r="${2*wheel_radius}" h="${2*wheel_length}"
|
||||||
|
xyz="0 0 0" rpy="${pi / 2.0} 0 0"/>
|
||||||
|
</link>
|
||||||
|
</xacro:macro>
|
||||||
|
|
||||||
|
|
||||||
|
<link name="base_footprint">
|
||||||
|
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
</link>
|
||||||
|
|
||||||
|
<link name="base_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<box size="${base_length} ${base_width} ${base_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 ${base_height/2.0}" rpy="0 0 0"/>
|
||||||
|
<material name="blue"/>
|
||||||
|
</visual>
|
||||||
|
<collision>
|
||||||
|
<geometry>
|
||||||
|
<box size="${base_length} ${base_width} ${base_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 ${base_height/2.0}" rpy="0 0 0"/>
|
||||||
|
</collision>
|
||||||
|
<xacro:box_inertia m="5.0" l="${2*base_length}" w="${2*base_width}" h="${2*base_height}"
|
||||||
|
xyz="0 0 ${base_height/2.0}" rpy="0 0 0"/>
|
||||||
|
</link>
|
||||||
|
|
||||||
|
<xacro:wheel_macro prefix="right" />
|
||||||
|
<xacro:wheel_macro prefix="left" />
|
||||||
|
|
||||||
|
<link name="caster_wheel_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<sphere radius="${wheel_radius / 2.0}" />
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
<material name="gray"/>
|
||||||
|
</visual>
|
||||||
|
<collision>
|
||||||
|
<geometry>
|
||||||
|
<sphere radius="${wheel_radius / 2.0}" />
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
</collision>
|
||||||
|
<xacro:sphere_inertia m="0.5" r="${2*wheel_radius / 2.0}"
|
||||||
|
xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
</link>
|
||||||
|
|
||||||
|
<joint name="base_joint" type="fixed">
|
||||||
|
<parent link="base_footprint" />
|
||||||
|
<child link="base_link" />
|
||||||
|
<origin xyz="0 0 ${wheel_radius}" rpy="0 0 0" />
|
||||||
|
</joint>
|
||||||
|
|
||||||
|
<joint name="base_left_wheel_joint" type="continuous">
|
||||||
|
<parent link="base_link" />
|
||||||
|
<child link="left_wheel_link" />
|
||||||
|
<origin xyz="${base_length / -4.0} ${base_width/2 + wheel_length/2} 0" rpy="0 0 0" />
|
||||||
|
<axis xyz="0 1 0"/>
|
||||||
|
</joint>
|
||||||
|
|
||||||
|
<joint name="base_right_wheel_joint" type="continuous">
|
||||||
|
<parent link="base_link" />
|
||||||
|
<child link="right_wheel_link" />
|
||||||
|
<origin xyz="${base_length / -4.0} -${base_width/2 + wheel_length/2} 0" rpy="0 0 0" />
|
||||||
|
<axis xyz="0 1 0"/>
|
||||||
|
</joint>
|
||||||
|
|
||||||
|
<joint name="base_caster_wheel_joint" type="fixed">
|
||||||
|
<parent link="base_link" />
|
||||||
|
<child link="caster_wheel_link" />
|
||||||
|
<origin xyz="${base_length / 3.0} 0 -${wheel_radius / 2}" rpy="0 0 0" />
|
||||||
|
</joint>
|
||||||
|
</robot>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
This is the file the contains the gazebo configs:
|
||||||
|
```xml title="mobile_base.xacro" linenums="1"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
<gazebo reference="base_link">
|
||||||
|
<material>Gazebo/Blue</material>
|
||||||
|
</gazebo>
|
||||||
|
|
||||||
|
<gazebo reference="right_wheel_link">
|
||||||
|
<material>Gazebo/Gray</material>
|
||||||
|
</gazebo>
|
||||||
|
|
||||||
|
<gazebo reference="left_wheel_link">
|
||||||
|
<material>Gazebo/Gray</material>
|
||||||
|
</gazebo>
|
||||||
|
|
||||||
|
<gazebo reference="caster_wheel_link">
|
||||||
|
<material>Gazebo/Gray</material>
|
||||||
|
<mu1 value="0.1" />
|
||||||
|
<mu2 value="0.1" />
|
||||||
|
</gazebo>
|
||||||
|
|
||||||
|
<gazebo>
|
||||||
|
<plugin name="diff_drive_controller" filename="libgazebo_ros_diff_drive.so">
|
||||||
|
<!-- Update rate in Hz -->
|
||||||
|
<update_rate>50</update_rate>
|
||||||
|
<!-- Wheels -->
|
||||||
|
<left_joint>base_left_wheel_joint</left_joint>
|
||||||
|
<right_joint>base_right_wheel_joint</right_joint>
|
||||||
|
<!-- Size -->
|
||||||
|
<wheel_separation>${wheel_length + base_width}</wheel_separation>
|
||||||
|
<wheel_diameter>${wheel_radius}</wheel_diameter>
|
||||||
|
|
||||||
|
<!-- Ros Topic -->
|
||||||
|
<command_topic>cmd_vel</command_topic>
|
||||||
|
<!-- output -->
|
||||||
|
<publish_odom>true</publish_odom>
|
||||||
|
<publish_odom_tf>true</publish_odom_tf>
|
||||||
|
<publish_wheel_tf>true</publish_wheel_tf>
|
||||||
|
<odometry_topic>odom</odometry_topic>
|
||||||
|
<odometry_frame>odom</odometry_frame>
|
||||||
|
<robot_base_frame>base_footprint</robot_base_frame>
|
||||||
|
</plugin>
|
||||||
|
</gazebo>
|
||||||
|
</robot>
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the file the contains the camera configs:
|
||||||
|
```xml title="mobile_base.xacro" linenums="1"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||||
|
|
||||||
|
<xacro:property name="camera_length" value="0.01"/>
|
||||||
|
<xacro:property name="camera_width" value="0.1"/>
|
||||||
|
<xacro:property name="camera_height" value="0.05"/>
|
||||||
|
|
||||||
|
|
||||||
|
<link name="camera_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<box size="${camera_length} ${camera_width} ${camera_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
<material name="gray" />
|
||||||
|
</visual>
|
||||||
|
<collision>
|
||||||
|
<geometry>
|
||||||
|
<box size="${camera_length} ${camera_width} ${camera_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
</collision>
|
||||||
|
<xacro:box_inertia m="0.1" l="${camera_length}" w="${camera_width}" h="${camera_height}" xyz="0 0 0" rpy="0 0 0"/>
|
||||||
|
</link>
|
||||||
|
|
||||||
|
<joint name="base_camera_joint" type="fixed">
|
||||||
|
<parent link="base_link"/>
|
||||||
|
<child link="camera_link"/>
|
||||||
|
<origin xyz="${(base_length + camera_length)/ 2} 0 ${base_height/2}" rpy="0 0 0"/>
|
||||||
|
</joint>
|
||||||
|
|
||||||
|
<gazebo reference="camera_link">
|
||||||
|
<material>Gazebo/Red</material>
|
||||||
|
<sensor name="camera_sensor" type="camera">
|
||||||
|
<!-- x y z r p y-->
|
||||||
|
<pose>0 0 0 0 0 0</pose>
|
||||||
|
<!-- whether you can see projection in gazebo or not-->
|
||||||
|
<visualize>true</visualize>
|
||||||
|
<!-- update rate in hz-->
|
||||||
|
<update_rate>10.0</update_rate>
|
||||||
|
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
|
||||||
|
<!-- camera link -->
|
||||||
|
<frame_name>camera_link</frame_name>
|
||||||
|
</plugin>
|
||||||
|
</sensor>
|
||||||
|
</gazebo>
|
||||||
|
|
||||||
|
</robot>
|
||||||
|
```
|
@ -87,7 +87,7 @@ here is a sample:
|
|||||||
```
|
```
|
||||||
### Materials
|
### Materials
|
||||||
Materials allow color and other information to be added to a `<visual>`
|
Materials allow color and other information to be added to a `<visual>`
|
||||||
```xml
|
```xml linenums="1"
|
||||||
<material name="green">
|
<material name="green">
|
||||||
<color rgba='0 1 0 0'>
|
<color rgba='0 1 0 0'>
|
||||||
</material>
|
</material>
|
||||||
@ -111,7 +111,7 @@ Materials allow color and other information to be added to a `<visual>`
|
|||||||
- **Color**: `<color rgba="r g b a" />` uses RGBA values (alpha for transparency).
|
- **Color**: `<color rgba="r g b a" />` uses RGBA values (alpha for transparency).
|
||||||
- **Texture**: `<texture filename="path/to/texture" />` for applying an image.
|
- **Texture**: `<texture filename="path/to/texture" />` for applying an image.
|
||||||
|
|
||||||
```xml
|
```xml linenums="1"
|
||||||
<link name="base_link">
|
<link name="base_link">
|
||||||
<visual>
|
<visual>
|
||||||
<geometry>
|
<geometry>
|
||||||
@ -123,6 +123,97 @@ Materials allow color and other information to be added to a `<visual>`
|
|||||||
</link>
|
</link>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 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"
|
||||||
|
<xacro:macro name="box_inertia" params="m l w h xyz rpy">
|
||||||
|
<inertial>
|
||||||
|
<mass value="${m}"/>
|
||||||
|
<origin xyz="${xyz}" rpy="${rpy}"/>
|
||||||
|
<inertia ixx="${(m/12) * (h*h + l*l)}" ixy="0" ixz="0"
|
||||||
|
iyy="${(m/12) * (w*w + l*l)}" iyz="0"
|
||||||
|
izz="${(m/12) * (w*w + h*h)}" />
|
||||||
|
</inertial>
|
||||||
|
</xacro:macro>
|
||||||
|
|
||||||
|
<link name="base_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<box size="${base_length} ${base_width} ${base_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 ${base_height/2.0}" rpy="0 0 0"/>
|
||||||
|
<material name="blue"/>
|
||||||
|
</visual>
|
||||||
|
<collision>
|
||||||
|
<geometry>
|
||||||
|
<box size="${base_length} ${base_width} ${base_height}"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 ${base_height/2.0}" rpy="0 0 0"/>
|
||||||
|
</collision>
|
||||||
|
<xacro:box_inertia m="5.0" l="${base_length}" w="${base_width}" h="${base_height}"
|
||||||
|
xyz="0 0 ${base_height/2.0}" rpy="0 0 0"/>
|
||||||
|
</link>
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 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"
|
||||||
|
<xacro:box_inertia m="5.0" l="${base_length * 2}" w="${base_width * 2}" h="${base_height * 2}"
|
||||||
|
xyz="0 0 ${base_height/2.0}" rpy="0 0 0"/>
|
||||||
|
```
|
||||||
|
#### 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"
|
||||||
|
<collision>
|
||||||
|
<geometry>
|
||||||
|
<cylinder radius="4" length="4"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0" rpy="${pi / 2.0} 0 0"/>
|
||||||
|
</collision>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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
|
||||||
|
<gazebo>
|
||||||
|
<plugin name="diff_drive_controller" filename="libgazebo_ros_diff_drive.so">
|
||||||
|
<!-- Update rate in Hz -->
|
||||||
|
<update_rate>50</update_rate>
|
||||||
|
<!-- Wheels -->
|
||||||
|
<left_joint>base_left_wheel_joint</left_joint>
|
||||||
|
<right_joint>base_right_wheel_joint</right_joint>
|
||||||
|
<!-- Size -->
|
||||||
|
<wheel_separation>${wheel_length + base_width}</wheel_separation>
|
||||||
|
<wheel_diameter>${wheel_radius}</wheel_diameter>
|
||||||
|
<!-- Ros Topic -->
|
||||||
|
<command_topic>cmd_vel</command_topic>
|
||||||
|
<!-- output -->
|
||||||
|
<publish_odom>true</publish_odom>
|
||||||
|
<publish_odom_tf>true</publish_odom_tf>
|
||||||
|
<publish_wheel_tf>true</publish_wheel_tf>
|
||||||
|
<odometry_topic>odom</odometry_topic>
|
||||||
|
<odometry_frame>odom</odometry_frame>
|
||||||
|
<robot_base_frame>base_footprint</robot_base_frame>
|
||||||
|
</plugin>
|
||||||
|
</gazebo>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Material
|
||||||
|
Adding material to gazebo you have to add a custom gazebo material.
|
||||||
|
```xml
|
||||||
|
<!-- the reference field gives gazebo the URDF link element -->
|
||||||
|
<gazebo reference="link_name">
|
||||||
|
<!-- Material Color -->
|
||||||
|
<material>Gazebo/Gray</material>
|
||||||
|
<!-- friction values -->
|
||||||
|
<mu1 value="0.1" />
|
||||||
|
<mu2 value="0.1" />
|
||||||
|
</gazebo>
|
||||||
|
```
|
||||||
|
|
||||||
### Joints
|
### 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 `<parent>` link tells the join what it is attached to while the `<child>` link tells it what its child is. The `<origin>` section tells the joint where it is located with the `xyz`being the coordinates and the `rpy` being role, pitch, and yaw. The `<axis>` section indicates a 1 for allowed moment and a 0 for no movement. Finally the `<limit>` section gives a lower and upper bound.
|
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 `<parent>` link tells the join what it is attached to while the `<child>` link tells it what its child is. The `<origin>` section tells the joint where it is located with the `xyz`being the coordinates and the `rpy` being role, pitch, and yaw. The `<axis>` section indicates a 1 for allowed moment and a 0 for no movement. Finally the `<limit>` section gives a lower and upper bound.
|
||||||
@ -189,7 +280,19 @@ This joint allows motion in a plane perpendicular to the axis.
|
|||||||
</joint>
|
</joint>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Meshes
|
||||||
|
This allows you to import meshes into your URDF from CAD programs. This allows you to add complex parts to your robot.
|
||||||
|
```xml
|
||||||
|
<link name="base_link">
|
||||||
|
<visual>
|
||||||
|
<geometry>
|
||||||
|
<mesh filename="package://package/meshes/folder_name/filename.stl" scale="0.001 0.001 0.001"/>
|
||||||
|
</geometry>
|
||||||
|
<origin xyz="0 0 0.1" rpy="0 0 0"/>
|
||||||
|
<material name="green" />
|
||||||
|
</visual>
|
||||||
|
</link>
|
||||||
|
```
|
||||||
## Links For Help
|
## Links For Help
|
||||||
Here are some links for help.
|
Here are some links for help.
|
||||||
- [ROS.org](https://wiki.ros.org/urdf/XML)
|
- [ROS.org](https://wiki.ros.org/urdf/XML)
|
@ -5,7 +5,7 @@
|
|||||||
## Creating Launch File Package
|
## 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.
|
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)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
project(my_robot1_description)
|
project(my_robot1_description)
|
||||||
|
|
||||||
|
80
docs/General ROS 2/Gazebo.md
Executable file
80
docs/General ROS 2/Gazebo.md
Executable file
@ -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
|
||||||
|
<include file="$(find-pkg-share gazebo_ros)/launch/gazebo.launch.py" />
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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
|
||||||
|
<launch>
|
||||||
|
<let name="urdf_path" value="$(find-pkg-share my_robot1_description)/urdf/my_robot1.urdf.xacro"/>
|
||||||
|
<let name="rviz_config_path" value="$(find-pkg-share my_robot1_bringup)/rviz/urdf_config.rviz"/>
|
||||||
|
|
||||||
|
<node pkg="robot_state_publisher" exec="robot_state_publisher">
|
||||||
|
<param name="robot_description" value="$(command 'xacro $(var urdf_path)')"/>
|
||||||
|
</node>
|
||||||
|
|
||||||
|
<include file="$(find-pkg-share gazebo_ros)/launch/gazebo.launch.py">
|
||||||
|
<arg name="world" value="$(find-pkg-share my_robot1_bringup)/worlds/test_world.world.xml"/>
|
||||||
|
</include>
|
||||||
|
|
||||||
|
<node pkg="gazebo_ros" exec="spawn_entity.py" args="-topic robot_description -entity my_robot1"/>
|
||||||
|
<node pkg="rviz2" exec="rviz2" output="screen" args="-d $(var rviz_config_path)" />
|
||||||
|
</launch>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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
|
||||||
|
<include file="$(find-pkg-share gazebo_ros)/launch/gazebo.launch.py">
|
||||||
|
<arg name="world" value="$(find-pkg-share my_robot1_bringup)/worlds/test_world.world.xml"/>
|
||||||
|
</include>
|
||||||
|
```
|
3
docs/General ROS 2/Rviz.md
Executable file
3
docs/General ROS 2/Rviz.md
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
# Rviz
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user