Skip to content

Commit

Permalink
Add default gazebo version as fortress
Browse files Browse the repository at this point in the history
  • Loading branch information
jasiex01 committed Oct 11, 2023
1 parent cff351e commit bc5803a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 82 deletions.
18 changes: 9 additions & 9 deletions leo_gz_bringup/launch/leo_gz.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@

def generate_launch_description():
# Setup project paths
pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim')
pkg_project_gazebo = get_package_share_directory('leo_gz_bringup')
pkg_project_worlds = get_package_share_directory('leo_gz_worlds')
pkg_ros_gz_sim = get_package_share_directory("ros_gz_sim")
pkg_project_gazebo = get_package_share_directory("leo_gz_bringup")
pkg_project_worlds = get_package_share_directory("leo_gz_worlds")

sim_world = DeclareLaunchArgument(
'sim_world',
default_value=os.path.join(pkg_project_worlds, 'worlds', 'empty.sdf'),
description='Path to the Gazebo world file',
"sim_world",
default_value=os.path.join(pkg_project_worlds, "worlds", "empty.sdf"),
description="Path to the Gazebo world file",
)

# Setup to launch the simulator and Gazebo world
gz_sim = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py')
os.path.join(pkg_ros_gz_sim, "launch", "gz_sim.launch.py")
),
launch_arguments={'gz_args': LaunchConfiguration('sim_world')}.items(),
launch_arguments={"gz_args": LaunchConfiguration("sim_world")}.items(),
)

robot_sim = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_project_gazebo, 'launch', 'spawn_robot.launch.py')
os.path.join(pkg_project_gazebo, "launch", "spawn_robot.launch.py")
),
)

Expand Down
100 changes: 50 additions & 50 deletions leo_gz_bringup/launch/spawn_robot.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,97 +30,97 @@


def spawn_robot(context: LaunchContext, namespace: LaunchConfiguration):
pkg_project_description = get_package_share_directory('leo_description')
pkg_project_description = get_package_share_directory("leo_description")
robot_name = context.perform_substitution(namespace)

robot_desc = xacro.process(
os.path.join(
pkg_project_description,
'urdf',
'leo_sim.urdf.xacro',
"urdf",
"leo_sim.urdf.xacro",
),
mappings={'robot_ns': robot_name},
mappings={"robot_ns": robot_name},
)

if robot_name == '':
robot_state_publisher_node_name = 'robot_state_publisher'
robot_gazebo_name = 'leo_rover'
topic_bridge_node_name = 'topic_bridge'
image_bridge_node_name = 'image_bridge'
if robot_name == "":
robot_state_publisher_node_name = "robot_state_publisher"
robot_gazebo_name = "leo_rover"
topic_bridge_node_name = "topic_bridge"
image_bridge_node_name = "image_bridge"
else:
robot_state_publisher_node_name = robot_name + '_robot_state_publisher'
robot_gazebo_name = 'leo_rover_' + robot_name
topic_bridge_node_name = robot_name + '_topic_bridge'
image_bridge_node_name = robot_name + '_image_bridge'
robot_state_publisher_node_name = robot_name + "_robot_state_publisher"
robot_gazebo_name = "leo_rover_" + robot_name
topic_bridge_node_name = robot_name + "_topic_bridge"
image_bridge_node_name = robot_name + "_image_bridge"

# Launch robot state publisher node
robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
package="robot_state_publisher",
executable="robot_state_publisher",
name=robot_state_publisher_node_name,
output='both',
output="both",
parameters=[
{'use_sim_time': True},
{'robot_description': robot_desc},
{"use_sim_time": True},
{"robot_description": robot_desc},
],
remappings=[
('/robot_description', robot_name + '/robot_description'),
("/robot_description", robot_name + "/robot_description"),
],
)
# Spawn a robot inside a simulation
leo_rover = Node(
package='ros_gz_sim',
executable='create',
name='ros_gz_sim_create',
output='both',
package="ros_gz_sim",
executable="create",
name="ros_gz_sim_create",
output="both",
arguments=[
'-topic',
robot_name + '/robot_description',
'-name',
"-topic",
robot_name + "/robot_description",
"-name",
robot_gazebo_name,
'-z',
'1.65',
"-z",
"1.65",
],
)

