Technical Blog

Control the AR.Drone LEDs

The AR.Drone has four LEDs, one per rotor.

Currently, we can only use predefined animations (around 20), but maybe we will be able to use user-defined sequences in a future version of the SDK.

Which function to use?

We use the ardrone_at_set_led_animation function to control the LEDs. The prototype is defined in ARDroneLib/Soft/Common/ardrone_api.h:

void ardrone_at_set_led_animation (
    LED_ANIMATION_IDS anim_id,
    float32_t freq,
    uint32_t duration_sec);
  • anim_id: set to one of the animations defined by the SDK. It is detailed further down in this article.
  • freq: the frequency (hertz) of the animation, or the inverse of the period (seconds). For example, if it is set to 0.25, the period is 4: the animation will be completed in 4 seconds. The higher the value is, the faster is the animation.
  • duration_sec: the duration in seconds. If its value is superior to the time of execution of the animation, it will loop. If the value is set to 0, the animation will loop infinitely.

The different animations

The anim_id is one of the values defined in ARDroneLib/Soft/Common/led_animation.h. They are several kinds of animations:

Animation’s Name Display
BLINK_GREEN_RED
BLINK_GREEN
BLINK_RED
BLINK_ORANGE
SNAKE_GREEN_RED
FIRE
STANDARD
RED
GREEN
RED_SNAKE
BLANK
Animation’s Name Display
RIGHT_MISSILE
LEFT_MISSILE
DOUBLE_MISSILE
FRONT_LEFT_GREEN_OTHERS_RED
FRONT_RIGHT_GREEN_OTHERS_RED
REAR_RIGHT_GREEN_OTHERS_RED
REAR_LEFT_GREEN_OTHERS_RED
LEFT_GREEN_RIGHT_RED
LEFT_RED_RIGHT_GREEN
BLINK_STANDARD

Understanding the led_animation.h file

The file ARDroneLib/Soft/Common/led_animation.h contains the declaration of the different animations. It works like a kind of enum: each identifier refers to an ID that will be transmitted to the drone. Then, it will play the animation settings associated to this ID. Therefore, we can’t define our own sequences.
For example:

LED_ANIMATION(BLINK_STANDARD, {0,2,{{0x00,500},{0xA5,500}}})

The LED_ANIMATION macro is explained in the file:

LED_ANIMATION(#name, {#nb_cycle,#nb_state,{{#led_pattern1,#delay1},{#led_pattern2,#delay2},{...,...}}})
#name = name, example : BLINK
#nb_cycle = number of times the animation is played (0 means infinite), example : 3
#nb_state = number of led patterns in the animation, example : 2
#led_pattern = led bitfield (G1 | R1 | G2 | R2 | G3 | R3 | G4 | R4), example : 0xAA all green led turned on
#delay = delay in ms for the associated led pattern, example : 500

In our example, the animation’s ID is BLINK_STANDARD. It loops infinitely and contains two states: 0×00 during 0.5 seconds, and 0xA5 during 0.5 seconds.
0xA5 is hexadecimal code. Its binary form is: 1010 0101. It is mapped this way:

1 0 1 0 0 1 0 1
G1 R1 G2 R2 G3 R3 G4 R4

Therefore, we can see that:

  • LEDs 1 and 2 are green
  • LEDs 3 and 4 are red

The results will be this:

The same way, in the following state, 0×00, all the lights are turned off.

To use this animation, we use the following code:

ardrone_at_set_led_animation(BLINK_STANDARD, 0.25, 6);

In this example, all the LEDs will switch between the two states every two seconds (period of 4 seconds) during 6 seconds.

Appendix: list of the animations

The list can be found in the following file: ARDroneLib/Soft/Common/led_animation.h

LED_ANIMATION(BLINK_GREEN_RED,               { 0,2, { {0x55,500},{0xAA,500} } } )
LED_ANIMATION(BLINK_GREEN,                   { 0,2, { {0x00,500},{0xAA,500} } } )
LED_ANIMATION(BLINK_RED,                     { 0,2, { {0x55,500},{0x00,500} } } )
LED_ANIMATION(BLINK_ORANGE,                  { 0,2, { {0xFF,500},{0x00,500} } } )
LED_ANIMATION(SNAKE_GREEN_RED,               { 0,8, { {0x90,200},{0x48,200},{0x24,200},{0x12,200},{0x9,200},{0x84,200},{0x42,200},{0x21,200}}})
LED_ANIMATION(FIRE,                          { 0,2, { {0x35,50},{0xC5,50} } } )
LED_ANIMATION(STANDARD,                      { 1,1, { {0xA5,100} } } )
LED_ANIMATION(RED,                           { 1,1, { {0x55,100} } } )
LED_ANIMATION(GREEN,                         { 1,1, { {0xAA,100} } } )
LED_ANIMATION(RED_SNAKE,                     { 0,4, { {0x40,500},{0x10,500},{0x04,500},{0x01,500}}})
LED_ANIMATION(BLANK,                         { 1,1, { {0x00,100} } } )
LED_ANIMATION(RIGHT_MISSILE,                 { 1,5, { {0x00,500},{0x04,300},{0x1C,100},{0x30,300},{0x00,500}}})
LED_ANIMATION(LEFT_MISSILE,                  { 1,5, { {0x00,500},{0x01,300},{0x43,100},{0xC0,300},{0x00,500}}})
LED_ANIMATION(DOUBLE_MISSILE,                { 1,5, { {0x00,500},{0x05,300},{0x5F,100},{0xF0,300},{0x00,500}}})
LED_ANIMATION(FRONT_LEFT_GREEN_OTHERS_RED,   { 1,1, { {0x95,100} } } )
LED_ANIMATION(FRONT_RIGHT_GREEN_OTHERS_RED,  { 1,1, { {0x65,100} } } )
LED_ANIMATION(REAR_RIGHT_GREEN_OTHERS_RED,   { 1,1, { {0x59,100} } } )
LED_ANIMATION(REAR_LEFT_GREEN_OTHERS_RED,    { 1,1, { {0x56,100} } } )
LED_ANIMATION(LEFT_GREEN_RIGHT_RED,          { 1,1, { {0x96,100} } } )
LED_ANIMATION(LEFT_RED_RIGHT_GREEN,          { 1,1, { {0x69,100} } } )
LED_ANIMATION(BLINK_STANDARD,                { 0,2, { {0x00,500},{0xA5,500} } } )

  • http://blog.vjeux.com/ Vjeux

    Nice use of RaphaelJS for the animations. It’s really sexy!

  • Tyler

    Hello, first of all thank you for making this great tutorial series! It is extremely helpful.

    Now I can display Image and do OpenCV computing based on the stream.

    I wonder how can I control the ar drone flying forward backward based on the computing of OpenCV. Could you please point me to some file or function?

    Thank you so much

  • Anonymous

    Hey Tyler, you can look at ardrone_at_set_progress_cmd or ardrone_tool_set_progressive_cmd