3
$\begingroup$

I'm running Webots R2023a where I have a robot node marked as Supervisor in Webots world (*.wbt file) to be controlled by an external node in ROS2 network. When writing a webots-ros2 plugin, I'm faced with an issue where I cannot access robot fields inside the plugin implementation file.

The init function of the plugin provides a WebotsNode object which inherits a ROS2 node:

init(webots_ros2_driver::WebotsNode *node, std::unordered_map<std::string, std::string> &parameters)

However, I need a reference to the current robot as a webots::Supervisor object so I can retrieve nodes and fields of this robot (using the Supervisor API methods) to have full control over various aspects of the simulation.

Is it possible to get a handle to the robot?

$\endgroup$

2 Answers 2

3
$\begingroup$

Since version 2023.0.0 of the webots_ros2 package, the Robot node (or Supervisor or Driver) cannot be accessed anymore. This is due to the fact that the webots_ros2_driver package (which defines the WebotsNode) doesn't use the C++ API of the libController anymore. Instead it now uses the C API.

Therefore, only the C API can now be used in plugins. You can take a look at the following tutorial: Creating a Custom C++ Plugin which uses the C API to access the robot devices and apply velocities to its motors.

$\endgroup$
1
$\begingroup$

I was able to accomplish this by:

  1. set SUPERVISOR to TRUE in the WeBots tree for the robot you want to get fields from and save your world (make sure you are saving the actual world and no a cached copy run by ros2 launch)

  2. in the init function, get the WeBots NODE (not the ROS2 Node) using .getSelf() (or wb_supervisor_node_get_self()). Save this object off for later use.

  3. in your step function (or any of your callbacks; just not the initialization functions) call .getField. You can use wb_supervisor_field_get_count (.getCount) from there.

$\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.