Mapping
Mapping
Hiwonder Website
1. URDF Model
The Unified Robot Description Format (URDF) is an XML file format widely
used in ROS (Robot Operating System) to comprehensively describe all
components of a robot.
Robots are typically composed of multiple links and joints. A link is defined as a
rigid object with certain physical properties, while a joint connects two links and
constrains their relative motion.
The URDF model serves as a description file for simple robot models, offering
a clear and easily understandable structure. However, when it comes to
describing complex robot structures, using URDF alone can result in lengthy
and unclear descriptions.
To address this limitation, the xacro model extends the capabilities of URDF
while maintaining its core features. The xacro format provides a more
advanced approach to describe robot structures. It greatly improves code
reusability and helps avoid excessive description length.
For instance, when describing the two legs of a humanoid robot, the URDF
model would require separate descriptions for each leg. On the other hand, the
xacro model allows for describing a single leg and reusing that description for
the other leg, resulting in a more concise and efficient representation.
2
1.3 Basic Syntax of URDF Model
Elements:
<element>
</element>
Properties:
<element
property_1="property value1"
property_2="property value2">
</element>
Comments:
1.3.2 Link
The Link element describes the visual and physical properties of the robot's
3
rigid component. The following tags are commonly used to define the motion of
a link:
<visual>: Describe the appearance of the link, such as size, color and shape.
<inertial>: Describe the inertia parameters of the link, which will used in
dynamics calculation.
Each tag contains the corresponding child tag. The functions of the tags are
listed below.
Tag Function
4
Describe the shape of the link. It uses
1.3.3 Joint
The "Joint" tag describes the kinematic and dynamic properties of the robot's
joints, including the joint's range of motion, target positions, and speed
limitations. In terms of motion style, joints can be categorized into six types.
5
<parent_link>: Parent link
The function of each tag is listed below. Each tag involves one or several child
tags.
Tag Function
6
range applied during rotation (values:
(m/s).
The complete top tags of a robot, including the <link> and <joint> tags, must
be enclosed within the <robot> tag. The format is as follows:
This tag is used in conjunction with the Gazebo simulator. Within this tag, you
can define simulation parameters and import Gazebo plugins, as well as
specify Gazebo's physical properties, and more.
7
1.3.6 Write Simple URDF Model
To start writing the URDF model, we need to set the name of the robot
following this format: “<robot name=“robot model name”>”. Lastly, input
“</robot>” at the end to represent that the model is written successfully.
1) To write the first link and use indentation to indicate that it is part of the
currently set model. Set the name of the link using the following format:
<link name="link name">. Finally, conclude with "</link>" to indicate the
successful completion of the link definition.
2) Write the link description and use indentation to indicate that it is part of the
currently set link, and conclude with "</visual>".
3) The "<geometry>" tag is employed to define the shape of a link. Once the
description is complete, include "</geometry>". Within the "<geometry>"
tag, indentation is used to specify the detailed description of the link's
shape. The following example demonstrates a link with a cylindrical shape:
"<cylinder length="0.01" radius="0.2"/>". In this instance,
8
"length="0.01"" signifies a length of 0.01 meters for the link, while
"radius="0.2"" denotes a radius of 0.2 meters, resulting in a cylindrical
shape.
5) The "<material>" tag is used to define the visual appearance of a link, with
indentation used to specify the detailed description of the link's color. To
start describing the color, include "<material>", and end with "</material>"
when the description is complete. The following example demonstrates
setting a link color to yellow: "<color rgba="1 1 0 1" />". In this example,
"rgba="1 1 0 1"" represents the color threshold for achieving a yellow
color.
1) To write the first joint, use indentation to indicate that the joint belongs to
the current model being set. Then, specify the name and type of the joint
as follows: "<joint name="joint name" type="joint type">". Finally,
9
include "</joint>" to indicate the completion of the joint definition.
Note: to learn about the type of the joint, please refer to “4.2 joint”.
2) Write the description section for the connection between the link and the
joint. Use indentation to indicate that it is part of the currently defined joint.
The parent parameter and child parameter should be set using the
following format: "<parent link="parent link"/>", and "<child link="child
link" />". With the parent link serving as the pivot, the joint rotates the child
link.
3) “<origin>” describes the position of the joint using indention. This example
describes the position of the joint: “<origin xyz=“0 0 0.1” />”. xyz is the
coordinate of the joint.
10
upper=“upper limit in radians”.
11
12
2. Explanation of ROS Robot URDF Model
2.1 Preparation
To grasp the URDF model, check out "1.3 Basic Syntax of URDF Model" for
the key syntax. This part quickly breaks down the robot model code and its
components.
1) Start the robot, and access the robot system desktop using NoMachine.
3) Execute the command and hit Enter key to navigate to the folder
containing startup programs.
colcon_cd jetrover_description
cd urdf
vim jetacker.xacro
13
Several URDF models are combined to create a full robot:
materials Color
lidar_a1 A1 Lidar
lidar_g4 G4 Lidar
Open a new command terminal and run the command to access the robot
model file, which contains the description of each part of the robot model.
vim jetacker.urdf.xacro
This is the beginning of the URDF file. It specifies the XML version and
14
encoding, and defines a robot model named "hiwonder". The xmlns:xacro
namespace is utilized here to generate URDF using Xacro macro definitions.
The following line of code defines a Xacro property named "M_PI" and assigns
the value of π to it.
The second parameter, base_link_w, defines the width of the robot's main
body model, in meters.
The third parameter, base_link_h, defines the height of the robot's main
body model, in meters.
The fourth parameter, base_link_d, defines the length of the robot's main
body model, in meters.
15
2.3.2 Ackermann Wheel Simulation (taking the right front wheel as an
example)
Define the link lidar_link. Define the inertial properties (keyword inertial)
and within this definition, specify: the inertial origin (keyword origin), the mass
(keyword mass), and the inertial properties between the links (keyword inertia).
Define the visual description (keyword visual) and within this definition
specify: the position as the origin (keyword origin), the relevant dynamics
configuration file (keyword geometry), and the color as black (keyword
material).
16
Define the collision properties (keyword collision), the collision position
(keyword origin), and the collision geometry (keyword geometry).
17
3.2 SLAM Mapping Principle
1 Preprocessing: Optimizing the raw data from the radar point cloud,
filtering out problematic data or performing filtering. Using laser as a signal
source, pulses of laser emitted by the laser are directed at surrounding
obstacles, causing scattering.
Some of the light waves will reflect back to the receiver of the lidar, and then,
according to the principle of laser ranging, the distance from the lidar to the
target point can be obtained.
2 Matching: Matching the point cloud data of the current local environment
with the established map to find the corresponding position.
3 Map Fusion: Integrating new round data from the lidar into the original
map, ultimately completing the map update.
18
3.3 Notes
3.For larger areas, it's recommended to complete a full mapping loop before
focusing on scanning smaller environmental details. This approach enhances
the overall efficiency and precision of the mapping process.
Finally, assess the robot's navigation process against the following criteria
once the mapping is complete:
1) Ensure that the edges of obstacles within the map are distinctly defined.
2) Check for any disparities between the map and the actual environment,
such as the presence of closed loops or inconsistencies.
3) Verify the absence of gray areas within the robot's motion area, indicating
areas that haven't been adequately scanned.
4) Confirm that the map doesn't incorporate obstacles that won't exist during
subsequent localization.
5) Validate the map's coverage of the entire extent of the robot's motion area.
19
4. slam_toolbox Mapping Algorithm
20
Synchronous, asynchronous mapping
From the above diagram, it can be seen that the process is relatively
straightforward. The traditional soft real-time operation mechanism of slam
involves processing each frame of data upon entry and then returning.
Relevant source code and WIKI links for KartoSLAM:
21
https://github.com/ros-perception/slam_karto
open_karto open-source algorithm:
https://github.com/ros-perception/open_karto
4.2.1 Install Virtual Machine Software and Import the Virtual Machine
Unzip the provided installation files, then click on the installation file to proceed
with the installation.
2) Enter the virtual machine interface and click on "Open Virtual Machine."
23
6) After import completion, follow the prompts to complete the installation
process.
1) Start the robot, and access the robot system desktop using NoMachine.
cd ros2_ws/src/
6) Enter the command to package the three files 'navigation', 'slam', and
'simulations' into a compressed file:
24
7) Enter the command to move the compressed file to the shared directory:
mv src.zip /home/ubuntu/share/tmp
cd ..
ls -a
10) Enter the command to move the .typerc file to the shared directory:
cp .typerc /home/ubuntu/share/tmp
home/docker/tmp directory:
12) Use the shortcut 'Ctrl + H' to show the hidden .typerc file:
13) Drag the two files from the directory to the computer desktop.
25
4.2.2.2 Import Files into the Virtual Machine
2) Drag and drop the .typerc and src.zip files from the computer desktop into
the virtual machine:
26
4.2.3 Create and Compile the Workspace
mkdir -p ros2_ws/src
unzip src.zip
mv .typerc ros2_ws/
27
6) Navigate to the ros2_ws directory:
cd ros2_ws/
7) Enter the command to check if .typerc has been moved to the ros2_ws
directory:
ls -a
colcon build
gedit ~/.bashrc
source /home/ubuntu/ros2_ws/.typerc
source /home/ubuntu/ros2_ws/install/setup.bash
10) After finishing writing, use the shortcut Ctrl + S or click the Save button in
the upper right corner to save and exit.
28
source ~/.bashrc
2) Enter the command to modify the wifi configuration file, change it to LAN
mode, and update your own WIFI name and password.
gedit ~/hiwonder-toolbox/hiwonder_wifi_conf.py
#!/usr/bin/python3
#coding:utf8
STA mode
characters and numbers, must start with HW- to enable app functionality
3) After finishing writing, use the shortcut “Ctrl + S” or click the Save button in
29
the upper right corner to save and exit.
5) It is important to note that the virtual machine and the robot are connected
to the same LAN, and their IP addresses should be within the same
subnet:
Virtual Machine:
Robot:
30
terminal. You will notice that the ROS_DOMAIN_ID is 0, which is the same
as on the virtual machine.
Robot:
Virtual Machine:
31
4.2.5.2 Virtual Machine Instructions
2) Enter the command to open the RViz tool and display the mapping
results.
2) Enter the command to start the keyboard control node, and press Enter
key:
32
If you see the prompt as shown in the following image, it means the keyboard
control service has been successfully started.
3) Control the robot to move in the current space to build a more complete
map. The table below lists the keyboard keys available for controlling robot
movement and their corresponding functions:
When controlling the robot's movement with the keyboard to map, it's
advisable to reduce the robot's movement speed appropriately. The slower the
robot's speed, the smaller the odometry relative error, leading to better
33
mapping results. As the robot moves, the map displayed in RVIZ will
continuously expand until the entire environment scene's map construction is
completed.
If you desire a more precise mapping outcome, optimizing the odometry can
be beneficial. Mapping with the robot requires the use of odometry, which in
turn relies on the IMU.
The robot itself comes with pre-calibrated IMU data loaded, enabling it to
perform mapping and navigation functions effectively. However, calibrating the
IMU can still enhance accuracy further. The calibration method and steps for
the IMU can be found in the "3 Motion Control Course -> 2. Motion Control -> 1.
IMU, Linear Velocity and Angular Velocity Calibration" section.
34
directory.
For more detailed information about the parameters, please refer to the official
documentation: https://wiki.ros.org/slam_toolbox
/home/ubuntu/ros2_ws/src/slam/launch/slam.launch.py
Import Library
The launch library can be explored in detail in the official ROS documentation:
https://docs.ros.org/en/humble/How-To-Guides/Launching-composable-nodes.
html
35
Initiate Other Launch File
36
5. RTAB-VSLAM 3D Vision Mapping & Navigation
37
RTAB-VSLAM software package link: https://github.com/introlab/rtabmap
2) Enter the command to open the RViz tool and display the mapping effect:
38
5.3.3 Enable Keyboard Control
2) Enter the command to start the keyboard control node, and press Enter.
If you encounter the prompt as shown in the figure below, it means that the
keyboard control service has been successfully activated.
39
3) Control the robot to move in the current space to build a more complete
map. The table below shows the keyboard keys available for controlling
robot movement and their corresponding functions:
When controlling the robot's movement for mapping using the keyboard, it's
advisable to appropriately reduce the robot's movement speed. The smaller
the robot's running speed, the smaller the relative error of the odometry,
resulting in a better mapping effect. As the robot moves, the map displayed in
RVIZ will continuously expand until the entire environmental scene's map
construction is completed.
After mapping is completed, you can use the shortcut "Ctrl+C" in each
command-line terminal window to close the currently running program.
Note: For 3D mapping, there's no need to manually save the map. When you use
"Ctrl+C" to close the mapping command, the map will be automatically saved.
40
5.4 lanunch File Analysis
/home/ubuntu/ros2_ws/src/slam/launch/rtabmap_slam.launch.py
Import Library:
You can refer to the ROS official documentation for detailed analysis of the
launch library:
“https://docs.ros.org/en/humble/How-To-Guides/Launching-composable-node
s.html”
41
base_launch: Launch for hardware initialization
42