Getting Started with Simulation


This tutorial will give you a first taste of controlling the Crazyflie in the Webots simulator by Cyberbotics.


All you need is the Webots simulator.

  1. Make sure that your computer meets the Webots system requirements.
  2. Then install the latest version of Webots on your computer by following Cyberbotics’ installation instructions.

Trying out the Crazyflie Model in Webots

Let’s dive right into it! This section explains how to open Webots, load the Crazyflie model, and fly it.

Open Webots and Find the Crazyflie Sample World

  1. Open Webots by typing ‘webots’ in a terminal in Ubuntu or by searching for the Webots installation in the search bar on Windows or Mac.
  2. Go to ‘File’ > ‘Open Sample World…’.
  3. In the dialog that appears, navigate to ‘robots’ > ‘bitcraze’ > ‘crazyflie’ > ‘crazyflie.wbt’.

Explore the Webots User Interface

The Webots window should now look like this:

crazyflie world

Here’s the purpose of each marked window:

  1. This is the ‘object’ tree, where you can add robots, obstacles, etc.
  2. This is the simulation window, where you can see the Crazyflie, its sensors, or camera output.
  3. This is the controller editor, showing the controller used by the Crazyflie.
  4. This is the simulation control panel, where you can start, stop, pause, and speed up the simulator.

For a more detailed description of the user interface, check out Webots’ ‘The User Interface’ user guide.

Fly the Crazyflie Using Your Keyboard

  1. In the simulation control panel (4), press play.
  2. The simulated Crazyflie’s propellers will start to rotate, and it will take off.
  3. Click on the simulation window (2) to ensure it is selected.
  4. Use the arrow keys (up, back, right, and left) to control the Crazyflie’s velocity in the body-fixed x, y direction.
  5. Use ‘Q’ and ‘E’ to control yaw rotation.
  6. Use ‘W’ and ‘S’ to control altitude (up and down).
  7. Now you can experiment and play with the Crazyflie’s controls!

You can examine the C code controlling the Crazyflie in the controller editor (3). If it’s not visible, find ‘Crazyflie “Crazyflie”’ in the object tree, click on ‘controller’, then click ‘edit’.

Note that you can’t currently modify this code yourself, but this will be explained later.

Try Out the Autonomy Example

Let’s explore another example!

crazyflie world
  1. Open another Crazyflie sample world following the same steps as above, but this time select ‘crazyflie_apartment.wbt’.
  2. You will now see the Crazyflie in an apartment example. There are also range sensors acting like the Multi-ranger deck . A virtual camera is attached, allowing you to see what the Crazyflie “sees”.
  3. Press play in the simulation control panel. The Crazyflie will take off.
  4. Control the Crazyflie with the keyboard as before.
  5. Position the Crazyflie facing a wall, then press ‘A’ on the keyboard. The Crazyflie will follow the wall.
  6. You can disable wall following by pressing ‘D’ on the keyboard. The Crazyflie will respond to manual arrow keys again.

Note that there might be an error when restarting the simulation, causing the Crazyflie to spawn in a different location. Use the simulation reload/refresh button () to fix this.

Edit the Controller

In the previous examples, you couldn’t modify the controller’s content due to restricted access. Now, we’ll show you how to save the project elsewhere, change the controller, or add an obstacle.

Save the Project in a Different Location

  1. In the ‘crazyflie_apartment.wbt’ from the previous example, refresh/reload the simulation if you’ve already started it.
  2. Access the controller editor. If it’s not visible, find ‘Crazyflie “Crazyflie”’ in the object tree, click on ‘controller’, then click ‘edit’.
  3. Modify the following lines as suggested:

     # OLD
     direction = WallFollowing.WallFollowingDirection.LEFT
     range_side_value = range_right_value
     # NEW
     direction = WallFollowing.WallFollowingDirection.RIGHT
     range_side_value = range_left_value
  4. Click the save icon. You may receive a notice that you’re not allowed to change the files. Select a folder in your working space where you have write access and click ‘copy’. You’ll now be allowed to make changes.
  5. Play the simulation, press ‘A’ to start autonomy mode. You’ll see the Crazyflie moving in the opposite direction.

Next Steps

You’ve now experienced the Webots simulator. You can continue modifying the controller or clone the ‘crazyflie-simulation’ repository:

git clone

You can try different examples from the source:

Note that the latter ‘wall following’ example from the source should directly link to files in the cflib examples. This allows you to try out the exact same state machine on a real Crazyflie with a Flow deck V2  and Multi-ranger deck .

Further Reading