Skip to content

Adding New Node and API Function

Benjamin Délèze edited this page Jun 14, 2023 · 31 revisions

Adding a new node

  1. Webots Core:
    1. Add a .wrl file in webots/resources/nodes/.
    2. Add a .png image of size 128x128 pixels in webots/resources/nodes/icons/.
    3. Add .cpp and .hpp files in src/webots/nodes, and add a new entry in src/webots/Makefile.
    4. Add an enum entry in webots/include/controller/c/webots/nodes.h and webots/include/controller/cpp/webots/Node.hpp.
    5. Add the node name in wb_node_get_name() function in webots/src/controller/c/node.c.
    6. Add a gen_const() entry in webots/src/controller/matlab/mgenerate.py and run it with the -update option.
    7. Add the node in src/webots/nodes/utils/WbConcreteNodeFactory.cpp.
    8. Add the node in src/webots/nodes/utils/WbNodeUtilities.cpp.
    9. Add the node in src/webots/core/WbLanguage.cpp.
  2. WebotsJS
    1. Run the script: $WEBOTS_HOME/resources/web/wwi/protoVisualizer/scripts/basenode_encoder.py to regenerate the $WEBOTS_HOME/resources/web/wwi/protoVisualizer/FieldModel.js class.
    2. If the new node should be supported in WebotsJS:
      1. Create a new javascript file in $WEBOTS_HOME/resources/web/wwi/nodes/ for the new node.
      2. Modify the #parseNode function of $WEBOTS_HOME/resources/web/wwi/Parser.js to be able to parse the new node.
      3. Add the node specific fields to the applyUpdateToObject function of $WEBOTS_HOME/resources/web/wwi/X3dScene.js.
      4. If it is a new device or joint: modify $WEBOTS_HOME/resources/web/wwi/FloatingProtoParameterWindow.js.
      5. Add the node in the getAllowedBaseType function of $WEBOTS_HOME/resources/web/wwi/NodeSelectorWindow.js.
      6. Add the node in $WEBOTS_HOME/resources/web/wwi/nodes/wb_node_type.js
  3. Webots-cloud (once #88 is merged):
    1. Add the node in php/create_or_update.php, in the $base_nodes array.
    2. If the node is a device, add it in php/create_or_update.php, in the $device_regex string.
    3. Add the node in httpdocs/js/webots-cloud.js in the baseNodeList array.
    4. If the node is a device, add it in httpdocs/js/webots-cloud.js, in the $device_regex string of the loadProtoFromScratch function.
  4. Documentation:
    1. Create a new file webots/docs/references/'node_name'.md and add it to the menu.
    2. Update webots/docs/reference/supervisor.md.
    3. Update webots/docs/reference/nodes-and-keywords.md.
    4. Add the new node in webots/docs/reference/node-chart.md.
    5. Update webots/docs/reference/nodes-and-api-functions.md.
  5. If the node is a device:
    1. Add in webots/lib/controller/matlab/launcher.m and webots/lib/controller/matlab/allincludes.h the entries corresponding to the device node.
    2. Add the C++ controller class in webots/resources/templates/controllers/cpp.vcxproj and cpp.vcxproj.filter.
    3. If the node name is newDevice, declare and define getNewDevice() and CreateNewDevice() in Robot.hpp and Robot.cpp (#include in Robot.hpp needed).
    4. If the node name is new_device, add extern void wb_new_device_init(WbDevice *) in device.c and add one more branch to the switch in device.c::wb_device_init();
    5. Add a corresponding robot window widget in webots/resources/projects/plugins/robot_windows/generic/.
    6. If the node name is newDevice, add RosNewDevice.cpp and RosNewDevice.hpp files in webots/projects/default/controller/ros/ and add a new entry in webots/projects/default/controller/ros/Makefile. If the new device is a sensor with a ~getValue() function, creates a topic for it.
    7. Add the RosNewDevice to the constructor of Ros.cpp in webots/projects/default/controller/ros/.
    8. Go to Adding a new API function
    9. Add a demo featuring this new device in webots/projects/samples/devices/ and add it in the webots/projects/guided_tour.txt.

Adding a new API function

  1. Add it in /include/controller/c/webots/.
  2. Add it in /src/controller/c/ (don't forget to include a "bad device tag" error message if the function takes a WbDeviceTag).
  3. Add it in /src/controller/c/Controller.def.
  4. Add it in /src/webots/nodes/.
  5. Add it in /include/controller/cpp/webots/.
  6. Add it in /src/controller/cpp/.
  7. Add it in /src/controller/java/, i.e. in Makefile and controller.i.
  8. Add it in /lib/controller/python/controller/ i.e. in node.py and new_device.py.
  9. Add it in /src/controller/matlab/mgenerate.py, possibly also in lib/controller/matlab/ and run mgenerate.py with the -update option. Update lib/controller/matlab/.gitignore if needed.
  10. Add it in /src/webots/core/WbLanguage.cpp.
  11. Add it in /docs/reference/'device_name'.md.
  12. Add a sample usage demo in /projects/sample/.
  13. Add it in ROS default controller and examples:
    1. In webots_ros repository:
      1. Check if existing messages or standard ROS messages can be used for the new API function.
      2. If not, create a service or message description file /resources/webots_ros/srv/<function_name>.srv or /resources/webots_ros/msg/<function_name>.msg.
      3. Try to use as much as possible standard message types, sensor message types or geometry message types.
      4. Add it in the /resources/webots_ros/CMakeLists.txt file.
    2. In /projects/default/controller/ros/ controller:
      1. Add it in Ros<Device> class: define a function callback and a service server (for a service) or a topic (for a message).
      2. If the function corresponds to getting a value that changes at each step (e.g. sensor output) prefer a message/topic to a service.
    3. In webots_ros repository:
      1. Add a test in /resources/webots_ros/src/complete_test.cpp.
    4. Commit changes to the webots_ros repository.
    5. Sync webots_ros submodule.
  14. Add a new API test in /tests/api (new world and controller).
Clone this wiki locally