paparazzi-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Paparazzi-devel] Spektrum Receiver


From: Gareth Roberts
Subject: Re: [Paparazzi-devel] Spektrum Receiver
Date: Wed, 13 Jun 2012 17:24:48 +0100
User-agent: Opera Mail/11.64 (Linux)

Hi Tilman,

I suppose you added the V8R7-SP receiver to the list because it is compatible and has ppm?

Yes. I use TFR4-B's (FAAST compatible receiver with PPM output), with a Futaba T8FG transmitter.
But for the FAAST compat stuff, the TX is expensive.

Great to have a local source for that

Giantshark are pretty good. Most of our orders are here next-day and the prices are right.

Huh, thanks for digging this out.
But I'm not sure what it will mean. If you could perhaps help me make sense of it.

I tried it as I said in the last email and it didn't work...however, I figured out what I did! <channel ctl="D" function="ROLL" min="1000" neutral="2000" max="1500" average="0"/>

Yep, flip the neutral & max...I can't remember if I figured this out by accident or luck :)
I flew many aircraft like this and never had a problem (a few years ago).
I decided to look through the code because I was curious myself as to whether this hack was dangerous or not, and how it worked.

This is long, and probably not worth reading if you:
- Are one of the core developers, who know this already
- Just want to fly

This is from radio.h, which is in your var/your_plane/generated folder.
I'm using ROLL because it isn't averaged, so it simplifies the code a bit.
It's the same code for MODE, it just includes averaging.

This first case is when <channel ctl="D" function="ROLL" min="1000" neutral="1500" max="2000" average="0"/> and sets the scene.

------------- Normal Case (MANUAL/AUTO2) -------------
tmp_radio = _ppm[RADIO_ROLL] - RC_PPM_TICKS_OF_USEC(1500);\

So, assuming the switch is at 1000, this should be -500, at 2000, +500

_rc.values[RADIO_ROLL] = tmp_radio * (tmp_radio >=0 ? (MAX_PPRZ/(float)(RC_PPM_SIGNED_TICKS_OF_USEC(2000-1500))) : (MIN_PPRZ/(float)(RC_PPM_SIGNED_TICKS_OF_USEC(1000-1500))));

If the switch is off (1000) the ternary operation is false, so
_rc.values[RADIO_ROLL] = tmp_radio * (MIN_PPRZ/(float)(RC_PPM_SIGNED_TICKS_OF_USEC(1000-1500)))
which in our hypothetical situation is -500 * -9600/-500 = -9600
or if the switch is on (at 2000) = 9600

Now to the actual mode switching...

In paparazzi.h:

MAX_PPRZ = 9600
MIN_PPRZ = -9600

In autopilot.h:

#define TRESHOLD_MANUAL_PPRZ (MIN_PPRZ / 2)

#define TRESHOLD1 TRESHOLD_MANUAL_PPRZ
#define TRESHOLD2 (MAX_PPRZ/2)

So...

TRESHOLD_MANUAL_PPRZ = -4800
TRESHOLD1 = -4800
TRESHOLD2 = 4800

Now...

#define PPRZ_MODE_OF_PULSE(pprz) \
  (pprz > TRESHOLD2 ? PPRZ_MODE_AUTO2 : \
        (pprz > TRESHOLD1 ? PPRZ_MODE_AUTO1 : PPRZ_MODE_MANUAL))

When pprz = -9600
So pprz is indeed less than 4800, so we go into the second ternary.
pprz is also less than TRESHOLD1, so the mode is PPRZ_MODE_MANUAL.
When pprz = 9600, the first ternary is true so the mode is PPRZ_MODE_AUTO2
----------------------------------------------------------

Now, if we muck around with the range values so we have the following input line: <channel ctl="D" function="ROLL" min="1000" neutral="2000" max="1500" average="0"/>

------------- Hacky Case (MANUAL/AUTO1)-------------

tmp_radio = _ppm[RADIO_ROLL] - RC_PPM_TICKS_OF_USEC(2000);\

Switch off = 1000 - 2000 = -1000
Switch on = 2000 - 2000 = 0 <- 'magic' happens here

_rc.values[RADIO_ROLL] = tmp_radio * (tmp_radio >=0 ? (MAX_PPRZ/(float)(RC_PPM_SIGNED_TICKS_OF_USEC(1500-2000))) : (MIN_PPRZ/(float)(RC_PPM_SIGNED_TICKS_OF_USEC(1000-2000))));\

Switch off = -1000 * (-9600/-1000) = -9600
Switch on = 0 * (9600/-500) = 0

Back in the mode switch, pprz = 0 which is less than 4800 but greater than -4800, so the mode because PPRZ_MODE_AUTO1
----------------------------------------------------------

That was surprisingly fun...I've never looked at that bit of the code before. If you want to play along yourself, I can't recommend ack-grep enough.

Cheers,
Gareth



reply via email to

[Prev in Thread] Current Thread [Next in Thread]