phenolic is correct tthat the mapping is reversed.
so lets say you defined SERIAL_SUM_PPM as YAW, PITCH, THROTTLE, ROLL (we'll just do the first 4 for simplicity)
as your channel order. and rcChannel array is initialized as follows
rcChannel[0] = 2 //YAW is 2
rcChannel[1] = 1 //PITCH is 1
rcChannel[2] = 3 // THROTTLE is 3
rcChannel[3] = 0 //ROLL is 0
so interrupt service handler will assign values to
rcValue[0] ->yaw value
rcValue[1]-> pitch value
rcValue[2]=>throttle value
rcValue[3]->roll value
so to get the rcData for THROTTLE channel, we actually need rcValue[2]
RX.ino code to get throttle value is
Code: Select all
uint16_t readRawRC(uint8_t chan) {
uint16_t data;
#if defined(SPEKTRUM)
readSpektrum();
if (chan < RC_CHANS) {
data = rcValue[rcChannel[chan]];
} else data = 1500;
#else
uint8_t oldSREG;
oldSREG = SREG; cli(); // Let's disable interrupts
data = rcValue[rcChannel[chan]]; // Let's copy the data Atomically
SREG = oldSREG; // Let's restore interrupt state
#endif
return data; // We return the value correctly copied when the IRQ's where disabled
}
for which if you request data for THROTTLE channel, it will return
rcValue[rcChannel[3]]
which evaluates to rcValue[0]
which is the value for ppm channel 0, and is the value for yaw.
so you can see that you requested data for throttle but got YAW instead.
proof the multiwii code is incorrect.
The fix is actually quite simple. change this
Code: Select all
data = rcValue[rcChannel[chan]]; // Let's copy the data Atomically
to this
Code: Select all
data = rcValue[rcChannel[rcChannel[chan]]]; // Let's copy the data Atomically
so in the throttle example, the result will now be
rcValue[rcChannel[rcChannel[3]]]
since rcChannel[3] is 0, which is ROLL then
rcValue[rcChannel[0]]
and rcChannel[0] is 2, which is YAW
so we now get the correct value
rcValue[2]
which is the 3rd ppm channel as defined in SERIAL_SUM_PPM
and is the correct value for throttle
Someone should make this fix in RX.ino, and give the proper warning to define SERIAL_SUM_PPM to the actual RX channel order instead of the current trial and error method to get the right combination.