# Bridge ROS topics and Gazebo messages for establishing communication
topic_bridge = Node(
package='ros_gz_bridge',
executable='parameter_bridge',
package="ros_gz_bridge",
executable="parameter_bridge",
name=topic_bridge_node_name,
arguments=[
'/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock',
robot_name + '/cmd_vel@geometry_msgs/msg/Twist]ignition.msgs.Twist',
robot_name + '/odom@nav_msgs/msg/Odometry[ignition.msgs.Odometry',
robot_name + '/tf@tf2_msgs/msg/TFMessage[ignition.msgs.Pose_V',
robot_name + '/imu/data_raw@sensor_msgs/msg/Imu[ignition.msgs.IMU',
"/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock",
robot_name + "/cmd_vel@geometry_msgs/msg/Twist]ignition.msgs.Twist",
robot_name + "/odom@nav_msgs/msg/Odometry[ignition.msgs.Odometry",
robot_name + "/tf@tf2_msgs/msg/TFMessage[ignition.msgs.Pose_V",
robot_name + "/imu/data_raw@sensor_msgs/msg/Imu[ignition.msgs.IMU",
robot_name
+ '/camera/camera_info@sensor_msgs/msg/CameraInfo[ignition.msgs.CameraInfo',
'world/leo_marsyard/model/'
+ "/camera/camera_info@sensor_msgs/msg/CameraInfo[ignition.msgs.CameraInfo",
"world/leo_marsyard/model/"
+ robot_gazebo_name
+ '/joint_state@sensor_msgs/msg/JointState[ignition.msgs.Model',
+ "/joint_state@sensor_msgs/msg/JointState[ignition.msgs.Model",
],
parameters=[
{
'qos_overrides./tf_static.publisher.durability': 'transient_local',
"qos_overrides./tf_static.publisher.durability": "transient_local",
}
],
remappings=[
(
'world/leo_marsyard/model/' + robot_gazebo_name + '/joint_state',
robot_name + '/joint_states',
"world/leo_marsyard/model/" + robot_gazebo_name + "/joint_state",
robot_name + "/joint_states",
),
],
output='screen',
output="screen",
)

# Camera image bridge
image_bridge = Node(
package='ros_gz_image',
executable='image_bridge',
package="ros_gz_image",
executable="image_bridge",
name=image_bridge_node_name,
arguments=[robot_name + '/camera/image_raw'],
output='screen',
arguments=[robot_name + "/camera/image_raw"],
output="screen",
)
return [
robot_state_publisher,
Expand All @@ -132,12 +132,12 @@ def spawn_robot(context: LaunchContext, namespace: LaunchConfiguration):

def generate_launch_description():
name_argument = DeclareLaunchArgument(
'robot_name',
default_value='',
description='Robot namespace',
"robot_name",
default_value="",
description="Robot namespace",
)

namespace = LaunchConfiguration('robot_name')
namespace = LaunchConfiguration("robot_name")

return LaunchDescription(
[name_argument, OpaqueFunction(function=spawn_robot, args=[namespace])]
Expand Down
44 changes: 21 additions & 23 deletions leo_gz_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,13 @@ endif()

find_package(ament_cmake REQUIRED)

add_library(leo_gazebo_differential_plugin SHARED
src/differential_system.cpp)

if(DEFINED ENV{GZ_VERSION})
message("GZ_VERSION is set to $ENV{GZ_VERSION}")
add_library(leo_gazebo_differential_plugin SHARED
src/differential_system.cpp)

if($ENV{GZ_VERSION} STREQUAL "fortress")
find_package(ignition-plugin1 REQUIRED COMPONENTS register)
set(IGN_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR})

find_package(ignition-common4 REQUIRED)
set(IGN_COMMON_VER ${ignition-common4_VERSION_MAJOR})

find_package(ignition-gazebo6 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo6_VERSION_MAJOR})

add_definitions(-DUSE_IGNITION)

target_link_libraries(leo_gazebo_differential_plugin
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
ignition-gazebo${IGN_GAZEBO_VER}::ignition-gazebo${IGN_GAZEBO_VER}
ignition-plugin${IGN_PLUGIN_VER}::ignition-plugin${IGN_PLUGIN_VER}
)
else() #garden
if($ENV{GZ_VERSION} STREQUAL "garden")
find_package(gz-plugin2 REQUIRED COMPONENTS register)
set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR})

Expand All @@ -41,10 +25,24 @@ if(DEFINED ENV{GZ_VERSION})
gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER}
)
endif()

else()
message(FATAL_ERROR "Enviormental variable GZ_VERSION is not set. Aborting build.")
return()
#If GZ_VERSION not set default to Fortress
find_package(ignition-plugin1 REQUIRED COMPONENTS register)
set(IGN_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR})

find_package(ignition-common4 REQUIRED)
set(IGN_COMMON_VER ${ignition-common4_VERSION_MAJOR})

find_package(ignition-gazebo6 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo6_VERSION_MAJOR})

add_definitions(-DUSE_IGNITION)

target_link_libraries(leo_gazebo_differential_plugin
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
ignition-gazebo${IGN_GAZEBO_VER}::ignition-gazebo${IGN_GAZEBO_VER}
ignition-plugin${IGN_PLUGIN_VER}::ignition-plugin${IGN_PLUGIN_VER}
)
endif()

set_property(TARGET leo_gazebo_differential_plugin PROPERTY CXX_STANDARD 17)
Expand Down

0 comments on commit bc5803a

Please sign in to comment.