Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ its previews.
`sim.launch.py` is `world.launch.py` (Gazebo with the world) and `sim_robot.launch.py` (the simulated robot with the
same localization, SLAM and navigation as the real one) together, with RViz and joystick teleop; tools such as the
GUI start them one by one.
In a simulation shared by several robots each one is started with `sim_robot.launch.py robot_ns:=<name>`: the name
is given to the model, its Gazebo topics and its controller manager. The topics of the controller manager move under
`/<name>` too (`robot_description`, `joint_states`, `diff_drive_controller/cmd_vel`, `diff_drive_controller/odom`), so
`robot_ns` works only with what runs the shared simulation and bridges them (the arena of the KPI Rover hub);
with `load_controllers:=false` it also loads the controllers.

Keyboard control (second zellij pane):
```bash
Expand Down
8 changes: 4 additions & 4 deletions src/platform/kpi_rover_bringup/config/gz_bridge.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
- ros_topic_name: "clock"
gz_topic_name: "clock"
- ros_topic_name: "/clock"
gz_topic_name: "/clock"
ros_type_name: "rosgraph_msgs/msg/Clock"
gz_type_name: "gz.msgs.Clock"
direction: GZ_TO_ROS

- ros_topic_name: "scan"
- ros_topic_name: "/scan"
gz_topic_name: "scan"
ros_type_name: "sensor_msgs/msg/LaserScan"
gz_type_name: "gz.msgs.LaserScan"
direction: GZ_TO_ROS

- ros_topic_name: "imu_broadcaster/imu"
- ros_topic_name: "/imu_broadcaster/imu"
gz_topic_name: "imu_broadcaster/imu"
ros_type_name: "sensor_msgs/msg/Imu"
gz_type_name: "gz.msgs.IMU"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
controller_manager:
/**/controller_manager:
ros__parameters:
# TODO Return back normal rate. It was decrised for debugging
update_rate: 30
Expand All @@ -12,7 +12,7 @@ controller_manager:
imu_broadcaster:
type: imu_sensor_broadcaster/IMUSensorBroadcaster

diff_drive_controller:
/**/diff_drive_controller:
ros__parameters:
left_wheel_names: ["front_left_wheel_joint", "rear_left_wheel_joint"]
right_wheel_names: ["front_right_wheel_joint", "rear_right_wheel_joint"]
Expand All @@ -28,12 +28,14 @@ diff_drive_controller:
publish_wheel_tf: true
publish_cmd: true
enable_odom_tf: false
# The frames stay odom, base_footprint in a namespace too (robot_ns of sim_robot.launch.py)
tf_frame_prefix_enable: false

position_feedback: true
linear:
x: {min_velocity: -1.0, max_velocity: 1.0}

imu_broadcaster:
/**/imu_broadcaster:
ros__parameters:
sensor_name: "imu"
frame_id: "imu_link"
22 changes: 18 additions & 4 deletions src/platform/kpi_rover_bringup/launch/sim_robot.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from launch.conditions import IfCondition
from launch.event_handlers import OnProcessExit
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution, PythonExpression
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare

Expand All @@ -17,6 +17,7 @@ def generate_launch_description():
y_pose = LaunchConfiguration('y_pose')
z_pose = LaunchConfiguration('z_pose')
yaw_pose = LaunchConfiguration('yaw_pose')
robot_ns = LaunchConfiguration('robot_ns')

declared_arguments = [
DeclareLaunchArgument(
Expand All @@ -32,6 +33,14 @@ def generate_launch_description():
DeclareLaunchArgument(
'nav', default_value='true',
description='Start Nav2 (handles the RViz 2D Goal Pose)'),
DeclareLaunchArgument(
'robot_ns', default_value='',
description='Name of the robot in a simulation shared by several robots: its model, '
'Gazebo topics and controller manager. The controller manager topics move under it '
'and need a bridge from what runs the shared simulation'),
DeclareLaunchArgument(
'load_controllers', default_value='true',
description='Load the controllers; false when something else loads them'),
]

# robot_state_publisher with the sim_mode URDF (gz_ros2_control plugin)
Expand All @@ -42,14 +51,15 @@ def generate_launch_description():
'use_sim_time': 'true',
'sim_mode': 'true',
'wheel_radius': wheel_radius,
'robot_ns': robot_ns,
}.items(),
)

spawn_robot = Node(
package='ros_gz_sim',
executable='create',
arguments=[
'-name', 'kpi_rover',
'-name', PythonExpression(["'", robot_ns, "' or 'kpi_rover'"]),
'-topic', 'robot_description',
'-x', x_pose,
'-y', y_pose,
Expand All @@ -59,19 +69,22 @@ def generate_launch_description():
output='screen',
)

# Relative Gazebo topics of the config get the namespace (<robot_ns>/scan), the ROS topics don't
gz_bridge = Node(
package='ros_gz_bridge',
executable='parameter_bridge',
namespace=robot_ns,
parameters=[{
'config_file': PathJoinSubstitution([pkg_bringup, 'config', 'gz_bridge.yaml']),
'expand_gz_topic_names': True,
}],
output='screen',
)

joint_state_broadcaster = Node(
package='controller_manager',
executable='spawner',
arguments=['joint_state_broadcaster', '--switch-timeout', '60'],
arguments=['joint_state_broadcaster', '-c', [robot_ns, '/controller_manager'], '--switch-timeout', '60'],
output='screen',
)

Expand All @@ -80,6 +93,7 @@ def generate_launch_description():
executable='spawner',
arguments=[
'diff_drive_controller',
'-c', [robot_ns, '/controller_manager'],
'--switch-timeout', '60',
'--controller-ros-args', '-r /diff_drive_controller/odom:=/odom',
],
Expand All @@ -90,7 +104,7 @@ def generate_launch_description():
spawn_controllers = RegisterEventHandler(OnProcessExit(
target_action=spawn_robot,
on_exit=[joint_state_broadcaster, diff_drive_controller],
))
), condition=IfCondition(LaunchConfiguration('load_controllers')))

# Turns unstamped /cmd_vel (Nav2, teleop_twist_keyboard) into the stamped input of the controller
twist_stamper = Node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def generate_launch_description():
serial_device = LaunchConfiguration('serial_device')
baud_rate = LaunchConfiguration('baud_rate')
wheel_radius = LaunchConfiguration('wheel_radius')
robot_ns = LaunchConfiguration('robot_ns')

pkg_share = FindPackageShare('kpi_rover_description')

Expand All @@ -28,7 +29,8 @@ def generate_launch_description():
' sim_mode:=', sim_mode,
' serial_device:=', serial_device,
' baud_rate:=', baud_rate,
' wheel_radius:=', wheel_radius
' wheel_radius:=', wheel_radius,
' robot_ns:=', robot_ns
])

# Launch!
Expand All @@ -53,6 +55,10 @@ def generate_launch_description():
'wheel_radius',
default_value='0.034',
description='Wheel radius in meters'),
DeclareLaunchArgument(
'robot_ns',
default_value='',
description='Name of the robot in a simulation shared by several robots (Gazebo topics, controller manager)'),

Node(
package='robot_state_publisher',
Expand Down
2 changes: 1 addition & 1 deletion src/platform/kpi_rover_description/urdf/imu.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<sensor type="imu" name="imu">
<always_on>1</always_on>
<visualize>false</visualize>
<topic>/imu_broadcaster/imu</topic>
<topic>$(arg robot_ns)/imu_broadcaster/imu</topic>
<gz_frame_id>imu_link</gz_frame_id>
</sensor>
</gazebo>
Expand Down
2 changes: 1 addition & 1 deletion src/platform/kpi_rover_description/urdf/lidar.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<gazebo reference="laser_frame">
<sensor name="gpu_lidar" type="gpu_lidar">
<update_rate>30</update_rate>
<topic>scan</topic>
<topic>$(arg robot_ns)/scan</topic>
<gz_frame_id>laser_frame</gz_frame_id>
<lidar>
<scan>
Expand Down
2 changes: 2 additions & 0 deletions src/platform/kpi_rover_description/urdf/robot.urdf.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<xacro:arg name="baud_rate" default="921600"/>
<xacro:arg name="encoder_ticks_per_rev" default="1320"/>
<xacro:arg name="wheel_radius" default="0.034"/>
<!-- Name of the robot in a simulation shared by several robots (Gazebo topics, controller manager namespace) -->
<xacro:arg name="robot_ns" default=""/>

<xacro:include filename="materials.xacro" />
<xacro:include filename="inertia.xacro" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<!-- Joint state publisher -->
<plugin filename="gz_ros2_control-system" name="gz_ros2_control::GazeboSimROS2ControlPlugin">
<parameters>$(find kpi_rover_bringup)/config/kpi_rover_controllers.yaml</parameters>
<ros><namespace>$(arg robot_ns)</namespace></ros>
</plugin>
</gazebo>
</xacro:if>
Expand Down