0
$\begingroup$

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).

$\endgroup$

2 Answers 2

1
$\begingroup$

You will need to use the ros_gz_bridge. See here and here for documentation. Refer to example 4 for services.

Note that Ignition was renamed to Gazebo from Fortress on, so the syntax for Ignition will differ somewhat from above examples. There is a code example for Ignition in the original PR.

An alternative option would be to include the gz-transport library in your code and instantiate a Gazebo node, but I think that this is C++ only. See here for documentation and examples.

There exist Python bindings but I am fairly sure that these were not backported to Fortress..

$\endgroup$
2
  • $\begingroup$ Thanks for the suggestions, I'm trying to reset the entire world models as well but seems that this feature is not supported on my simulator version. If I run the command gn service -s /world/arena/control --reqtype ignition.msgs.WorldControl --reptype ignition.msgs.Boolean --timeout 5000 --req 'reset: {model_only: true}' I got the following warning [Wrn] [SimulationRunner.cc:1131] Model only reset is not supported. $\endgroup$
    – Paolo
    Commented Oct 23 at 7:42
  • $\begingroup$ It says 'Model only reset is not supported', so you could try --req 'reset: {all: true}' instead. That being said, this is a new question; if this suggestion doesn't help, then you should post a new question. $\endgroup$
    – JRTG
    Commented Oct 23 at 12:02
0
$\begingroup$

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).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.