Skip to content

Adding New Node and API Function

Stefania Pedrazzi edited this page Oct 12, 2020 · 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 src/Controller/api/node.c.
    6. Add a gen_const() entry in webots/lib/controller/matlab/mgenerate.py and run it.
    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. 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.
  3. 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. If the node name is newDevice, declare and define getNewDevice() and CreateNewDevice() in Robot.hpp and Robot.cpp (#include in Robot.hpp needed).
    3. 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();
    4. Add a corresponding robot window widget in webots/resources/projects/plugins/robot_windows/generic/.
    5. 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.
    6. Add the RosNewDevice to the constructor of Ros.cpp in webots/projects/default/controller/ros/.
    7. Go to Adding a new API function
    8. 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/api/ (don't forget to include a "bad device tag" error message if the function takes a WbDeviceTag).
  3. Add it in /src/Controller/Controller.def.
  4. Add it in /src/webots/nodes/.
  5. Add it in /include/controller/cpp/webots/.
  6. Add it in /resources/languages/cpp/.
  7. Add it in /resources/languages/java/, i.e. in Makefile and controller.i.
  8. Add it in /resources/languages/python/ i.e. in Makefile and controller.i.
  9. Add it in /lib/controller/matlab/mgenerate.py and run it.
  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 /projects/default/controller/ros/ controller and webots_ros repository:
    1. Create a service or message description file (if possible use an already existing one or a standard one) /resources/webots_ros/srv/<function_name>.srv or /resources/webots_ros/msg/<function_name>.msg.
    2. Add it in Ros<Device> class: define a function callback and a service server (for a service) or a topic (for a message).
    3. If the function corresponds to getting a value that changes at each step (e.g. sensor output) prefer a message/topic to a service.
    4. Try to use as much as possible standard message types, sensor message types or geometry message types.
    5. Add it in the /resources/webots_ros/CMakeLists.txt and /projects/languages/ros/webots_ros/CMakeLists.txt file.
    6. Add a test in /resources/webots_ros/src/complete_test.cpp``and /projects/languages/ros/webots_ros/src/complete_test.cpp.
    7. Commit changes to the webots_ros repository
  14. Add a new API test in /tests/api (new world and controller).
Clone this wiki locally