Page 1 of 1

LED-Ring Deck Coding in Autonmous Script

Posted: Fri Apr 20, 2018 6:27 pm
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?

Re: LED-Ring Deck Coding in Autonmous Script

Posted: Tue Jan 29, 2019 5:16 am
by beemarie
Were you ever able to figure this out? I'm trying to do something similar!

Re: LED-Ring Deck Coding in Autonmous Script

Posted: Wed Jan 30, 2019 1:27 pm
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)

Re: LED-Ring Deck Coding in Autonmous Script

Posted: Fri Feb 15, 2019 4:52 am
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.