Spawn and drive
A gz-maritime bring-up is two parts. The simulation part,
kai_bringup/launch/simulation.launch.xml, starts Gazebo on the ocean, the
GUI, and a bridge for /clock. It names no vehicle. The spawn part,
kai_bringup/launch/spawn_vehicle.launch.xml, puts one instance of any
vehicle in, with its bridge and its TF, given the vehicle’s files and a
name. Run the first once and the second once per vehicle.
flowchart TB
subgraph sim["kai_bringup simulation.launch.xml (once)"]
S["Gazebo server<br/><i>open_water.sdf</i>"]
GUI["Gazebo GUI"]
CB["ros_gz_bridge<br/><i>/clock</i>"]
end
subgraph a["spawn_vehicle.launch.xml name:=boat_a"]
SA["ros_gz_sim create<br/><i>boat_a</i>"]
BA["ros_gz_bridge<br/><i>/boat_a/...</i>"]
RA["robot_state_publisher<br/><i>frame_prefix boat_a/</i>"]
end
subgraph b["spawn_vehicle.launch.xml name:=boat_b"]
SB["ros_gz_sim create<br/><i>boat_b</i>"]
BB["ros_gz_bridge<br/><i>/boat_b/...</i>"]
RB["robot_state_publisher<br/><i>frame_prefix boat_b/</i>"]
end
SA --> S
SB --> S
GUI --- S
S <--> CB
S <--> BA
S <--> BB
BA -->|/boat_a/joint_states| RA
BB -->|/boat_b/joint_states| RB
The simulation part
Argument |
Default |
What it does |
|---|---|---|
|
|
World to load. |
|
|
Start the Gazebo GUI. |
|
|
Run the Gazebo server and the bridges in one process, |
Run on its own it gives you the ocean and nothing else.
Spawn an instance
One command, with the vehicle’s three files:
ros2 launch kai_bringup spawn_vehicle.launch.xml name:=boat_a y:=2 \
xacro:=$(ros2 pkg prefix --share kai_custom_vehicle)/models/custom_usv/model.sdf.xacro \
bridge:=$(ros2 pkg prefix --share kai_custom_vehicle)/config/ros_gz_bridge.yaml.in \
urdf:=$(ros2 pkg prefix --share kai_custom_vehicle)/urdf/custom_usv.urdf.xacro
For one instance, all from the name, the launch:
Renders the files for the name. The model xacro with
name:=boat_a, the URDF xacro, and the bridge template with@name@filled in, minus any/clockentry, intoinstance_dir(by default~/.ros/kai_bringup/boat_a). The model xacro gets the rendered URDF asurdf_uri:=file://...to merge.Spawns the model under the name, at
x,y,z,roll,pitchandyaw.Bridges its topics in the
/boat_anamespace.Publishes its TF, every frame prefixed
boat_a/, from arobot_state_publisherin the same namespace, on simulation time.
With composition on, the default, the bridge and the state publisher load
into the simulation’s container, ros_gz_container, from wherever the
command is run, and the command returns once the model is in. The nodes
stay up in the container and go down with the simulation.
Argument |
Default |
What it does |
|---|---|---|
|
Instance name: letters, digits and underscores, starting with a letter. |
|
|
The vehicle’s model xacro, bridge template and URDF. |
|
|
Instead of the three files: a command that writes them for a name (Other vehicles). |
|
|
|
Spawn pose; z = 0 is the waterline. |
|
empty |
Name of the world to spawn into; empty is the one running. |
|
|
Where the rendered files go. |
|
|
Load the bridge and state publisher into the simulation’s container. |
Your sim.launch.xml
A vehicle package usually keeps a convenience launch that includes the
simulation part and one spawn with its own three files.
kai_custom_vehicle/launch/sim.launch.xml is the template; copy it and
change the three paths:
<let name="share" value="$(find-pkg-share kai_custom_vehicle)"/>
<!-- 1. The simulation: Gazebo on the ocean, the GUI, /clock. -->
<include file="$(find-pkg-share kai_bringup)/launch/simulation.launch.xml">
<arg name="world" value="$(var world)"/>
<arg name="gazebo_gui" value="$(var gazebo_gui)"/>
<arg name="use_composition" value="$(var use_composition)"/>
</include>
<!-- 2. The boat: this vehicle's three files, one instance name. The spawn
launch's `world` is the name of the world to spawn into, empty for
the one running; it is set here so this file's `world`, the SDF file
name, does not leak into it. -->
<include file="$(find-pkg-share kai_bringup)/launch/spawn_vehicle.launch.xml">
<arg name="name" value="$(var name)"/>
<arg name="world" value=""/>
<arg name="xacro" value="$(var share)/models/custom_usv/model.sdf.xacro"/>
<arg name="bridge" value="$(var share)/config/ros_gz_bridge.yaml.in"/>
<arg name="urdf" value="$(var share)/urdf/custom_usv.urdf.xacro"/>
<arg name="x" value="$(var x)"/>
<arg name="y" value="$(var y)"/>
<arg name="z" value="$(var z)"/>
<arg name="roll" value="$(var roll)"/>
<arg name="pitch" value="$(var pitch)"/>
<arg name="yaw" value="$(var yaw)"/>
<arg name="use_composition" value="$(var use_composition)"/>
</include>
</launch>
Its arguments are the simulation part’s plus name and the pose. The spawn
include is handed an empty world on purpose: to the spawn launch world
is the world’s name, while to the simulation launch it is the SDF file, and
without that line the file name would leak into the include.
One name per instance
Everything about an instance follows its name:
|
|
|---|---|
Gazebo model |
|
Gazebo and ROS topics |
|
ROS namespace |
|
TF frames |
|
Sensor |
|
RViz |
fixed frame |
The model file carries the name in its topics and frame ids (the xacro
name argument), the launch puts the nodes in the namespace,
robot_state_publisher’s frame_prefix puts it on the TF frames, and
rviz.launch.xml writes an RViz config that looks the robot up under it.
The URDF itself never contains it. A name must work as all four at once:
letters, digits and underscores, starting with a letter.
What the launch needs from a vehicle
A model xacro with a
nameargument used for the model name and every topic and frame id, and aurdf_uriargument for the URDF to merge.A bridge template listing the vehicle’s own topics, with
@name@where the name goes. No/clock: the launch drops one anyway, since the simulation part bridges it once.A URDF, xacro or plain, for
robot_state_publisher; its frames get the<name>/prefix in TF, so sensor messages should carry the name in theirframe_idtoo.Absolute or
model://references for meshes and files inside the model, since the rendered model is written to the instance directory.
A vehicle laid out that way spawns any number of times with nothing else.
The bridge configuration
Each entry connects one Gazebo topic to one ROS topic. The instance’s
config is rendered from a template with @name@ where the name goes:
- ros_topic_name: /@name@/motor_port/cmd
gz_topic_name: /@name@/motor_port/cmd
ros_type_name: std_msgs/msg/Float64
gz_type_name: gz.msgs.Double
direction: ROS_TO_GZ
The pairs a maritime vehicle usually needs:
What |
ROS type |
Gazebo type |
Direction |
|---|---|---|---|
Propeller command |
|
|
|
Propeller speed |
|
|
|
Joint states |
|
|
|
IMU |
|
|
|
GPS |
|
|
|
Magnetometer |
|
|
|
Camera |
|
|
|
Important
No /clock in a vehicle’s bridge. The simulation part bridges it once;
a second bridge of the same topic would publish it twice. The spawn launch
drops a clock entry if it finds one.
Drive
One terminal per propeller. A command is a fraction of full thrust, from -1 (full astern) to 1 (full ahead). Terminal 1:
ros2 topic pub -r 5 /custom_usv/motor_port/cmd std_msgs/msg/Float64 "{data: 0.25}"
Terminal 2:
ros2 topic pub -r 5 /custom_usv/motor_stbd/cmd std_msgs/msg/Float64 "{data: 0.25}"
Commands latch until the next one arrives, so start the second right after
the first, and stop by sending 0.0 to both
(First simulation).
Change the sea while it runs
gz service -s /world/default/wave/set_parameters --reqtype gz.msgs.Param \
--reptype gz.msgs.Boolean --timeout 2000 \
--req 'params {key: "sea_state" value {type: INT32 int_value: 3}}'
Sea states go from 0 (glassy) to 9. Remember that vehicles float on the flat water level, not on the drawn waves (Waves and physics today).
Several vehicles
Run the spawn launch once per instance, each with its own name, after the simulation part. Terminal 1, the ocean:
ros2 launch kai_bringup simulation.launch.xml
Terminal 2, the first boat:
ros2 launch kai_bringup spawn_vehicle.launch.xml name:=boat_a y:=2 \
xacro:=$(ros2 pkg prefix --share kai_custom_vehicle)/models/custom_usv/model.sdf.xacro \
bridge:=$(ros2 pkg prefix --share kai_custom_vehicle)/config/ros_gz_bridge.yaml.in \
urdf:=$(ros2 pkg prefix --share kai_custom_vehicle)/urdf/custom_usv.urdf.xacro
Terminal 3, the second:
ros2 launch kai_bringup spawn_vehicle.launch.xml name:=boat_b y:=-2 yaw:=1.57 \
xacro:=$(ros2 pkg prefix --share kai_custom_vehicle)/models/custom_usv/model.sdf.xacro \
bridge:=$(ros2 pkg prefix --share kai_custom_vehicle)/config/ros_gz_bridge.yaml.in \
urdf:=$(ros2 pkg prefix --share kai_custom_vehicle)/urdf/custom_usv.urdf.xacro
Both boats float, because each marks its own displacement; each has its own
topics, namespace and TF prefix; and /clock has one publisher. A boat
added an hour later joins the same way.
Other vehicles
Different vehicles mix the same way: one spawn command each, next to the one simulation part. A vehicle that generates its files with a script of its own, as the Blue Robotics vehicles do, is given the script instead of the three files:
ros2 launch kai_bringup spawn_vehicle.launch.xml name:=blueboat x:=6 \
generator:="$(ros2 pkg prefix blueboat_gazebo)/lib/blueboat_gazebo/configure_vehicle.py --config $(ros2 pkg prefix --share blueboat_description)/config/blueboat.yaml"
The launch runs the command with --name <name> --out-dir <dir> and expects
model.sdf, ros_gz_bridge.yaml and a URDF in that directory
(BlueBoat and BlueROV2).
Next: Add sensors.