-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adding New Node and API Function
Benjamin Délèze edited this page Jun 14, 2023
·
31 revisions
- Webots Core:
- Add a .wrl file in
webots/resources/nodes/
. - Add a .png image of size 128x128 pixels in
webots/resources/nodes/icons/
. - Add .cpp and .hpp files in
src/webots/nodes
, and add a new entry insrc/webots/Makefile
. - Add an enum entry in
webots/include/controller/c/webots/nodes.h
andwebots/include/controller/cpp/webots/Node.hpp
. - Add the node name in
wb_node_get_name()
function inwebots/src/controller/c/node.c
. - Add a
gen_const()
entry inwebots/src/controller/matlab/mgenerate.py
and run it with the-update
option. - Add the node in
src/webots/nodes/utils/WbConcreteNodeFactory.cpp
. - Add the node in
src/webots/nodes/utils/WbNodeUtilities.cpp
. - Add the node in
src/webots/core/WbLanguage.cpp
.
- Add a .wrl file in
- WebotsJS
- 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. - If the new node should be supported in WebotsJS:
- Create a new javascript file in
$WEBOTS_HOME/resources/web/wwi/nodes/
for the new node. - Modify the
#parseNode
function of$WEBOTS_HOME/resources/web/wwi/Parser.js
to be able to parse the new node. - Add the node specific fields to the
applyUpdateToObject
function of$WEBOTS_HOME/resources/web/wwi/X3dScene.js
. - If it is a new device or joint: modify
$WEBOTS_HOME/resources/web/wwi/FloatingProtoParameterWindow.js
. - Add the node in the
getAllowedBaseType
function of$WEBOTS_HOME/resources/web/wwi/NodeSelectorWindow.js
. - Add the node in
$WEBOTS_HOME/resources/web/wwi/nodes/wb_node_type.js
- Create a new javascript file in
- Run the script:
-
Webots-cloud (once #88 is merged):
- Add the node in
php/create_or_update.php
, in the$base_nodes
array. - If the node is a device, add it in
php/create_or_update.php
, in the$device_regex
string. - Add the node in
httpdocs/js/webots-cloud.js
in thebaseNodeList
array. - If the node is a device, add it in
httpdocs/js/webots-cloud.js
, in the$device_regex
string of theloadProtoFromScratch
function.
- Add the node in
- Documentation:
- Create a new file
webots/docs/references/'node_name'.md
and add it to the menu. - Update
webots/docs/reference/supervisor.md
. - Update
webots/docs/reference/nodes-and-keywords.md
. - Add the new node in
webots/docs/reference/node-chart.md
. - Update
webots/docs/reference/nodes-and-api-functions.md
.
- Create a new file
- If the node is a device:
- Add in
webots/lib/controller/matlab/launcher.m
andwebots/lib/controller/matlab/allincludes.h
the entries corresponding to the device node. - Add the C++ controller class in
webots/resources/templates/controllers/cpp.vcxproj
andcpp.vcxproj.filter
. - If the node name is newDevice, declare and define
getNewDevice()
andCreateNewDevice()
inRobot.hpp
andRobot.cpp
(#include in Robot.hpp needed). - If the node name is new_device, add
extern void wb_new_device_init(WbDevice *)
indevice.c
and add one more branch to the switch indevice.c::wb_device_init();
- Add a corresponding robot window widget in
webots/resources/projects/plugins/robot_windows/generic/
. - If the node name is newDevice, add
RosNewDevice.cpp
andRosNewDevice.hpp
files inwebots/projects/default/controller/ros/
and add a new entry inwebots/projects/default/controller/ros/Makefile
. If the new device is a sensor with a ~getValue() function, creates a topic for it. - Add the
RosNewDevice
to the constructor ofRos.cpp
inwebots/projects/default/controller/ros/
. - Go to Adding a new API function
- Add a demo featuring this new device in
webots/projects/samples/devices/
and add it in thewebots/projects/guided_tour.txt
.
- Add in
- Add it in
/include/controller/c/webots/
. - Add it in
/src/controller/c/
(don't forget to include a "bad device tag" error message if the function takes a WbDeviceTag). - Add it in
/src/controller/c/Controller.def
. - Add it in
/src/webots/nodes/
. - Add it in
/include/controller/cpp/webots/
. - Add it in
/src/controller/cpp/
. - Add it in
/src/controller/java/
, i.e. in Makefile and controller.i. - Add it in
/lib/controller/python/controller/
i.e. in node.py andnew_device.py
. - Add it in
/src/controller/matlab/mgenerate.py
, possibly also inlib/controller/matlab/
and runmgenerate.py
with the-update
option. Updatelib/controller/matlab/.gitignore
if needed. - Add it in
/src/webots/core/WbLanguage.cpp
. - Add it in
/docs/reference/'device_name'.md
. - Add a sample usage demo in
/projects/sample/
. - Add it in ROS default controller and examples:
- In
webots_ros
repository:- Check if existing messages or standard ROS messages can be used for the new API function.
- If not, create a service or message description file
/resources/webots_ros/srv/<function_name>.srv
or/resources/webots_ros/msg/<function_name>.msg
. - Try to use as much as possible standard message types, sensor message types or geometry message types.
- Add it in the
/resources/webots_ros/CMakeLists.txt
file.
- In
/projects/default/controller/ros/
controller:- Add it in
Ros<Device>
class: define a function callback and a service server (for a service) or a topic (for a message). - If the function corresponds to getting a value that changes at each step (e.g. sensor output) prefer a message/topic to a service.
- Add it in
- In
webots_ros
repository:- Add a test in
/resources/webots_ros/src/complete_test.cpp
.
- Add a test in
- Commit changes to the
webots_ros
repository. - Sync
webots_ros
submodule.
- In
- Add a new API test in
/tests/api
(new world and controller).