zd880105132 / ardupilot-mega

Automatically exported from code.google.com/p/ardupilot-mega
0 stars 0 forks source link

Easy setup of FLIGHT_MODE switch positions vs pulsewidth #219

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

My radio does not support programming capabilities for a 6-position channel. 
One solution is to solder equal resistors between a multiposition switch to get 
some kind of linear potentiometer. The trick was then to find the pulsewidth 
for every position.

I wrote a slightly different readSwitch(void) code to simplify calculations of 
the position bounderies.  Some definitions in APM_conf.h help to keep the code 
untouched in the future.

****APM_conf.h****
// Define the pulsewidth when switch to next higher FLIGHT_MODE
#define FLIGHT_MODE_1_BOUNDARY  1125
#define FLIGHT_MODE_2_BOUNDARY  1335
#define FLIGHT_MODE_3_BOUNDARY  1550
#define FLIGHT_MODE_4_BOUNDARY  1690
#define FLIGHT_MODE_5_BOUNDARY  1880

****control_modes.pde****
byte readSwitch(void){
    int pulsewidth = APM_RC.InputCh(flight_mode_channel);
    if (pulsewidth > FLIGHT_MODE_5_BOUNDARY)    return 5;
    if (pulsewidth > FLIGHT_MODE_4_BOUNDARY)    return 4;
    if (pulsewidth > FLIGHT_MODE_3_BOUNDARY)    return 3;
    if (pulsewidth > FLIGHT_MODE_2_BOUNDARY)    return 2;
    if (pulsewidth > FLIGHT_MODE_1_BOUNDARY)    return 1;
    return 0;
}

regards
Uwe Gartmann

Original issue reported on code.google.com by flightro...@gmail.com on 1 Nov 2010 at 10:06

GoogleCodeExporter commented 8 years ago
APM_RC.InputCh(flight_mode_channel);

must be changed to 

APM_RC.InputCh(FLIGHT_MODE_CHANNEL - 1);

Original comment by flightro...@gmail.com on 1 Nov 2010 at 10:36

GoogleCodeExporter commented 8 years ago

Original comment by dewei...@gmail.com on 9 Nov 2010 at 2:57