Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2109 → Rev 2110

/branches/dongfang_FC_fixedwing/analog.c
429,7 → 429,7
 
airpressureOffset = (offsets[3] + OFFSET_CYCLES / 2) / OFFSET_CYCLES;
int16_t min = 200;
int16_t max = (1024-200) * 2;
int16_t max = 1024-200;
if(airpressureOffset < min || airpressureOffset > max)
versionInfo.hardwareErrors[0] |= FC_ERROR0_PRESSURE;
 
/branches/dongfang_FC_fixedwing/arduino_atmega328/README.txt
5,7 → 5,8
 
PB0/ICP1 PPM receiver signal in
PB1,2 Digital outputs (output.c)
PB3,4,5 Left free for SPI use
PB3,4 Left free for SPI use
PB5 Green Arduino LED (use as LED2).
PB6,7 Xtal
 
PC0,1,2,3 unused
20,8 → 21,8
PD3/OC2B: CLK of 4017 change B3
PD4: RESET of 4017
PD5 Beeper
PD6,7 LEDs
PD6 Red LED
PD7 unusd
 
 
ADC6 Battery voltage divider
ADC7 Airspeed sensor
/branches/dongfang_FC_fixedwing/arduino_atmega328/commands.h
2,6 → 2,7
#define _COMMANDS_H
 
#include <inttypes.h>
 
#define COMMAND_NONE 0
#define COMMAND_GYROCAL 1
#define COMMAND_CHMOD 2
/branches/dongfang_FC_fixedwing/arduino_atmega328/controlMixer.c
54,7 → 54,7
int16_t targetvalue;
for (i=0; i < VARIABLE_COUNT; i++) {
targetvalue = RC_getVariable(i);
if (i<2) debugOut.analog[18+i] = targetvalue;
// if (i<2) debugOut.analog[18+i] = targetvalue;
if (targetvalue < 0)
targetvalue = 0;
if (variables[i] < targetvalue && variables[i] < 255)
/branches/dongfang_FC_fixedwing/arduino_atmega328/main.c
114,7 → 114,7
} else {
debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER;
}
J4HIGH;
PD2HIGH;
// This is probably the correct order:
// The attitude computation should not depend on anything from control (except maybe the estimation of control activity level)
// The control may depend on attitude - for example, attitude control uses pitch and roll angles, compass control uses yaw angle etc.
123,7 → 123,7
controlMixer_periodicTask();
commands_handleCommands();
flight_control();
J4LOW;
PD2LOW;
 
