### Install InnoSetup Source: https://github.com/cyberbotics/webots/wiki/Windows-Optional-Dependencies Execute this script to install InnoSetup version 6.2.1 or later, which is needed for creating Webots binary setup packages for Windows distribution. ```shell ./scripts/install/inno_setup_installer.sh ``` -------------------------------- ### Install ikfast Solvers (Linux) Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/development-2020.md Instructions for installing ikfast solvers using pip on Linux. This command should be run from the directory containing the setup. ```bash pip install . ``` -------------------------------- ### Install and Start Zram Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/advanced-configuration.md Install and enable the zram-config package to compress less-used RAM, acting as a faster alternative to swap. This helps manage memory usage for more parallel simulations. ```bash sudo apt-get install zram-config sudo service zram-config start ``` -------------------------------- ### Install Qt and Make Installation Package on Mac Source: https://github.com/cyberbotics/webots/wiki/Qt-compilation Navigate to the Webots scripts directory and execute the Qt macOS installer script. This installs Qt and creates the necessary installation package for Webots on macOS. Optionally, edit the script to fix rpath issues. ```bash cd ~/webots/scripts/install/ # Optional: edit the 2 first paths of ./qt_mac_installer.sh ./qt_mac_installer.sh ``` -------------------------------- ### Build and Install ODE with Autotools Source: https://github.com/cyberbotics/webots/blob/master/src/ode/INSTALL.txt After successful configuration, build the library using 'make' and install it using 'make install'. The install command also creates pkg-config scripts. ```bash $ make $ make install ``` -------------------------------- ### Example: Software Emulation Detected on Linux Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/verifying-your-graphics-driver-installation.md This output signifies that a hardware driver is not installed, and your system is using a slower software emulation for OpenGL. A hardware driver installation is recommended. ```bash $ glxinfo | grep OpenGL OpenGL vendor string: Mesa project: www.mesa3d.org OpenGL renderer string: Mesa GLX Indirect OpenGL version string: 1.4 (1.5 Mesa 6.5.2) ... ``` -------------------------------- ### Initialize and Run Webots Controller (C++) Source: https://github.com/cyberbotics/webots/blob/master/docs/reference/robot.md The C++ API handles initialization and cleanup automatically. This example demonstrates setting up a controller class, getting device tags, enabling sensors, and running the main control loop. ```C++ #include #include #include class MyController : public Robot { public: MyController() { timeStep = 32; // set the control time timeStep // get device tags distanceSensor = getDistanceSensor("my_distance_sensor"); led = getLed("my_led"); distanceSensor->enable(timeStep); // enable sensors to read data from them } void run() { // main control loop: perform simulation steps of 32 milliseconds // and leave the loop when the simulation is over while (step(timeStep) != -1) { double val = distanceSensor->getValue(); // Read and process sensor data led->set(1); // Send actuator commands } } private: int timeStep; DistanceSensor *distanceSensor; Led *led; } // main C++ program int main() { MyController *controller = new MyController(); controller->run(); delete controller; return 0; } ``` -------------------------------- ### Webots CI Test Setup Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2021.md This example shows how Webots is tested in a Continuous Integration environment. It involves running Webots from scripts in the background for automated testing. ```bash git clone https://github.com/cyberbotics/webots.git cd webots cd tests ``` -------------------------------- ### Install Homebrew Packages Source: https://github.com/cyberbotics/webots/wiki/macOS-installation Installs essential packages like cmake, swig, wget, and protobuf using Homebrew. Ensure Homebrew is installed first. ```shell brew install cmake swig wget protobuf ``` -------------------------------- ### Webots Controller Initialization Example Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2019.md This C code shows a typical initialization sequence for a Webots controller, including getting device handles for emitter and receiver nodes. It's crucial that these devices are obtained before the main simulation loop. ```c #include #include #include #define TIME_STEP 64 int main(int argc, char **argv) { wb_robot_init(); int emitter = wb_robot_get_device("emitter"); int receiver = wb_robot_get_device("receiver"); while (wb_robot_step(TIME_STEP) != -1) { // Simulation loop } wb_robot_cleanup(); return 0; } ``` -------------------------------- ### Install ffmpeg Dependencies Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2021.md Install necessary development libraries for video capture. Ensure these are installed before attempting to use video recording features. ```bash sudo apt-get install libx264-dev ``` ```bash sudo apt-get install libfdk-aac1 ``` ```bash sudo apt install ffmpeg ``` -------------------------------- ### Launch SUMO Interface with Options Source: https://github.com/cyberbotics/webots/blob/master/docs/automobile/sumo-interface.md Launches the SUMO interface controller with specific SUMO options. This example includes '--use-netconvert' and '--no-gui'. ```bash $WEBOTS_HOME/webots-controller $WEBOTS_HOME/projects/default/controllers/sumo_supervisor/sumo_supervisor.py --use-netconvert --no-gui ``` -------------------------------- ### Silent Webots Installation on Windows Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/installation-procedure.md Installs Webots silently on Windows from an administrator DOS console using the setup executable with specific flags. ```bash webots-{{ webots.version.package }}_setup.exe /SUPPRESSMSGBOXES /VERYSILENT /NOCANCEL /NORESTART /ALLUSERS ``` -------------------------------- ### Download and Make Qt Executable Source: https://github.com/cyberbotics/webots/wiki/Qt-compilation Download the Qt online installer and make it executable. This is the first step for installing Qt on Linux. ```bash curl -L -O https://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run chmod +x ./qt-unified-linux-x64-online.run ./qt-unified-linux-x64-online.run ``` -------------------------------- ### Hello World Example in C Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/controller-programming.md A basic C controller that prints 'Hello World!' to the console. Requires initialization and cleanup functions. ```c #include #include int main() { wb_robot_init(); while(wb_robot_step(32) != -1) printf("Hello World!\n"); wb_robot_cleanup(); return 0; } ``` -------------------------------- ### Setup Session Server Autostart Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/session-server.md Configure the session server to launch automatically on reboot by creating a desktop entry file in the autostart directory. ```bash cd ~/.config mkdir -p autostart cd autostart echo "[Desktop Entry]" > session_server.desktop echo "Name=session_server" >> session_server.desktop echo "Exec=python /home/cyberbotics/webots-server/session_server.py /home/cyberbotics/webots-server/config/session/session.json" >> session_server.desktop echo "Type=Application" >> session_server.desktop echo "X-GNOME-Autostart-enabled=true" >> session_server.desktop ``` -------------------------------- ### Install Emscripten SDK Source: https://github.com/cyberbotics/webots/wiki/Windows-Optional-Dependencies Clone the Emscripten SDK repository, navigate into it, and then download and install the latest SDK tools. This is part of the setup for the web interface with wren.js. ```shell git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install latest ``` -------------------------------- ### Install SUMO on Ubuntu 20.04 Source: https://github.com/cyberbotics/webots/wiki/SUMO-compilation Installs SUMO and its tools using apt, then copies binaries and dependencies to a custom directory for packaging. ```bash # Recommended: sudo apt-get autoremove libxerces-c3.2 libxerces-c-dev libfox-1.6-0 libfox-1.6-dev sudo add-apt-repository ppa:sumo/stable sudo apt-get update sudo apt-get install sumo sumo-tools cd $HOME/software mkdir sumo-1.13-Ubuntu_20.04 cd sumo-1.13-Ubuntu_20.04 mkdir bin cp /usr/bin/duarouter bin/ cp /usr/bin/netconvert bin/ cp /usr/bin/netedit bin/ cp /usr/bin/sumo bin/ cp /usr/bin/sumo-gui bin/ # other dependencies cp /usr/bin/activitygen bin/ cp /usr/bin/dfrouter bin/ cp /usr/bin/emissionsDrivingCycle bin/ cp /usr/bin/emissionsMap bin/ cp /usr/bin/jtrrouter bin/ cp /usr/bin/marouter bin/ cp /usr/bin/netgenerate bin/ cp /usr/bin/od2trips bin/ cp /usr/bin/polyconvert bin/ # To make it work on Ubuntu 22.04 we also need these libraries cp /usr/lib/libarmadillo.so.9 bin/ cp /usr/lib/x86_64-linux-gnu/libaec.so.0 bin/ cp /usr/lib/x86_64-linux-gnu/libarpack.so.2 bin/ cp /usr/lib/x86_64-linux-gnu/libblas.so.3 bin/ cp /usr/lib/x86_64-linux-gnu/libCharLS.so.2 bin/ cp /usr/lib/x86_64-linux-gnu/libcfitsio.so.8 bin/ cp /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 bin/ cp /usr/lib/x86_64-linux-gnu/libdap.so.25 bin/ cp /usr/lib/x86_64-linux-gnu/libdapclient.so.6 bin/ cp /usr/lib/x86_64-linux-gnu/libepsilon.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/libFOX-1.6.so.0 bin/ cp /usr/lib/x86_64-linux-gnu/libfreexl.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/libfyba.so.0 bin/ cp /usr/lib/x86_64-linux-gnu/libfygm.so.0 bin/ cp /usr/lib/x86_64-linux-gnu/libfyut.so.0 bin/ cp /usr/lib/x86_64-linux-gnu/libgdal.so.26 bin/ cp /usr/lib/x86_64-linux-gnu/libgeos.so.3.10.2 bin/ cp /usr/lib/x86_64-linux-gnu/libgeos_c.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/libgeotiff.so.5 bin/ cp /usr/lib/x86_64-linux-gnu/libgfortran.so.5 bin/ cp /usr/lib/x86_64-linux-gnu/libhdf5_serial.so.103 bin/ cp /usr/lib/x86_64-linux-gnu/libhdf5_serial_hl.so.100 bin/ cp /usr/lib/x86_64-linux-gnu/libjson-c.so.4 bin/ cp /usr/lib/x86_64-linux-gnu/libkmlbase.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/libkmldom.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/libkmlengine.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/liblapack.so.3 bin/ cp /usr/lib/x86_64-linux-gnu/libminizip.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21 bin/ cp /usr/lib/x86_64-linux-gnu/libnetcdf.so.15 bin/ cp /usr/lib/x86_64-linux-gnu/libodbc.so.2 bin/ cp /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 bin/ cp /usr/lib/x86_64-linux-gnu/libopenblas.so.0 bin/ cp /usr/lib/x86_64-linux-gnu/libpoppler.so.97 bin/ cp /usr/lib/x86_64-linux-gnu/libproj.so.15 bin/ cp /usr/lib/x86_64-linux-gnu/libpq.so.5 bin/ cp /usr/lib/x86_64-linux-gnu/libqhull.so.7 bin/ cp /usr/lib/x86_64-linux-gnu/libspatialite.so.7 bin/ cp /usr/lib/x86_64-linux-gnu/libsuperlu.so.5 bin/ cp /usr/lib/x86_64-linux-gnu/libsz.so.2 bin/ cp /usr/lib/x86_64-linux-gnu/liburiparser.so.1 bin/ cp /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so bin/ cp /usr/lib/x86_64-linux-gnu/libwebp.so.6 bin/ cp /usr/lib/libdfalt.so.0 bin/ cp /usr/lib/libgdal.so.26 bin/ cp /usr/lib/libmfhdfalt.so.0 bin/ cp /usr/lib/libogdi.so.4 bin/ mkdir tools cp -R /usr/share/sumo/tools/traci tools/ cp -R /usr/share/sumo/tools/sumolib tools/ cp /usr/share/sumo/tools/randomTrips.py tools/ mkdir data cp -R /usr/share/sumo/data/3D data/ cp -R /usr/share/sumo/data/emissions data/ cp -R /usr/share/sumo/data/typemap data/ cp -R /usr/share/sumo/data/xsd data/ sudo apt-get autoremove sumo sumo-tools cd $HOME/software tar -cvjSf sumo-1.13-Ubuntu_20.04.tar.bz2 sumo-1.13-Ubuntu_20.04 ``` -------------------------------- ### Get Node Handle from DEF Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2020.md Example of how to get a node handle using getFromDef in Webots Supervisor. This method might return None if the node is inside a PROTO. ```python LED0 = robot.getFromDef('EPUCK_LED0') ``` -------------------------------- ### Display "hello world" Label Source: https://github.com/cyberbotics/webots/blob/master/docs/reference/supervisor.md Example of displaying a red "hello world" label at the top-left corner of the 3D window. ```C wb_supervisor_set_label(0,"hello world",0,0,0.1,0xff0000,0,"Arial"); ``` -------------------------------- ### Webots Installation on Debian Buster Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2021.md When encountering issues with pre-built Webots packages on Debian Buster, building from source is recommended. Follow the official Linux installation guide for detailed instructions. ```bash https://github.com/cyberbotics/webots/wiki/Linux-installation ``` -------------------------------- ### Get Relative Object Position in Webots (Python Example) Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2021.md This Python script demonstrates how to get the position of an object relative to another, which is often needed for inverse kinematics or robot-relative measurements. It can be adapted to C++. ```Python from controller import Supervisor supervisor = Supervisor() # Get the node of the object you want to track object_node = supervisor.getFromDef("myObject") # Get the node of the reference object (e.g., robot base) reference_node = supervisor.getFromDef("myRobotBase") # Get the position of the object object_position = object_node.getPosition() # Get the position of the reference node reference_position = reference_node.getPosition() # Calculate relative position (example: object position relative to reference) relative_position = [object_position[i] - reference_position[i] for i in range(3)] print(f"Relative position: {relative_position}") ``` -------------------------------- ### Install Git on Ubuntu Source: https://github.com/cyberbotics/webots/wiki/Linux-installation Installs the Git version control system on Ubuntu using apt. ```shell sudo apt install git ``` -------------------------------- ### Hello World Example in C++ Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/controller-programming.md A basic C++ controller that prints 'Hello World!' to the console. Uses object-oriented approach for robot interaction. ```cpp #include #include using namespace webots; int main() { Robot *robot = new Robot(); while (robot->step(32) != -1) std::cout << "Hello World!" << std::endl; delete robot; return 0; } ``` -------------------------------- ### Python Inverse Kinematics Example Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2020.md This Python script demonstrates an example of inverse kinematics, likely intended for use with a robot arm. It requires specific libraries and setup, as indicated by the discussion around pyikfast and Docker. ```python from math import pi from controller import * #------------------------------------------------------------------------------ # Inverse Kinematics #------------------------------------------------------------------------------ def compute_ik(target_position, target_orientation): # compute inverse kinematics # target_position: a list of 3 doubles representing the target position # target_orientation: a list of 4 doubles representing the target orientation (quaternion) # return: a list of doubles representing the joint angles # Example: compute inverse kinematics for the arm # The arm is composed of 7 joints. # The target position is (0.5, 0.0, 0.5) # The target orientation is (1, 0, 0, 0) (identity quaternion) # Note: This is a placeholder function. The actual inverse kinematics computation # depends on the robot model and the IK library used. # For example, if using pyikfast: # ik = IKFast(robot_model) # joint_angles = ik.solve(target_position, target_orientation) # For this example, we will return a dummy list of joint angles. joint_angles = [0.0] * 7 return joint_angles #------------------------------------------------------------------------------ # Main function #------------------------------------------------------------------------------ def main(): # create the Robot instance. robot = Robot() # get the time step of the current simulation (in milliseconds). time_step = int(robot.getBasicTimeStep()) # get the arm joints shoulder_pan_joint = robot.getDevice("shoulder_pan_joint") shoulder_lift_joint = robot.getDevice("shoulder_lift_joint") upper_arm_joint = robot.getDevice("upper_arm_joint") elbow_joint = robot.getDevice("elbow_joint") wrist_1_joint = robot.getDevice("wrist_1_joint") wrist_2_joint = robot.getDevice("wrist_2_joint") wrist_3_joint = robot.getDevice("wrist_3_joint") # set the target position and orientation target_position = [0.5, 0.0, 0.5] target_orientation = [1.0, 0.0, 0.0, 0.0] # compute inverse kinematics joint_angles = compute_ik(target_position, target_orientation) # set the joint angles shoulder_pan_joint.setPosition(joint_angles[0]) shoulder_lift_joint.setPosition(joint_angles[1]) upper_arm_joint.setPosition(joint_angles[2]) elbow_joint.setPosition(joint_angles[3]) wrist_1_joint.setPosition(joint_angles[4]) wrist_2_joint.setPosition(joint_angles[5]) wrist_3_joint.setPosition(joint_angles[6]) # wait for the simulation to end while robot.step(time_step) != -1: pass if __name__ == "__main__": main() ``` -------------------------------- ### Webots Camera Recognition Example in C Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2019.md This C code provides an example of how to use Webots camera recognition features. It shows how to get the number of detected objects and iterate through them. Refer to the Webots documentation for detailed API usage. ```c #include #include #include #include int main(int argc, char **argv) { wb_robot_init(); WbDeviceTag camera = wb_robot_get_device("camera"); wb_camera_enable(camera, 64); while (wb_robot_step(64) != -1) { int num_objects = wb_camera_recognition_get_number_of_objects(camera); if (num_objects > 0) { printf("Detected %d objects.\n", num_objects); for (int i = 0; i < num_objects; i++) { const WbCameraRecognitionObject *object = wb_camera_recognition_get_object_by_id(camera, i); printf(" - Object %d: position = [%.3f, %.3f, %.3f], size = [%.3f, %.3f]\n", i, object->position[0], object->position[1], object->position[2], object->size[0], object->size[1]); } } }; wb_robot_cleanup(); return 0; } ``` -------------------------------- ### Start Session and Simulation Servers Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/protocol-and-quick-start.md Starts both the session server and the simulation server using the provided script. This command uses the 'local' configuration profiles. ```bash ./server.sh start local ``` -------------------------------- ### PascalCase for Type Names Source: https://github.com/cyberbotics/webots/wiki/CPP-Coding-Style Type names must use PascalCase, starting with an uppercase letter, for example, 'Line' or 'SavingsAccount'. ```plaintext Line, SavingsAccount ``` -------------------------------- ### Zram Output Example Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/advanced-configuration.md Example output from 'cat /proc/swaps' showing the presence of zram devices alongside traditional swap partitions. ```text Filename Type Size Used Priority /dev/sda3 partition 9215996 0 -1 /dev/zram0 partition 755740 8104 5 /dev/zram1 partition 755740 8004 5 /dev/zram2 partition 755740 8120 5 /dev/zram3 partition 755740 8064 5 ``` -------------------------------- ### Accessing Robot Node Fields Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2020.md To access specific fields of a robot node, such as its translation or sensor data, you need to get the field name using the robot object. This example shows how to attempt to get the 'translation' field of an FSR sensor. ```python FSRField =robot.getField('TouchSensor "LFsrFL"') FSRField1 =FSRField.getField('translation') ``` -------------------------------- ### Install Docker for Webots Launching Source: https://github.com/cyberbotics/webots/wiki/Linux-Optional-Dependencies Install Docker, which may be used by simulation_server.py to launch Webots instances. This is an optional step. ```bash sudo apt install docker ``` -------------------------------- ### Lower Camel Case for Variable Names Source: https://github.com/cyberbotics/webots/wiki/CPP-Coding-Style Variable names should follow lowerCamelCase, starting with a lowercase letter. Examples include 'line' and 'savingsAccount'. ```plaintext int line; SavingsAccount savingsAccount; ``` -------------------------------- ### Hello World Example in Python Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/controller-programming.md A basic Python controller that prints 'Hello World!' to the console. Leverages the Webots Python API. ```python from controller import Robot robot = Robot() while robot.step(32) != -1: print("Hello World!") ``` -------------------------------- ### Setting OpenCV Path Variable Source: https://github.com/cyberbotics/webots/blob/master/docs/discord/technical-questions-2020.md This is an example of how to set the OpenCV path in environment variables. Ensure this path points to your OpenCV installation's binary directory. ```bash D:\username\Documents\opencv\build\bin ``` -------------------------------- ### Hello World Example in Java Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/controller-programming.md A basic Java controller that prints 'Hello World!' to the console. Utilizes the Webots Java API. ```java import com.cyberbotics.webots.controller.Robot; public class HelloWorld { public static void main(String[] args) { final Robot robot = new Robot(); while (robot.step(32) != -1) System.out.println("Hello World!"); } } ``` -------------------------------- ### Webots Command Line Usage Source: https://github.com/cyberbotics/webots/blob/master/docs/guide/starting-webots.md This shows the general usage and available options for starting Webots from the command line. Use this to understand the different parameters you can pass. ```bash Usage: webots [options] [worldfile] Options: --help Display this help message and exit. --version Display version information and exit. --sysinfo Display information about the system and exit. --mode= Choose the startup mode, overriding application preferences. The argument must be either pause, realtime or fast. --no-rendering Disable rendering in the main 3D view. --fullscreen Start Webots in fullscreen. --minimize Minimize the Webots window on startup. --batch Prevent Webots from creating blocking pop-up windows. --clear-cache Clear the cache of Webots on startup. --stdout Redirect the stdout of the controllers to the terminal. --stderr Redirect the stderr of the controllers to the terminal. --port Change the TCP port used by Webots (default value is 1234). --stream[=] Start the Webots streaming server. The argument should be either w3d (default) or mjpeg. --extern-urls Print on stdout the URL of extern controllers that should be started. --heartbeat[=