Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdformat_urdf parser demo #265

Merged
merged 19 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ros_ign_gazebo_demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ install(
DESTINATION share/${PROJECT_NAME}/models
)

install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/models/vehicle
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
DESTINATION share/${PROJECT_NAME}/models/
)

install(
DIRECTORY
worlds/
DESTINATION share/${PROJECT_NAME}/worlds
)

ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/${PROJECT_NAME}.dsv.in")

ament_package()
1 change: 1 addition & 0 deletions ros_ign_gazebo_demos/hooks/ros_ign_gazebo_demos.dsv.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prepend-non-duplicate;IGN_GAZEBO_RESOURCE_PATH;@CMAKE_INSTALL_PREFIX@/share
107 changes: 107 additions & 0 deletions ros_ign_gazebo_demos/launch/sdf_parser.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright 2022 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution


def generate_launch_description():

pkg_ros_ign_gazebo_demos = get_package_share_directory('ros_ign_gazebo_demos')
pkg_ros_ign_gazebo = get_package_share_directory('ros_ign_gazebo')

sdf_file = os.path.join(pkg_ros_ign_gazebo_demos, 'models', 'vehicle', 'model.sdf')

with open(sdf_file, 'r') as infp:
robot_desc = infp.read()

rviz_launch_arg = DeclareLaunchArgument(
'rviz', default_value='false',
description='Open RViz.'
)

gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_ros_ign_gazebo, 'launch', 'ign_gazebo.launch.py'),
),
launch_arguments={
'ign_args': PathJoinSubstitution([
pkg_ros_ign_gazebo_demos,
'worlds',
'vehicle.sdf'
]
)}.items(),
)

# Bridge to forward tf and joint states to ros2
joint_state_gz_topic = '/world/demo/model/vehicle/joint_state'
link_pose_gz_topic = '/model/vehicle/pose'
bridge = Node(
package='ros_ign_bridge',
executable='parameter_bridge',
arguments=[
# Clock (Gazebo -> ROS2)
'/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock',
# Joint states (Gazebo -> ROS2)
joint_state_gz_topic + '@sensor_msgs/msg/JointState[ignition.msgs.Model',
# Link poses (Gazebo -> ROS2)
link_pose_gz_topic + '@tf2_msgs/msg/TFMessage[ignition.msgs.Pose_V',
link_pose_gz_topic + '_static@tf2_msgs/msg/TFMessage[ignition.msgs.Pose_V',
],
remappings=[
(joint_state_gz_topic, 'joint_states'),
(link_pose_gz_topic, '/tf'),
(link_pose_gz_topic + '_static', '/tf_static'),
],
parameters=[{'qos_overrides./tf_static.publisher.durability': 'transient_local'}],
output='screen'
)

# Get the parser plugin convert sdf to urdf using robot_description topic
robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='both',
parameters=[
{'use_sim_time': True},
{'robot_description': robot_desc},
]
)

# Launch rviz
rviz = Node(
package='rviz2',
executable='rviz2',
arguments=['-d', os.path.join(pkg_ros_ign_gazebo_demos, 'rviz', 'vehicle.rviz')],
condition=IfCondition(LaunchConfiguration('rviz')),
parameters=[
{'use_sim_time': True},
]
)

return LaunchDescription([
rviz_launch_arg,
gazebo,
bridge,
robot_state_publisher,
rviz
])
13 changes: 13 additions & 0 deletions ros_ign_gazebo_demos/models/vehicle/model.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<model>
<name>vehicle</name>
<version>1.0</version>
<sdf version="1.8">model.sdf</sdf>

<author>
</author>
quarkytale marked this conversation as resolved.
Show resolved Hide resolved

<description>
Parser compatible differential drive vehicle model.
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
</description>
</model>
188 changes: 188 additions & 0 deletions ros_ign_gazebo_demos/models/vehicle/model.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" ?>
<sdf version="1.8">
<model name='vehicle'>
<link name='chassis'>
<pose>-0.151427 -0 0.175 0 -0 0</pose>
<inertial>
<mass>1.14395</mass>
<inertia>
<ixx>0.126164</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.416519</iyy>
<iyz>0</iyz>
<izz>0.481014</izz>
</inertia>
</inertial>
<visual name='visual_chassis'>
<geometry>
<box>
<size>2.01142 1 0.568726</size>
</box>
</geometry>
<material>
<ambient>0.5 0.5 1.0 1</ambient>
<diffuse>0.5 0.5 1.0 1</diffuse>
<specular>0.0 0.0 1.0 1</specular>
</material>
</visual>
<collision name='collision_chassis'>
<geometry>
<box>
<size>2.01142 1 0.568726</size>
</box>
</geometry>
</collision>
</link>

