Mapping keys to parameters

Firmware/software/electronics/mechanics
Post Reply
dbrgn
Member
Posts: 51
Joined: Tue Dec 16, 2014 9:42 pm

Mapping keys to parameters

Post by dbrgn »

Is there a way to map keys to arbitrary parameters?

E.g. I'd like to turn on the headlight or change the LED effect using my gamepad.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Mapping keys to parameters

Post by chad »

I'm not sure if there's an easy way to do this after the latest changes for CF2.0 but when I modded my CF1.0 with a NeoPixel LED ring, I added similar controller functionality myself... Maybe this will be of some help to you?
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Mapping keys to parameters

Post by marcus »

dbrgn wrote:Is there a way to map keys to arbitrary parameters?

E.g. I'd like to turn on the headlight or change the LED effect using my gamepad.
I have code for this, but it's based on the old pygame and not the pysdl2/linuxdev changes, so it needs some work before it's merged. I'll try to sit down tomorrow and merge it in.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Mapping keys to parameters

Post by chad »

marcus wrote:I have code for this, but it's based on the old pygame and not the pysdl2/linuxdev changes, so it needs some work before it's merged. I'll try to sit down tomorrow and merge it in.
Cool! I'll be happy to use this code too. Thanks Marcus!!
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Mapping keys to parameters

Post by marcus »

The code is merged now, it's on the branch dev-inputdev. To make a long story short we have been talking about refactoring the input layer for a while now, but never gotten around to it. So I thought that I might as well start the changes we talked about while merging in the old code. Everything is a bit messy and there's more changes than is required for what you wanted, but here's the explanation.

We have added two new buttons that can be mapped, alt1 and alt2. They can be configured in the input configuration dialog and then used in the application. They were put in to enable us to do all kinds of things, among them changing the LED-ring effect and turning off the headlights. When the state of the button is changed up->down or down->up a callback is called from the input layer that you can register to. Currently it's registered in the FlightTab to call two functions, one for alt1 and one for alt2. The function alt1_updated can be used to roll over all the LED-ring effects. When it's released the effect number is increased until you reach the number of effects, then it rolls back to zero. The function alt2_updated can be used to switch the LED-ring headlight on and off. Currently it's implemented to switch the light on while the alt2 buttons is pressed, and switch it off otherwise.

So to use the code just go to the Input Device -> Configure device mapping... dialog, start the configuration and map the Alt1/Alt2 buttons. Then use the callbacks in the FlightTab to implement whatever functionality you want when the buttons are pressed/released. Here's the current code:

Code: Select all

    def alt1_updated(self, state):
        if state:
            self._ring_effect += 1
            if self._ring_effect > self._ledring_nbr_effects:
                self._ring_effect = 0
            self.helper.cf.param.set_value("ring.effect", str(self._ring_effect))

    def alt2_updated(self, state):
        self.helper.cf.param.set_value("ring.headlightEnable", str(state))
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Mapping keys to parameters

Post by chad »

Cool. Thanks for the explanation and link to the branch!
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
Psichosix
Beginner
Posts: 7
Joined: Thu Jan 08, 2015 9:11 pm

Re: Mapping keys to parameters

Post by Psichosix »

I'd like to map this as well. However, I don't see a alt 1 or an alternative 2 button in my input screen.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Mapping keys to parameters

Post by chad »

Psichosix wrote:I'd like to map this as well. However, I don't see a alt 1 or an alternative 2 button in my input screen.
Are you using the dev-inputdev branch? The mappings are not on the master yet.

The alt buttons should be on the lower-right of the configure mappings window.
alt mappings
alt mappings
alt_buttons.png (20.47 KiB) Viewed 6499 times
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
Ziboul
Beginner
Posts: 8
Joined: Tue Nov 17, 2015 11:51 pm

Re: Mapping keys to parameters

Post by Ziboul »

Hello!
About post by Marcus 2014-12-27-8:32pm:
My problems
1/ everything like you say, Alt 1 mapped on Button 3 of a Xbox360 wireless. But pressing the button just turn off the ring, not shifting through different choices. My Python client is 2015-09. Firmware is the original latest one.
2/ The input configure device tab does not function. All places are greyed when I ask configure and load json file Xbox360...
Yours truly
Z.
Post Reply