-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheck URDF file from Terminal
77 lines (59 loc) · 2.7 KB
/
Check URDF file from Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
### 1. Ensure Your URDF is Correct
Make sure your URDF file is properly formatted and contains all necessary elements. You can check it using the `check_urdf` command.
### 2. Create a Launch File for Gazebo
You need to create a launch file that will:
- Load your URDF file into the parameter server under the `robot_description` parameter.
- Start the `robot_state_publisher` node to publish the state of the robot's joints.
- Start Gazebo and spawn your robot into the world.
Here's an example of what that launch file might look like:
```python
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import LaunchConfiguration, Command
from launch_ros.actions import Node
def generate_launch_description():
pkg_share = get_package_share_directory('my_robot_description')
default_model_path = os.path.join(pkg_share, 'urdf/my_robot.urdf.xml')
default_rviz_config_path = os.path.join(pkg_share, 'rviz/my_robot.rviz')
robot_state_publisher_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='screen',
parameters=[{'robot_description': Command(['xacro ', LaunchConfiguration('model')])}]
)
gazebo = ExecuteProcess(
cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_factory.so'],
output='screen'
)
spawn_entity_node = Node(
package='gazebo_ros',
executable='spawn_entity.py',
arguments=['-entity', 'my_robot', '-topic', 'robot_description'],
output='screen'
)
return LaunchDescription([
DeclareLaunchArgument(
name='model', default_value=default_model_path,
description='Absolute path to robot urdf file'
),
gazebo,
robot_state_publisher_node,
spawn_entity_node
])
```
Save this launch file in the `launch` directory of your package, for example as `spawn_my_robot.launch.py`.
### 3. Launch Gazebo with Your Robot Model
Navigate to the root of your ROS workspace and source the ROS environment, then build your workspace and source it again if you haven't already:
```bash
cd ~/my_ros2_ws
colcon build
source install/setup.bash
```
Now launch the file with:
```bash
ros2 launch my_robot_description spawn_my_robot.launch.py
```
This should start Gazebo and spawn your robot model into the simulation environment. If there are any errors, they will be printed to the console, and you will need to resolve them to proceed. Possible issues could be related to the URDF file, ROS parameters, or the Gazebo simulation environment itself.