LED-Ring Deck Coding in Autonmous Script

Post here to get support
Post Reply
emrefisher
Beginner
Posts: 5
Joined: Wed Apr 11, 2018 6:15 pm

LED-Ring Deck Coding in Autonmous Script

Post by emrefisher »

I am trying to integrate control of the LED-ring in the example code Autonomous Sequence and am not sure of the syntax to call upon it. Could anyone provide an example of the code I would have to include to have control of the RGB or the ring effects that are available in the client?
beemarie
Beginner
Posts: 3
Joined: Thu Jan 24, 2019 5:39 pm

Re: LED-Ring Deck Coding in Autonmous Script

Post by beemarie »

Were you ever able to figure this out? I'm trying to do something similar!
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: LED-Ring Deck Coding in Autonmous Script

Post by tobias »

We should have written an example of this a long time ago, shame on us :oops:, but so many things to do...

The short answer to this is that there are two ways. Either use the LED-ring parameters which you set with the parameter framework, or use the memory framework.

LED-ring parameters example using SyncCrazyflie

Code: Select all

"""
Simple example that connects to the crazyflie at `URI` and writes to
parameters that control the LED-ring, 
it has been tested with (and designed for) the LED-ring deck.

Change the URI variable to your Crazyflie configuration.
"""
import logging
import time

import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie

URI = 'radio://0/80/250K'

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)


if __name__ == '__main__':
    # Initialize the low-level drivers (don't list the debug drivers)
    cflib.crtp.init_drivers(enable_debug_driver=False)

    with SyncCrazyflie(URI) as scf:
        cf = scf.cf

        # Set solid color effect
        cf.param.set_value('ring.effect', '7')
        # Set the RGB values
        cf.param.set_value('ring.solidRed', '100')
        cf.param.set_value('ring.solidGreen', '0')
        cf.param.set_value('ring.solidBlue', '0')
        time.sleep(2)

        # Set black color effect
        cf.param.set_value('ring.effect', '0')
        time.sleep(1)

        # Set fade to color effect
        cf.param.set_value('ring.effect', '14')
        # Set fade time i seconds
        cf.param.set_value('ring.fadeTime', '1.0')
        # Set the RGB values in one uint32 0xRRGGBB
        cf.param.set_value('ring.fadeColor', '0x0000A0')
        time.sleep(1)
        cf.param.set_value('ring.fadeColor', '0x00A000')
        time.sleep(1)
        cf.param.set_value('ring.fadeColor', '0xA00000')
        time.sleep(1)
LED mem example using SyncCrazyflie

Code: Select all

"""
Simple example that connects to the crazyflie at `URI` and writes to
the LED memory so that individual leds in the LED-ring can be set, 
it has been tested with (and designed for) the LED-ring deck.

Change the URI variable to your Crazyflie configuration.
"""
import logging
import time

import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.crazyflie.mem import MemoryElement

URI = 'radio://0/80/250K'

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)


if __name__ == '__main__':
    # Initialize the low-level drivers (don't list the debug drivers)
    cflib.crtp.init_drivers(enable_debug_driver=False)

    with SyncCrazyflie(URI, cf=Crazyflie(rw_cache='./cache')) as scf:
        cf = scf.cf

        # Set virtual mem effect
        cf.param.set_value('ring.effect', '13')
        
        # Get LED memory and write to it
        mem = cf.mem.get_mems(MemoryElement.TYPE_DRIVER_LED)
        if len(mem) > 0:
            mem[0].leds[0].set(r=0,   g=100, b=0)
            mem[0].leds[3].set(r=0,   g=0,   b=100)
            mem[0].leds[6].set(r=100, g=0,   b=0)
            mem[0].leds[9].set(r=100, g=100, b=100)
            mem[0].write_data(None)

        time.sleep(2)
Yoyasp
Beginner
Posts: 19
Joined: Mon Jan 14, 2019 2:41 am

Re: LED-Ring Deck Coding in Autonmous Script

Post by Yoyasp »

Can you eleborate on the perfomance of both options?

Im trying to get a swarm to change colors at the same time. Currently im using the parameter framework, but when changing colors you can see the different color channels change brightness very briefly. Im wondering if changing the memory directly is faster or still requires 3 packets to be send.
Post Reply