Call Gazebo service from ROS

I’m trying to understand if and how I can call a Gazebo (Ignition) service from a ROS 2 node. Is it possible? If yes, what is a general pipeline to follow?

In my simulation now I call the following service ign service -s /world/arena/set_pose --reqtype ignition.msgs.Pose --reptype ignition.msgs.Boolean --req 'id: 87 position: { x: 1.0, y: 3.0, z: 0.5 } orientation: { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }' --timeout 1000 to reset the position of an object. Is it possible to call this service from a ROS node (I wrote my node in python).

I’ve found another way to set the position of a model without needing to know the model’s ID. You can use the following command:

ign service -s /world/arena/set_pose --reqtype ignition.msgs.Pose --reptype ignition.msgs.Boolean --req 'name: "model_name" position: { x: 1.0, y: 1.0, z: 0.2 } orientation: { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }' --timeout 1000

Even if this doesn’t answer my question, it’s a good workaround since it’s easier to know the name of your model (ign model --list) instead of your model ID (which is assigned by Gazebo). The previous line can also be embedded in a Python script (I guess relatively easily).