<link name='left_wheel'>
<pose>0.554283 0.625029 -0.025 -1.5707 0 0</pose>
<inertial>
<mass>2</mass>
<inertia>
<ixx>0.145833</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.145833</iyy>
<iyz>0</iyz>
<izz>0.125</izz>
</inertia>
</inertial>
<visual name='visual_left_wheel'>
<geometry>
<sphere>
<radius>0.3</radius>
</sphere>
</geometry>
<material>
<ambient>0.2 0.2 0.2 1</ambient>
<diffuse>0.2 0.2 0.2 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
</material>
</visual>
<collision name='collision_left_wheel'>
<geometry>
<sphere>
<radius>0.3</radius>
</sphere>
</geometry>
</collision>
</link>

<link name='right_wheel'>
<pose>0.554282 -0.625029 -0.025 -1.5707 0 0</pose>
<inertial>
<mass>2</mass>
<inertia>
<ixx>0.145833</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.145833</iyy>
<iyz>0</iyz>
<izz>0.125</izz>
</inertia>
</inertial>
<visual name='visual_right_wheel'>
<geometry>
<sphere>
<radius>0.3</radius>
</sphere>
</geometry>
<material>
<ambient>0.2 0.2 0.2 1</ambient>
<diffuse>0.2 0.2 0.2 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
</material>
</visual>
<collision name='collision_right_wheel'>
<geometry>
<sphere>
<radius>0.3</radius>
</sphere>
</geometry>
</collision>
</link>

<link name='caster'>
<pose>-0.957138 -0 -0.125 0 -0 0</pose>
<inertial>
<mass>1</mass>
<inertia>
<ixx>0.1</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.1</iyy>
<iyz>0</iyz>
<izz>0.1</izz>
</inertia>
</inertial>
<visual name='visual_caster'>
<geometry>
<sphere>
<radius>0.2</radius>
</sphere>
</geometry>
<material>
<ambient>0.2 0.2 0.2 1</ambient>
<diffuse>0.2 0.2 0.2 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
</material>
</visual>
<collision name='collision_caster'>
<geometry>
<sphere>
<radius>0.2</radius>
</sphere>
</geometry>
</collision>
</link>

<joint name='left_wheel_joint' type='revolute'>
<parent>chassis</parent>
<child>left_wheel</child>
<axis>
<xyz>0 0 1</xyz>
<limit>
<lower>-1.79769e+308</lower>
<upper>1.79769e+308</upper>
</limit>
</axis>
</joint>

<joint name='right_wheel_joint' type='revolute'>
<parent>chassis</parent>
<child>right_wheel</child>
<axis>
<xyz>0 0 1</xyz>
<limit>
<lower>-1.79769e+308</lower>
<upper>1.79769e+308</upper>
</limit>
</axis>
</joint>

<joint name='caster_wheel' type='ball'>
<parent>chassis</parent>
<child>caster</child>
</joint>

<plugin
filename="ignition-gazebo-diff-drive-system"
name="ignition::gazebo::systems::DiffDrive">
<left_joint>left_wheel_joint</left_joint>
<right_joint>right_wheel_joint</right_joint>
<wheel_separation>1.25</wheel_separation>
<wheel_radius>0.3</wheel_radius>
<odom_publish_frequency>1</odom_publish_frequency>
<max_linear_acceleration>1</max_linear_acceleration>
<min_linear_acceleration>-1</min_linear_acceleration>
<max_angular_acceleration>2</max_angular_acceleration>
<min_angular_acceleration>-2</min_angular_acceleration>
<max_linear_velocity>0.5</max_linear_velocity>
<min_linear_velocity>-0.5</min_linear_velocity>
<max_angular_velocity>1</max_angular_velocity>
<min_angular_velocity>-1</min_angular_velocity>
</plugin>

</model>
</sdf>
1 change: 1 addition & 0 deletions ros_ign_gazebo_demos/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<exec_depend>rqt_plot</exec_depend>
<exec_depend>rqt_topic</exec_depend>
<exec_depend>rviz2</exec_depend>
<exec_depend>sdformat_urdf</exec_depend>
<exec_depend>xacro</exec_depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
Loading