// Allow Serial Data Transmit if motors must not updated or motors are not running
if (!runFlightControl || !isFlying) {
/branches/dongfang_FC_fixedwing/arduino_atmega328/output.h
3,18 → 3,10
 
#include <avr/io.h>
 
#define J3HIGH PORTD |= (1<<PORTD5)
#define J3LOW PORTD &= ~(1<<PORTD5)
#define J3TOGGLE PORTD ^= (1<<PORTD5)
#define PD2HIGH PORTD |= (1<<PORTD2)
#define PD2LOW PORTD &= ~(1<<PORTD2)
#define PD2TOGGLE PORTD ^= (1<<PORTD2)
 
#define J4HIGH PORTD |= (1<<PORTD2)
#define J4LOW PORTD &= ~(1<<PORTD2)
#define J4TOGGLE PORTD ^= (1<<PORTD2)
 
#define J5HIGH PORTD |= (1<<PORTD3)
#define J5LOW PORTD &= ~(1<<PORTD3)
#define J5TOGGLE PORTD ^= (1<<PORTD3)
 
// invert means: An "1" bit in digital debug data make a LOW on the output.
#define DIGITAL_DEBUG_INVERT 0
 
/branches/dongfang_FC_fixedwing/arduino_atmega328/rc.c
92,7 → 92,6
 
//sync gap? (3.5 ms < signal < 25.6 ms)
if (signal > TIME(3.5)) {
// never happens...
index = 0;
} else { // within the PPM frame
if (index < MAX_CHANNELS) { // PPM24 supports 12 channels
/branches/dongfang_FC_fixedwing/arduino_atmega328/rc.h
29,14 → 29,6
// Set this for a full stick range of about -1024..1024.
#define RC_SCALING 1
 
/*
int16_t RC_getPitch (void);
int16_t RC_getYaw (void);
int16_t RC_getRoll (void);
uint16_t RC_getThrottle (void);
uint8_t RC_hasNewRCData (void);
*/
 
// void RC_periodicTask(void);
void RC_periodicTaskAndPRYT(int16_t* PRYT);
uint8_t RC_getArgument(void);
/branches/dongfang_FC_fixedwing/attitude.c
59,7 → 59,7
*/
 
void setStaticAttitudeAngles(void) {
attitude[PITCH] = attitude[ROLL] = 0;
attitude[PITCH] = attitude[ROLL] = attitude[YAW] = 0;
}
 
/************************************************************************
/branches/dongfang_FC_fixedwing/main.c
34,7 → 34,7
 
// This is strange: It should NOT be necessarty to do. But the call of the same,
// in channelMap_readOrDefault (if eeprom read fails) just sets all to 0,0,0,....
channelMap_default();
channelMap_default();
 
// initalize modules
output_init();
76,8 → 76,8
;
 
timer = setDelay(200);
outputSet(0,0);
outputSet(1,1);
outputSet(0, 0);
outputSet(1, 1);
RED_OFF;
GRN_ON;
while (!checkDelay(timer))
119,7 → 119,7
debugOut.digital[0] |= DEBUG_MAINLOOP_TIMER;
} else {
debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER;
 
}
J4HIGH;
// This is probably the correct order:
// The attitude computation should not depend on anything from control (except maybe the estimation of control activity level)
171,7 → 171,6
} else {
debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER;
}
}
}
return (1);
}
/branches/dongfang_FC_fixedwing/rc.c
15,6 → 15,7
uint8_t lastRCCommand = COMMAND_NONE;
uint8_t lastFlightMode = FLIGHT_MODE_NONE;
 
#define TIME(s) ((int16_t)(((long)F_CPU/(long)8000)*(float)s))
/***************************************************************
* 16bit timer 1 is used to decode the PPM-Signal
***************************************************************/
103,17 → 104,17
oldICR1 = ICR1;
 
//sync gap? (3.5 ms < signal < 25.6 ms)
if (signal > 8750) {
if (signal > TIME(3.5)) {
index = 0;
} else { // within the PPM frame
if (index < MAX_CHANNELS) { // PPM24 supports 12 channels
// check for valid signal length (0.8 ms < signal < 2.2 ms)
if ((signal >= 2000) && (signal < 5500)) {
if ((signal >= TIME(0.8)) && (signal < TIME(2.2))) {
// shift signal to zero symmetric range -154 to 159
//signal -= 3750; // theoretical value
signal -= (3750+56); // best value with my Futaba in zero trim.
signal -= (TIME(1.5) + RC_TRIM); // best value with my Futaba in zero trim.
// check for stable signal
if (abs(signal - PPM_in[index]) < 50) {
if (abs(signal - PPM_in[index]) < TIME(0.05)) {
if (RCQuality < 200)
RCQuality += 10;
else
149,11 → 150,9
#define COMMAND_CHANNEL_VERTICAL CH_THROTTLE
#define COMMAND_CHANNEL_HORIZONTAL CH_YAW
 
#define RC_SCALING 2
 
uint8_t getControlModeSwitch(void) {
int16_t channel = RCChannel(CH_MODESWITCH);
uint8_t flightMode = channel < -330 ? FLIGHT_MODE_MANUAL : (channel > 330 ? FLIGHT_MODE_ANGLES : FLIGHT_MODE_RATE);
uint8_t flightMode = channel < -TIME(0.17) ? FLIGHT_MODE_MANUAL : (channel > TIME(0.17) ? FLIGHT_MODE_ANGLES : FLIGHT_MODE_RATE);
return flightMode;
}
 
173,7 → 172,7
 
int16_t channel = RCChannel(CH_THROTTLE);
 
if (channel <= -1400) {
if (channel <= -TIME(0.55)) {
lastRCCommand = COMMAND_GYROCAL;
} else {
lastRCCommand = COMMAND_NONE;
210,12 → 209,12
int16_t RC_getVariable(uint8_t varNum) {
if (varNum < 4)
// 0th variable is 5th channel (1-based) etc.
return (RCChannel(varNum + CH_POTS) >> 3) + POT_OFFSET;
return (RCChannel(varNum + CH_POTS) >> 3) + VARIABLE_OFFSET;
/*
* Let's just say:
* The RC variable i is hardwired to channel i, i>=4
*/
return (PPM_in[varNum] >> 3) + POT_OFFSET;
return (PPM_in[varNum] >> 3) + VARIABLE_OFFSET;
}
 
uint8_t RC_getSignalQuality(void) {
/branches/dongfang_FC_fixedwing/rc.h
21,15 → 21,13
#define CH_RUDDER 3
#define CH_MODESWITCH 4
#define CH_POTS 4
#define POT_OFFSET 128
 
/*
int16_t RC_getPitch (void);
int16_t RC_getYaw (void);
int16_t RC_getRoll (void);
uint16_t RC_getThrottle (void);
uint8_t RC_hasNewRCData (void);
*/
// These are a little individual for differnt R/C systems... trim for zero channel readings at zero
// stick, and trim VARIABLE_OFFSET for full variable range 0..255.
#define VARIABLE_OFFSET 128
#define RC_TRIM 23
// Set this for a full stick range of about -1024..1024.
#define RC_SCALING 2
 
// void RC_periodicTask(void);
void RC_periodicTaskAndPRYT(int16_t* PRYT);