# 23 ROS2-MoveIt & Gazebo Simulation ## 23.1 Virtual Machine Installation and Configuration ### 23.1.1 Virtual Machine Installation and Import * **Virtual Machine Software Installation** **1. VMware Installation** A virtual machine allows us to run other operating systems within our current operating system. In this section, we will demonstrate the installation process using VMware Workstation as an example: 1. Unzip the virtual machine software package located under the "**Configuration File -\> VMware**" path. 2. After unzipping, locate the virtual machine folder and double-click the executable file (with the ".exe" extension). 3. Follow the on-screen instructions to complete the installation of the virtual machine. 4. VMware Workstation offers 30-day free trial. After 30-day trial, you can purchase a license key to activate this software. If you need free resource, please contact us via email. **(1) Starting Local VMware Services** 5) On your computer, press the “**WIN+R**” keys to open the Run window. Then, type “control” and press Enter to open the Control Panel. 6) Click on “**Administrative Tools**” and then double-click on “**Services**”. 7) Locate the VMware-related services as shown in the image below. 8) Right-click on the "**Start**" button and select it to start all VMware-related services. **2. VirtualBox Installation** 1. Open the software installation package in the same directory and click "**Next**". 2. Modify the installation path if needed, then click "**Next**". 3. No changes needed, just click "**Next**". 4. Confirm the installation and click "**Start Installation**". 5. Once the installation is complete, click "**Finish**". ### 23.1.2 Configuration It is normal for the virtual machine to take a longer time to start for the first time. The virtual machine interface is as below: * **Package Import (Performed on Virtual Machine)** 1. Start the virtual machine. Click the system desktop icon to open the command-line terminal. 2. Click the "Home" icon on the desktop to enter the Home directory. 3. Locate the “**hiwonder_moveit_config.zip**”, “**robot_gazebo.zip**” and “**jetrover_description.zip**” compressed file in the following path “**[23.1 Virtual Machine Installation and Configuration/Resource Files/3. Feature Package]()**”. Drag each of there compressed files into the Home directory of the virtual machine one by one. > [!NOTE] > > **Note: Only drag one file at a time.** 4. Right-click in the Home directory and select “**Open in terminal**” to open the terminal. 5. Enter the following command to create a directory: ```py mkdir -p ~/ros2_ws/src ``` 6. Execute the following commands to extract the source files and enter the source directory: ```py unzip  ~/hiwonder_moveit_config.zip -d ~/ros2_ws/src unzip  ~/robot_gazebo.zip -d ~/ros2_ws/src unzip ~/jetrover_description.zip -d ~/ros2_ws/src ``` If prompted to replace files, type \`A\` and press Enter. 7. Run the following command to compile the packages and wait for the process to finish: ```py cd ~/ros2_ws && colcon build --symlink-install ``` 8. Run the following command to replace the .typerc file: ```py mv /home/ubuntu/.typerc ~/ros2_ws/.typerc ``` 9. Check if the file move was successful by running: ```py cd ~/ros2_ws/ && ls -a ``` 10. To update the settings, reload the configuration file using: ```py source ~/.bashrc ``` * **Network Configuration (Performed in Robot System Desktop)** To ensure proper communication between the virtual machine and the robot during future operations, we need to configure the device's network settings. 1. Start the robot and open a terminal on the desktop. 2. Enter the following command to configure the WiFi file: ```py cd ~/wifi_manager && gedit wifi_conf.py ``` 3. Modify the configuration to LAN mode and enter the WiFi name and password 4. Press Ctrl+S to save and close the file. 5. For subsequent connections, ensure that the device and virtual machine are on the same network segment. You can check this by running the following command in the terminal: ```py ifconfig ``` > [!NOTE] > > **In this example, both the virtual machine and the robot are on the 192.168.11 network segment, allowing for normal communication.** **Common connection methods:** 1. Via Router (Recommended): Connect the computer and Jetson board to the same router using an Ethernet cable. 2. Via Local Area Network (LAN) (Recommended): Configure the STA (station) mode on the WiFi, then connect both the robot and computer to the same WiFi network (or mobile hotspot). 3. Direct Connection (Not Recommended): Set the robot to AP (Access Point) mode, then connect the computer directly to the robot's WiFi. * **Device ID Configuration (To Be Performed on the Virtual Machine)** In the previous section, we configured the network environment. However, for the virtual machine and the robot to communicate on the same network, they must have matching ID numbers. Below are the steps to configure the ID: 1. Start the robot and open a terminal from the desktop. 2. The terminal will display the device's DOMAIN_ID, as shown below: For example, if the DOMAIN_ID is 23, we will configure the virtual machine accordingly. 3. Start the virtual machine and open a terminal from the desktop. 4. Enter the following command to open the configuration file: ```py gedit ~/ros2_ws/.typerc ``` 5. Modify the ID in the configuration file to match the robot’s DOMAIN_ID (e.g., 23): 6. Press Ctrl+S to save the changes and close the file. 7. Close the current terminal, then open a new terminal. You will observe that the ID has been successfully updated to 23. ## 23.2 Introduction to URDF Models ### 23.2.1 URDF Model > [!NOTE] > > **Note: This tutorial is based on configuration and simulation within a virtual machine. If the virtual machine is not yet installed, please first refer to Section 1: Virtual Machine Installation and Configuration to complete the installation.** * **URDF Model Introduction** 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. By connecting links with joints and imposing motion restrictions, a kinematic model is formed. The URDF file specifies the relationships between joints and links, their inertial properties, geometric characteristics, and collision models. * **Comparison between Xacro and URDF Model** 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. * **Install URDF Dependency** > [!NOTE] > > **Note: The URDF and Xacro models are already pre-installed in the virtual machine, so there is no need for users to reinstall them. This section is for informational purposes only.** 1. Run the following command and press Enter to update the package information: ```py sudo apt update ``` 2. Run the following command and press Enter to install the URDF dependencies: ```py sudo apt-get install ros-humble-urdf ``` When the output matches the image below, the installation is successful: 3. Run the following command and press Enter to install the Xacro model extension for URDF: ```py sudo apt-get install ros-humble-xacro ``` When the output matches the image below, the installation is successful: * **URDF Model Basic Syntax** **1. XML Basic Syntax** The URDF model is written using XML standard. **Elements**: An element can be defined as desired using the following formula: **\** **\** **Properties**: Properties are included within elements to define characteristics and parameters. Please refer to the following formula to define an element with properties: **\** **\** **Comments**: Comments have no impact on the definition of other properties and elements. Please use the following formula to define a comment: **\