|
| 1 | +# ,---------, ____ _ __ |
| 2 | +# | ,-^-, | / __ )(_) /_______________ _____ ___ |
| 3 | +# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \ |
| 4 | +# | / ,--' | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ |
| 5 | +# +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/ |
| 6 | +# |
| 7 | +# Copyright (C) 2026 Bitcraze AB |
| 8 | +# |
| 9 | +# This program is free software: you can redistribute it and/or modify |
| 10 | +# it under the terms of the GNU General Public License as published by |
| 11 | +# the Free Software Foundation, either version 3 of the License, or |
| 12 | +# (at your option) any later version. |
| 13 | +# |
| 14 | +# This program is distributed in the hope that it will be useful, |
| 15 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +# GNU General Public License for more details. |
| 18 | +# |
| 19 | +# You should have received a copy of the GNU General Public License |
| 20 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +""" |
| 22 | +Simple example that connects to the crazyflie at `URI` and writes to |
| 23 | +the LED memory so that individual leds in the LED-ring can be set, |
| 24 | +it has been tested with (and designed for) the LED-ring deck. |
| 25 | +
|
| 26 | +Change the URI variable to your Crazyflie configuration. |
| 27 | +""" |
| 28 | + |
| 29 | +import asyncio |
| 30 | +from dataclasses import dataclass |
| 31 | + |
| 32 | +import tyro |
| 33 | + |
| 34 | +from cflib2 import Crazyflie, LedRingColor, LinkContext |
| 35 | + |
| 36 | + |
| 37 | +@dataclass |
| 38 | +class Args: |
| 39 | + uri: str = "radio://0/80/2M/E7E7E7E7E7" |
| 40 | + """Crazyflie URI""" |
| 41 | + |
| 42 | + |
| 43 | +async def main() -> None: |
| 44 | + args = tyro.cli(Args) |
| 45 | + |
| 46 | + print(f"Connecting to {args.uri}...") |
| 47 | + ctx = LinkContext() |
| 48 | + cf = await Crazyflie.connect_from_uri(ctx, args.uri) |
| 49 | + print("Connected!") |
| 50 | + |
| 51 | + try: |
| 52 | + # Set virtual mem effect |
| 53 | + await cf.param().set("ring.effect", 13) |
| 54 | + |
| 55 | + # Build LED list and set individual LEDs |
| 56 | + leds = [LedRingColor() for _ in range(12)] |
| 57 | + leds[0].set(r=0, g=100, b=0) |
| 58 | + leds[3].set(r=0, g=0, b=100) |
| 59 | + leds[6].set(r=100, g=0, b=0) |
| 60 | + leds[9].set(r=100, g=100, b=100) |
| 61 | + await cf.memory().write_led_ring(leds) |
| 62 | + |
| 63 | + await asyncio.sleep(2) |
| 64 | + |
| 65 | + finally: |
| 66 | + print("Disconnecting...") |
| 67 | + await cf.disconnect() |
| 68 | + print("Done!") |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + asyncio.run(main()) |
0 commit comments