This section gives various examples of complex behaviors and/or functionalities. The examples are located in "[WEBOTS_HOME/projects/samples/howto/]({{ url.github_tree }}/projects/samples/howto/)". Each example has its own controllers and worlds directories. For each, the world file and its corresponding controller are named according to the behavior they exemplify.
[asymmetric_friction1.wbt]({{ url.github_tree }}/projects/samples/howto/asymmetric_friction/worlds/asymmetric_friction1.wbt)
Keywords: ContactProperties, asymmetric friction
This example shows the setup of asymmetric friction between two solids.
A small box slides on two leaning fixed boxes.
Each of the boxes are striped with black lines.
There is a smaller friction along the black lines, therefore the box is sliding along the black lines.
[asymmetric_friction2.wbt]({{ url.github_tree }}/projects/samples/howto/asymmetric_friction/worlds/asymmetric_friction2.wbt)
Keywords: ContactProperties, asymmetric friction
This example shows the setup of asymmetric friction between two solids.
A solid composed of two cylinders is sliding down a leaning plane.
The black strips on the cylinders indicate the friction direction: there is smaller friction along the black lines.
Rotate the solid to modify its speed.
Keywords: Camera, stereovision, stereoscopic cameras
This example simply shows the use of two Cameras for stereovision.
The example does not actually perform stereovision or any form of computer vision.
Keywords: Humanoid robot, biped robot, power off, passive joint
In this example, a biped robot stands up while his head rotates.
After a few seconds, all the motors are turned off and the robot collapses.
This example illustrates the build of a simple articulated robot and also how to turn off motor power.
[center_of_mass.wbt]({{ url.github_tree }}/projects/samples/howto/center_of_mass/worlds/center_of_mass.wbt)
Keywords: Center of mass
In this example, a light robot rotates a heavy mass.
The inertia of the heavy mass lets the robot base turn round.
The overall center of mass of the robot is changing.
This can be visualized with the View / Optional Rendering / Show Center of Mass... or mass tab of in the node editor when the robot is selected.
Keywords: Console
In this example is shown how to customize the formatting of the text in the console.
It allows to change the color, modify the style and clear the console.
[custom_robot_window_simple.wbt]({{ url.github_tree }}/projects/samples/howto/custom_robot_window_simple/worlds/custom_robot_window_simple.wbt)
Keywords: custom robot window, controller plugin, HTML, JavaScript
This example shows a minimal two way communication between a simple robot window and a robot controller.
The JavaScript and Python files deal with the interactions between the page and the robot, using the WWI API to exchange string messages.
[custom_robot_window.wbt]({{ url.github_tree }}/projects/samples/howto/custom_robot_window/worlds/custom_robot_window.wbt)
Keywords: custom robot window, controller plugin, HTML, JavaScript, CSS
This example shows a simple custom robot window.
The HTML file contains the page content.
The CSS file contains the page style.
The JavaScript and C files deal with the interactions between the page and the robot, using the WWI API to exchange string messages.
[cylinder_stack.wbt]({{ url.github_tree }}/projects/samples/howto/cylinder_stack/worlds/cylinder_stack.wbt)
Keywords: Supervisor, contact points, cylinder collisions
In this example, a stack of cylinders collapses.
A Supervisor controller gets information on the contact points and displays the reaction forces in the Console.
[force_control.wbt]({{ url.github_tree }}/projects/samples/howto/force_control/worlds/force_control.wbt)
Keywords: Force control, linear motor, spring and damper
This world shows two boxes connected by a LinearMotor.
Here, the purpose is to demonstrate the usage of the wb_motor_set_force function to control a LinearMotor with a user specified force.
In this example, the wb_motor_set_force function is used to simulate the effect of a spring and a damper between the two boxes.
When the simulation starts, the motor force is used to move the boxes apart.
Then, the motor force is turned off and the boxes oscillate for a while, according to the spring and damping equations programmed in the controller.
In addition, there is an equivalent version of a MATLAB controller force_control_matlab that you can switch to.
Keywords: four-wheeled frame
This example shows three models of four-wheeled vehicles.
In the first layout, the four motorized wheels are positioned circularly, as could be done for omnidirectional-wheeled robots.
In the second layout, the four motorized wheels are oriented in the same direction, as could be done for a robot with tracks.
In the third layout, a simple Ackermann steering geometry is shown.
Note that more completed Ackermann steering geometry can be achieved using the [AckermannVehicle](https://webots.cloud/run?url={{ url.github_blob }}/projects/vehicles/protos/abstract/AckermannVehicle.proto) PROTO, and the car library.
Keywords: gears, self-collision
This example shows the transfer of power between two gears through physical interaction.
The red gear is motorized whereas the blue one is passive, and when the boundingObject at the tip of the teeth collides the second wheel begins to turn.
Using this sort of approach as general purpose transmission is not generally advised but does work with some tuning of the dampingConstant of the HingeJoint, and the ERP and CFM values in the WorldInfo node.
[inverted_pendulum.wbt]({{ url.github_tree }}/projects/samples/howto/inverted_pendulum/worlds/inverted_pendulum.wbt)
Keywords: Inverted pendulum, PID, LinearMotor
In this example, a robot moves from left to right in order to keep an inverted pendulum upright.
This is known as the "Inverted Pendulum Problem", and it is solved in our example by using a PID (Proportional Integral Differential) controller.
[mouse_events.wbt]({{ url.github_tree }}/projects/samples/howto/mouse_events/worlds/mouse_events.wbt)
Keywords: Mouse events, user input
This example shows the use of the Supervisor API to retrieve mouse events.
When the simulation is running, the Supervisor controller called mouse_events.c waits for a mouse event and displays in the Console the 3D and 2D coordinates of the mouse and the name of the hit object.
The controller of this simulation is blocking, which means it will block until a mouse click is detected and it will not advance the simulation time.
An alternative non blocking controller called mouse_events_non_blocking.c is also available for this example.
Keywords: Omnidirectional wheels
This example shows an omnidirectional wheel model.
In this example, the omnidirectional wheels are modeled with two layers of joints and cylinders solids.
Faster omnidirectional wheels implementations could be achieved using asymmetric friction (cf. Youbot model).
Keywords: Reinforcement learning, OpenAI Gym
This example shows an integration of OpenAI Gym with Webots.
In this example, the robot tries to keep an inverted pendulum up as long as possible.
The OpenAI Gym interface is utilized by Stable Baselines3 to train the robot to keep the inverted pendulum up.
[passive_dynamic_walker.wbt]({{ url.github_tree }}/projects/samples/howto/passive_dynamic_walker/worlds/passive_dynamic_walker.wbt)
Keywords: Passive dynamic walker
This example shows a passive dynamic walker model.
This biped robot is not motorized.
It goes down the slope with a smooth motion simply because of its shape and its potential energy.
Keywords: Pedal racer, apply a force, mechanical loop, SolidReference
This example shows the mouse interaction with a complex model.
You can apply a force to the pedals using alt + mouse left click.
Keywords: Physics plugin, OpenGL drawing, flying robot, Emitter, Receiver
In this example, a robot flies using a physics plugin.
This plugins is an example of:
- How to access Webots objects in the physics plugin.
- How to exchange information with the controller.
- How to add custom forces.
- How to move objects.
- How to handle collisions.
[rolling_friction.wbt]({{ url.github_tree }}/projects/samples/howto/rope/worlds/rolling_friction.wbt)
Keywords: ContactProperties, rolling friction
In this example is demonstrated the principle of rolling friction.
The physics engine (ODE) supports up to three coefficients, commonly referred to as rho, rho2, and rhoN.
The black marbles are free to roll, however they are subject to different values of rho and therefore some take longer than others to accelerate.
The green marbles are also free to roll, but are given an initial lateral velocity.
The resulting lateral movement is limited to varying degrees due to having different values of rho2.
Lastly, the blue marbles are initially spun around the Z axis and they come to a halt at different moments because they have different values of rhoN.
Keywords: BallJoint, rope
In this example, a rope is simulated.
The rope is composed of several discrete rigid cylinders attached using ball joints.
[sick_terrain_scanning.wbt]({{ url.github_tree }}/projects/samples/howto/sick_terrain_scanning/worlds/sick_terrain_scanning.wbt)
Keywords: Lidar, Sick, scanning
In this example, a Pioneer 3AT mounted with a Sick LMS 291 is scanning its environment.
Each lidar scan is displayed in a Display device.
A Supervisor controller applies the scan depth output by removing pixels on a black texture which is applied on the ground.
[spinning_top.wbt]({{ url.github_tree }}/projects/samples/howto/spinning_top/worlds/spinning_top.wbt)
Keywords: Spinner, chessboard, chess pieces, apply a torque
This example shows rotating objects, in order to play with the torque application feature.
To apply a torque on the spinner, use the alt + mouse right click sequence.
[supervisor_draw_trail.wbt]({{ url.github_tree }}/projects/samples/howto/supervisor_draw_trail/worlds/supervisor_draw_trail.wbt)
Keywords: Supervisor, IndexedLineSet, draw trail
In this example, a Supervisor controller draws a green path behind a target node.
The target node is a Pose node mounted in the turretSlot of a moving e-puck robot.
At the beginning of the simulation, the Supervisor controller creates programmatically an IndexedLineSet node.
Then at each simulation step, it uses the target node position to update the IndexedLineSet node fields.
[texture_change.wbt]({{ url.github_tree }}/projects/samples/howto/texture_change/worlds/texture_change.wbt)
Keywords: Supervisor, texture, wb_supervisor_field_set_* functions, Camera
In this example, a robot moves forward and backward in front of a large textured panel.
The robot watches the panel with its Camera.
Meanwhile a Supervisor controller switches the image displayed on the panel.
Keywords: url, asset, download, Background, Camera, ContactProperties, ImageTexture, Mesh, Motor
This example shows how to specify textures, meshes and sounds using URLs instead of local files.
Nodes supporting asset download are the Background, Camera, ContactProperties, ImageTexture, Mesh and Motor.
The URL for the asset is defined in the world file using either the https:// or http:// protocol.
It can be changed from the graphical user interface in the scene tree and also from a supervisor process as demonstrated in this example.
If a texture is not found, it is replaced with a default image as shown on the picture.
Keywords: OpenCV, color filter
This example demonstrates the use of OpenCV to process the camera image.
The robot acquires images from a colored scene.
This controller requires OpenCV to be installed (not embedded in Webots), it should therefore be compiled with the OPENCV_DIR environment variable set.
The Camera image is given to OpenCV, OpenCV filters are applied on the image, and the result is displayed in a Display overlay.
[ziegler_nichols.wbt]({{ url.github_tree }}/projects/samples/howto/ziegler_nichols/worlds/ziegler_nichols.wbt)
Keywords: PID control, Ziegler-Nichols method, plot
This example shows the use of the wb_motor_set_pid function.
It adapts its PID parameters as specified by the Ziegler-Nichols tuning method.
Each P-controller is tested during a period of 400 time steps, i.e. 12.8 seconds.
A P-controller 'succeeds' if a constant error amplitude repeats at least 10 times during the test period.
Otherwise the proportional gain P is incremented by 10 and the experiment restarts.
The tuned Ziegler-Nichols "ultimate" gains will be computed for the first successful controller.
The result is plot in a Display overlay.