I am trying to understand the __calculation__ being performed in some existing code written to read accelerations from an ADXL345 accelerometer board so that I can write some AVR code using a different accelerometer.

The calculation is in this code:

rxVal[CHANNEL_ROLL] = input pulse width in micro seconds from transmitter.

CHANNEL_ROLL = 1 // Index to channel

ROLL_RX_MULT = ROLL_A_MAX/400 = 20/400 //ROLL_A_MAX = 20, max roll angle set point in degrees

ROLL_RX_SUB =1500 * ROLL_RX_MULT

if(updateFlags & 1<<CHANNEL_ROLL){ // New roll

rxRoll = (float)rxVal[CHANNEL_ROLL]*ROLL_RX_MULT - ROLL_RX_SUB; //THIS IS THE LINE THAT I NEED SOME HELP WITH, APPARENTLY CALCULATING DEGREES

rxRoll = constrain(rxRoll, -ROLL_A_MAX, ROLL_A_MAX); //insure that it is within limits

}

I understand the code itself BUT can anyone help in explaining the __calculation__ being performed here? The input is the pulse width of the transmitter and I am guessing it is some sort of a conversion but what is going on here? What do the '400' and '1500' represent?

Many thanks to anyone who understands this calculation when done with the ADXL345.