/branches/V0.76g-acid/T-Rex_450.mkm |
---|
0,0 → 1,55 |
[Info] |
Name=T-Rex 450 |
Version=1 |
[Gas] |
Motor1=1 |
Motor2=20 |
Motor3=113 |
Motor4=1 |
Motor5=4 |
Motor6=4 |
Motor7=4 |
Motor8=4 |
Motor9=0 |
Motor10=0 |
Motor11=0 |
Motor12=0 |
[Nick] |
Motor1=16 |
Motor2=-5 |
Motor3=0 |
Motor4=70 |
Motor5=50 |
Motor6=0 |
Motor7=0 |
Motor8=0 |
Motor9=0 |
Motor10=0 |
Motor11=0 |
Motor12=0 |
[Roll] |
Motor1=8 |
Motor2=0 |
Motor3=0 |
Motor4=0 |
Motor5=12 |
Motor6=0 |
Motor7=0 |
Motor8=0 |
Motor9=0 |
Motor10=0 |
Motor11=0 |
Motor12=0 |
[Yaw] |
Motor1=45 |
Motor2=0 |
Motor3=0 |
Motor4=0 |
Motor5=0 |
Motor6=0 |
Motor7=0 |
Motor8=0 |
Motor9=0 |
Motor10=0 |
Motor11=0 |
Motor12=0 |
/branches/V0.76g-acid/fc.c |
---|
80,7 → 80,6 |
volatile long Mess_Integral_Hoch = 0; |
int KompassValue = 0; |
int KompassStartwert = 0; |
int KompassEinschaltStartwert = 0; |
int KompassRichtung = 0; |
unsigned int KompassSignalSchlecht = 500; |
unsigned char MAX_GAS,MIN_GAS; |
163,7 → 162,14 |
#define LIMIT_MIN(value, min) {if(value < min) value = min;} |
#define LIMIT_MAX(value, max) {if(value > max) value = max;} |
#define LIMIT_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;} |
uint8_t servoValues[6] = { 127, 127, 127, 127, 127 , 127 }; |
uint8_t MakeByte(int16_t i) { |
if (i < 0) return 0; |
if (i > 255) return 255; |
return i; |
} |
int MotorSmoothing(int neu, int alt) |
{ |
int motor; |
251,7 → 257,6 |
VarioMeter = 0; |
Mess_Integral_Hoch = 0; |
KompassStartwert = KompassValue; |
KompassEinschaltStartwert = KompassValue; |
GPS_Neutral(); |
beeptime = 50; |
Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
473,21 → 478,10 |
{ |
unsigned char i; |
if(!MotorenEin) |
{ |
MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY); |
for(i=0;i<MAX_MOTORS;i++) |
{ |
if(!PC_MotortestActive) MotorTest[i] = 0; |
Motor[i] = MotorTest[i]; |
} |
if(PC_MotortestActive) PC_MotortestActive--; |
} |
else MikroKopterFlags |= FLAG_MOTOR_RUN; |
else |
MikroKopterFlags |= FLAG_MOTOR_RUN; |
DebugOut.Analog[12] = Motor[0]; |
DebugOut.Analog[13] = Motor[1]; |
DebugOut.Analog[14] = Motor[3]; |
DebugOut.Analog[15] = Motor[2]; |
//Start I2C Interrupt Mode |
twi_state = 0; |
540,7 → 534,6 |
MIN_GAS = EE_Parameter.Gas_Min; |
} |
//############################################################################ |
// |
void MotorRegler(void) |
599,6 → 592,7 |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
if(SenderOkay > 140) |
{ |
MikroKopterFlags &= ~FLAG_NOTLANDUNG; |
RcLostTimer = EE_Parameter.NotGasZeit * 50; |
if(GasMischanteil > 40 && MotorenEin) |
697,6 → 691,7 |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
if(++delay_einschalten > 200) |
{ |
beeptime = 1000; |
delay_einschalten = 200; |
modell_fliegt = 1; |
MotorenEin = 1; |
710,7 → 705,6 |
SummeNick = 0; |
SummeRoll = 0; |
MikroKopterFlags |= FLAG_START; |
KompassEinschaltStartwert = KompassValue; |
} |
} |
else delay_einschalten = 0; |
722,6 → 716,7 |
{ |
if(++delay_ausschalten > 200) // nicht sofort |
{ |
beeptime = 1000; |
MotorenEin = 0; |
delay_ausschalten = 200; |
modell_fliegt = 0; |
737,77 → 732,13 |
if(!NewPpmData-- || (MikroKopterFlags & FLAG_NOTLANDUNG)) |
{ |
static int stick_nick,stick_roll; |
int e_stick_nick, e_stick_nick_diff, e_stick_roll, e_stick_roll_diff; |
int stick_p, stick_d; |
ParameterZuordnung(); |
stick_p = EE_Parameter.Stick_P; |
stick_d = EE_Parameter.Stick_D; |
if (Parameter_UserParam8) { |
int angle, stick_nick_tmp, stick_roll_tmp; |
if (Parameter_UserParam8 == 254) { |
angle = -45; |
} else if (Parameter_UserParam8 > 128) { |
angle = KompassValue; |
} else { |
angle = (ErsatzKompass / GIER_GRAD_FAKTOR); |
} |
angle = ((KompassEinschaltStartwert - angle + 360) % 360); |
stick_nick_tmp = (long)c_cos_8192(angle) * (long)PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] / 8192L; |
stick_roll_tmp = (long)c_sin_8192(angle) * (long)PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] / 8192L; |
e_stick_nick = stick_roll_tmp + stick_nick_tmp; |
e_stick_roll = stick_roll_tmp - stick_nick_tmp; |
stick_nick_tmp = (long)c_cos_8192(angle) * (long)PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] / 8192L; |
stick_roll_tmp = (long)c_sin_8192(angle) * (long)PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] / 8192L; |
e_stick_nick_diff = stick_roll_tmp + stick_nick_tmp; |
e_stick_roll_diff = stick_roll_tmp - stick_nick_tmp; |
if (Parameter_UserParam8 == 255) { |
int gier = abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]); |
if (gier > 100) { |
stick_d /= 3; |
} else if (gier > 50) { |
stick_d /= 2; |
} |
if (stick_d < 1) { |
stick_d = 1; |
} |
} |
/* |
DebugOut.Analog[12] = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; |
DebugOut.Analog[13] = e_stick_nick; |
DebugOut.Analog[14] = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; |
DebugOut.Analog[15] = e_stick_roll; |
*/ |
} else { |
e_stick_nick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; |
e_stick_roll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; |
e_stick_nick_diff = PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]]; |
e_stick_roll_diff = PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]]; |
} |
stick_nick = (stick_nick * 3 + e_stick_nick * stick_p) / 4; |
stick_nick += e_stick_nick_diff * stick_d; |
stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
StickNick = stick_nick - (GPS_Nick + GPS_Nick2); |
stick_roll = (stick_roll * 3 + e_stick_roll * stick_p) / 4; |
stick_roll += e_stick_roll_diff * stick_d; |
stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
StickRoll = stick_roll - (GPS_Roll + GPS_Roll2); |
StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
1233,7 → 1164,7 |
DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
DebugOut.Analog[4] = MesswertGier; |
DebugOut.Analog[5] = HoehenWert/5; |
DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az; |
//DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az; |
DebugOut.Analog[8] = KompassValue; |
DebugOut.Analog[9] = UBat; |
DebugOut.Analog[10] = SenderOkay; |
1594,7 → 1525,7 |
modell_fliegt = 1; |
GasMischanteil = MIN_GAS; |
} |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
/*// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Mischer und PI-Regler |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
DebugOut.Analog[7] = GasMischanteil; |
1642,31 → 1573,69 |
pd_ergebnis_roll = DiffRoll + SummeRoll / Ki; // PI-Regler für Roll |
tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;*/ |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// Universal Mixer |
// Servo Mixer |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
for(i=0; i<MAX_MOTORS; i++) |
{ |
signed int tmp_int; |
if(Mixer.Motor[i][0] > 0) |
{ |
tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]); // Filter |
tmp_int = tmp_motorwert[i] / STICK_GAIN; |
CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS); |
Motor[i] = tmp_int; |
} |
else Motor[i] = 0; |
} |
/* |
if(Poti1 > 20) Motor1 = 0; |
if(Poti1 > 90) Motor6 = 0; |
if(Poti1 > 140) Motor2 = 0; |
//if(Poti1 > 200) Motor7 = 0; |
*/ |
{ |
int16_t nick, roll, tmp, pitch, throttle; |
int16_t servo[6]; |
// throttle |
if (MotorenEin == 0 || MikroKopterFlags & FLAG_NOTLANDUNG) { |
tmp = 0; |
} else { |
throttle = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + Mixer.Motor[2][0]; |
if (throttle < 0) throttle = 0; |
tmp = throttle / Mixer.Motor[3][0]; |
if (tmp > Mixer.Motor[3][1] * 2) tmp = Mixer.Motor[3][1] * 2; |
} |
servo[4] = tmp; |
// pitch |
pitch = throttle / Mixer.Motor[4][0] + Mixer.Motor[4][2]; |
if (pitch > Mixer.Motor[4][1]) pitch = Mixer.Motor[4][1]; |
servo[0] = -pitch; |
servo[1] = pitch; |
servo[2] = pitch; |
nick = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
roll = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
// nick |
nick /= Mixer.Motor[0][1]; |
nick -= PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] / Mixer.Motor[5][0]; |
servo[0] += 127 + Mixer.Motor[0][0] - nick; |
servo[1] += 127 + Mixer.Motor[0][0] + nick; |
servo[2] += 127 + Mixer.Motor[0][0] - nick; |
// roll |
roll /= Mixer.Motor[0][2]; |
roll -= PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] / Mixer.Motor[6][0]; |
servo[0] += roll; |
servo[1] += roll; |
// gier |
tmp = MesswertGier / Mixer.Motor[0][3]; |
servo[3] = 127 + Mixer.Motor[1][1] + tmp + (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] / Mixer.Motor[7][0]); |
// not used |
servo[5] = 127; |
for(tmp = 0; tmp < 6; tmp++) { |
servoValues[tmp] = MakeByte(servo[tmp]); |
} |
DebugOut.Analog[12] = servo[0]; |
DebugOut.Analog[13] = servo[1]; |
DebugOut.Analog[14] = servo[2]; |
DebugOut.Analog[15] = servo[3]; |
DebugOut.Analog[6] = pitch; |
DebugOut.Analog[7] = servo[4]; |
} |
} |
/branches/V0.76g-acid/main.c |
---|
129,20 → 129,20 |
if(UBat < 130) |
{ |
BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
if(print) |
if(print) |
{ |
Piep(3,200); |
printf(" 3 Cells "); |
} |
} |
} |
else |
{ |
BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
if(print) |
if(print) |
{ |
Piep(4,200); |
printf(" 4 Cells "); |
} |
} |
} |
} |
else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
233,34 → 233,6 |
eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
} |
printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Check connected BL-Ctrls |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
printf("\n\rFound BL-Ctrl: "); |
motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
timer = SetDelay(2000); |
for(i=0; i < MAX_MOTORS; i++) |
{ |
UpdateMotor = 0; |
SendMotorData(); |
while(!UpdateMotor); |
if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
{ |
while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
} |
if(MotorPresent[i]) printf("%d ",i+1); |
} |
for(i=0; i < MAX_MOTORS; i++) |
{ |
if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
{ |
printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
} |
MotorError[i] = 0; |
} |
printf("\n\r==================================="); |
SendMotorData(); |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Check Settings |
358,7 → 330,7 |
ROT_OFF; |
if(SenderOkay) SenderOkay--; |
else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
370,7 → 342,7 |
GPS_Roll = 0; |
} |
} |
if(!--I2CTimeout || MissingMotor) |
if(!--I2CTimeout) |
{ |
if(!I2CTimeout) |
{ |
428,10 → 400,10 |
timer2 = 0; |
FlugMinuten++; |
FlugMinutenGesamt++; |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
} |
} |
/branches/V0.76g-acid/main.h |
---|
86,6 → 86,7 |
extern unsigned char CosinusNickWinkel, CosinusRollWinkel; |
extern unsigned char PlatinenVersion; |
extern unsigned char SendVersionToNavi; |
extern unsigned char servoValues[6]; |
void ReadParameterSet (unsigned char number, unsigned char *buffer, unsigned char length); |
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length); |
extern unsigned char GetActiveParamSetNumber(void); |
/branches/V0.76g-acid/makefile |
---|
20,7 → 20,7 |
ifeq ($(MCU), atmega644) |
FUSE_SETTINGS = -u -U lfuse:w:0xff:m -U hfuse:w:0xdf:m |
#FUSE_SETTINGS = -U lfuse:w:0xff:m -U hfuse:w:0xdf:m |
#FUSE_SETTINGS = -U lfuse:w:0xff:m -U hfuse:w:0xdf:m |
# -u bei neuen Controllern wieder einspielen |
HEX_NAME = MEGA644 |
endif |
102,7 → 102,7 |
########################################################################################################## |
# List C source files here. (C dependencies are automatically generated.) |
SRC = main.c uart.c printf_P.c timer0.c analog.c menu.c |
SRC = main.c uart.c printf_P.c timer0.c analog.c menu.c |
SRC += twimaster.c rc.c fc.c GPS.c spi.c led.c Spectrum.c |
SRC += mymath.c |
122,7 → 122,7 |
# List any extra directories to look for include files here. |
# Each directory must be seperated by a space. |
EXTRAINCDIRS = |
EXTRAINCDIRS = |
# Optional compiler flags. |
157,7 → 157,7 |
# for use in COFF files, additional information about filenames |
# and function names needs to be present in the assembler source |
# files -- see avr-libc docs [FIXME: not yet described there] |
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
185,7 → 185,7 |
# Programming support using avrdude. Settings and variables. |
# Programming hardware: alf avr910 avrisp bascom bsd |
# Programming hardware: alf avr910 avrisp bascom bsd |
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
# |
# Type: avrdude -c ? |
201,7 → 201,7 |
#AVRDUDE_PORT = lpt1 # programmer connected to parallel port |
AVRDUDE_PORT = usb # programmer connected to USB |
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex |
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex |
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_SETTINGS) |
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
218,7 → 218,7 |
AVRDUDE_FLAGS += -V |
# Increase verbosity level. Please use this when submitting bug |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
# to submit bug reports. |
#AVRDUDE_FLAGS += -v -v |
254,7 → 254,7 |
MSG_ERRORS_NONE = Errors: none |
MSG_BEGIN = -------- begin -------- |
MSG_END = -------- end -------- |
MSG_SIZE_BEFORE = Size before: |
MSG_SIZE_BEFORE = Size before: |
MSG_SIZE_AFTER = Size after: |
MSG_COFF = Converting to AVR COFF: |
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
269,7 → 269,7 |
# Define all object files. |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
# Define all listing files. |
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) |
310,7 → 310,7 |
# Display compiler version information. |
gccversion : |
gccversion : |
@$(CC) --version |
320,7 → 320,7 |
--change-section-address .data-0x800000 \ |
--change-section-address .bss-0x800000 \ |
--change-section-address .noinit-0x800000 \ |
--change-section-address .eeprom-0x810000 |
--change-section-address .eeprom-0x810000 |
coff: $(TARGET).elf |
337,7 → 337,7 |
# Program the device. |
# Program the device. |
program: $(TARGET).hex $(TARGET).eep |
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
366,7 → 366,7 |
%.sym: %.elf |
@echo |
@echo $(MSG_SYMBOL_TABLE) $@ |
avr-nm -n $< > $@ |
# avr-nm -n $< > $@ |
425,8 → 425,8 |
$(REMOVE) $(SRC:.c=.d) |
# Automatically generate C source code dependencies. |
# (Code originally taken from the GNU make user manual and modified |
# Automatically generate C source code dependencies. |
# (Code originally taken from the GNU make user manual and modified |
# (See README.txt Credits).) |
# |
# Note that this will work with sh (bash) and sed that is shipped with WinAVR |
/branches/V0.76g-acid/twimaster.c |
---|
17,12 → 17,12 |
//############################################################################ |
{ |
TWSR = 0; |
TWBR = ((SYSCLK/SCL_CLOCK)-16)/2; |
TWBR = ((SYSCLK/SCL_CLOCK)-16)/2; |
} |
//############################################################################ |
//Start I2C |
void i2c_start(void) |
void i2c_start(void) |
//############################################################################ |
{ |
TWCR = (1<<TWSTA) | (1<<TWEN) | (1<<TWINT) | (1<<TWIE); |
38,7 → 38,7 |
void i2c_reset(void) |
//############################################################################ |
{ |
i2c_stop(); |
i2c_stop(); |
twi_state = 0; |
motor = TWDR; |
motor = 0; |
56,7 → 56,7 |
//############################################################################ |
void i2c_write_byte(char byte) |
//############################################################################ |
{ |
{ |
TWSR = 0x00; |
TWDR = byte; |
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE); |
91,8 → 91,15 |
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE); |
} |
uint8_t calc_crc(uint8_t *buffer, uint8_t l) { |
uint8_t crc = 0xff; |
uint8_t i; |
for(i = 0; i < l; i++) { |
crc = crc ^ buffer[i]; |
} |
return crc; |
} |
//############################################################################ |
SIGNAL (TWI_vect) |
//############################################################################ |
101,121 → 108,92 |
switch(twi_state++) |
{ |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// Writing the Data |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
case 0: |
while(Mixer.Motor[motor][0] <= 0 && motor < MAX_MOTORS) motor++; // skip if not used |
if(motor == MAX_MOTORS) // writing finished -> now read |
{ |
motor = 0; |
twi_state = 3; |
i2c_write_byte(0x53+(motorread*2)); |
} |
else i2c_write_byte(0x52+(motor*2)); |
break; |
case 1: |
i2c_write_byte(Motor[motor++]); |
break; |
case 2: |
if(TWSR == 0x30) |
{ |
if(!missing_motor) missing_motor = motor; |
if(++MotorError[motor-1] == 0) MotorError[motor-1] = 255; |
} |
i2c_stop(); |
I2CTimeout = 10; |
twi_state = 0; |
i2c_start(); |
break; |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// Reading Data |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
case 3: |
//Transmit 1st byte for reading |
if(TWSR != 0x40) // Error? |
{ |
MotorPresent[motorread] = 0; |
motorread++; |
if(motorread >= MAX_MOTORS) motorread = 0; |
i2c_stop(); |
twi_state = 0; |
} |
else |
{ |
MotorPresent[motorread] = ('1' - '-') + motorread; |
I2C_ReceiveByte(); |
} |
MissingMotor = missing_motor; |
missing_motor = 0; |
break; |
case 4: //Read 1st byte and transmit 2nd Byte |
motor_rx[motorread] = TWDR; |
I2C_ReceiveLastByte(); //nack |
break; |
case 5: |
//Read 2nd byte |
motor_rx2[motorread++] = TWDR; |
if(motorread >= MAX_MOTORS) motorread = 0; |
i2c_stop(); |
twi_state = 0; |
break; |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// writing Gyro-Offset |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
case 8: |
case 8: |
i2c_write_byte(0x98); // Address of the DAC |
break; |
case 9: |
case 9: |
i2c_write_byte(0x10); // Update Channel A |
break; |
case 10: |
case 10: |
i2c_write_byte(AnalogOffsetNick); // Value |
break; |
case 11: |
case 11: |
i2c_write_byte(0x80); // Value |
break; |
case 12: |
i2c_stop(); |
case 12: |
i2c_stop(); |
I2CTimeout = 10; |
i2c_start(); |
i2c_start(); |
break; |
case 13: |
case 13: |
i2c_write_byte(0x98); // Address of the DAC |
break; |
case 14: |
case 14: |
i2c_write_byte(0x12); // Update Channel B |
break; |
case 15: |
case 15: |
i2c_write_byte(AnalogOffsetRoll); // Value |
break; |
case 16: |
case 16: |
i2c_write_byte(0x80); // Value |
break; |
case 17: |
i2c_stop(); |
case 17: |
i2c_stop(); |
I2CTimeout = 10; |
i2c_start(); |
i2c_start(); |
break; |
case 18: |
case 18: |
i2c_write_byte(0x98); // Address of the DAC |
break; |
case 19: |
case 19: |
i2c_write_byte(0x14); // Update Channel C |
break; |
case 20: |
case 20: |
i2c_write_byte(AnalogOffsetGier); // Value |
break; |
case 21: |
case 21: |
i2c_write_byte(0x80); // Value |
break; |
case 22: |
i2c_stop(); |
case 22: |
i2c_stop(); |
I2CTimeout = 10; |
twi_state = 0; |
break; |
case 0: |
i2c_write_byte(0x82); // servo board |
twi_state = 100; |
break; |
case 100: // servo 1 |
i2c_write_byte(servoValues[0]); |
break; |
case 101: // servo 2 |
i2c_write_byte(servoValues[1]); |
break; |
case 102: // servo 3 |
i2c_write_byte(servoValues[2]); |
break; |
case 103: // servo 4 |
i2c_write_byte(servoValues[3]); |
break; |
case 104: // servo 5 |
i2c_write_byte(servoValues[4]); |
break; |
case 105: // servo 6 |
i2c_write_byte(servoValues[5]); |
break; |
case 106: |
i2c_write_byte(calc_crc(&servoValues, 6)); |
break; |
case 107: |
i2c_stop(); |
I2CTimeout = 10; |
twi_state = 0; |
break; |
default: twi_state = 0; |
break; |
break; |
} |
TWCR |= 0x80; |
} |
/branches/V0.76g-acid/version.txt |
---|
341,22 → 341,68 |
carefree MOD |
!!!ACHTUNG!!! - diese version ist experimentell und nicht fuer den mikrokopter geeignet |
voraussetzungen: |
HeliCTRL v0.0.1 |
FC ME oder FC 1.x + MK3MAG |
mit user parameter 8 stellt man ein, welche funktion aktiv ist. |
Servo board I2C address 0x82 |
0 die funktion ist deaktiviert |
1-128 verwende gier gyro fuer die umrechnung (nur fuer ME zu empfehlen) |
data |
>128 verwende MK3MAG. dabei ist zu beachten, dass kompass an und kompassrichtung fest aus ist |
byte[0] - servo 1 |
byte[1] - servo 2 |
byte[2] - servo 3 |
byte[3] - servo 4 |
byte[4] - servo 5 |
byte[5] - crc |
255 ist fuer sportliche flieger und entschaerft stick D beim gieren. |
servo 1 nick |
servo 2 roll |
servo 3 pitch |
servo 4 gier |
servo 5 throttle |
servo 6 unused |
254 ist fuer eine X formation. die koordinaten werden um 45 grad gedreht. |
Mixer settings |
die startrichtung wird beim einschalten der motoren festgelegt. |
motor 1 |
1 nick/roll base value |
2 nick gyro sensitivity 32 |
3 roll gyro sensitivity 16 |
4 gier gyro sensitivity 20 |
motor 2 |
1 gier smoothing 20 |
2 gier base 0 |
motor 3 |
1 throttle deadband 113 |
motor 4 |
1 throttle sensitivity 1 |
2 max throttle 75 |
motor 5 |
1 pitch sensitivity 6 |
2 max pitch 60 |
3 pitch base 30 |
motor 6 |
1 nick sensitivity 4 |
motor 7 |
1 roll sensitivity 4 |
motor 8 |
1 gier sensitivity 4 |