Rev 942 | Rev 957 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 942 | Rev 943 | ||
---|---|---|---|
Line 126... | Line 126... | ||
126 | int16_t DiffNick, DiffRoll; |
126 | int16_t DiffNick, DiffRoll; |
Line 127... | Line 127... | ||
127 | 127 | ||
Line 128... | Line 128... | ||
128 | int16_t Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
128 | int16_t Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
- | 129 | ||
- | 130 | // setpoints for motors |
|
- | 131 | #ifdef HEXAKOPTER |
|
129 | 132 | volatile uint8_t Motor_FrontLeft, Motor_FrontRight, Motor_RearLeft, Motor_RearRight, Motor_Right, Motor_Left; |
|
- | 133 | #else |
|
Line 130... | Line 134... | ||
130 | // setpoints for motors |
134 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; //used by twimaster isr |
131 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; |
135 | #endif |
132 | 136 | ||
Line 380... | Line 384... | ||
380 | /************************************************************************/ |
384 | /************************************************************************/ |
381 | void SendMotorData(void) |
385 | void SendMotorData(void) |
382 | { |
386 | { |
383 | if(!(MKFlags & MKFLAG_MOTOR_RUN)) |
387 | if(!(MKFlags & MKFLAG_MOTOR_RUN)) |
384 | { |
388 | { |
- | 389 | #ifdef HEXAKOPTER |
|
- | 390 | Motor_RearLeft = 0; |
|
- | 391 | Motor_FrontLeft = 0; |
|
- | 392 | Motor_RearRight = 0; |
|
- | 393 | Motor_FrontRight = 0; |
|
- | 394 | Motor_Right = 0; |
|
- | 395 | Motor_Left = 0; |
|
- | 396 | if(MotorTest[0]) Motor_FrontLeft = Motor_FrontRight = MotorTest[0]; |
|
- | 397 | if(MotorTest[1]) Motor_RearLeft = Motor_RearRight = MotorTest[1]; |
|
- | 398 | if(MotorTest[2]) Motor_Left = MotorTest[2]; |
|
- | 399 | if(MotorTest[3]) Motor_Right = MotorTest[3]; |
|
- | 400 | #else |
|
385 | Motor_Rear = 0; |
401 | Motor_Rear = 0; |
386 | Motor_Front = 0; |
402 | Motor_Front = 0; |
387 | Motor_Right = 0; |
403 | Motor_Right = 0; |
388 | Motor_Left = 0; |
404 | Motor_Left = 0; |
389 | if(MotorTest[0]) Motor_Front = MotorTest[0]; |
405 | if(MotorTest[0]) Motor_Front = MotorTest[0]; |
390 | if(MotorTest[1]) Motor_Rear = MotorTest[1]; |
406 | if(MotorTest[1]) Motor_Rear = MotorTest[1]; |
391 | if(MotorTest[2]) Motor_Left = MotorTest[2]; |
407 | if(MotorTest[2]) Motor_Left = MotorTest[2]; |
392 | if(MotorTest[3]) Motor_Right = MotorTest[3]; |
408 | if(MotorTest[3]) Motor_Right = MotorTest[3]; |
- | 409 | #endif |
|
393 | MKFlags &= ~(MKFLAG_FLY|MKFLAG_START); // clear flag FLY and START if motors are off |
410 | MKFlags &= ~(MKFLAG_FLY|MKFLAG_START); // clear flag FLY and START if motors are off |
394 | } |
411 | } |
395 | DebugOut.Analog[12] = Motor_Front; |
- | |
396 | DebugOut.Analog[13] = Motor_Rear; |
- | |
397 | DebugOut.Analog[14] = Motor_Left; |
- | |
398 | DebugOut.Analog[15] = Motor_Right; |
- | |
399 | 412 | ||
400 | //Start I2C Interrupt Mode |
413 | //Start I2C Interrupt Mode |
401 | twi_state = TWI_STATE_MOTOR_TX; |
414 | twi_state = TWI_STATE_MOTOR_TX; |
402 | I2C_Start(); |
415 | I2C_Start(); |
403 | } |
416 | } |
Line 472... | Line 485... | ||
472 | /* MotorControl */ |
485 | /* MotorControl */ |
473 | /************************************************************************/ |
486 | /************************************************************************/ |
474 | void MotorControl(void) |
487 | void MotorControl(void) |
475 | { |
488 | { |
476 | int16_t MotorValue, pd_result, h, tmp_int; |
489 | int16_t MotorValue, pd_result, h, tmp_int; |
477 | int16_t YawMixFraction, GasMixFraction; |
490 | int16_t YawMixFraction, GasMixFraction, NickMixFraction, RollMixFraction; |
478 | static int32_t SumNick = 0, SumRoll = 0; |
491 | static int32_t SumNick = 0, SumRoll = 0; |
479 | static int32_t SetPointYaw = 0; |
492 | static int32_t SetPointYaw = 0; |
480 | static int32_t IntegralErrorNick = 0; |
493 | static int32_t IntegralErrorNick = 0; |
481 | static int32_t IntegralErrorRoll = 0; |
494 | static int32_t IntegralErrorRoll = 0; |
482 | static uint16_t RcLostTimer; |
495 | static uint16_t RcLostTimer; |
Line 573... | Line 586... | ||
573 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
586 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
574 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
587 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
575 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
588 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
576 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
589 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
Line -... | Line 590... | ||
- | 590 | ||
577 | 591 | ||
578 | // if motors are off and the gas stick is in the upper position |
592 | // if motors are off and the gas stick is in the upper position |
579 | if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && !(MKFlags & MKFLAG_MOTOR_RUN) ) |
593 | if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && !(MKFlags & MKFLAG_MOTOR_RUN) ) |
580 | { |
594 | { |
581 | // and if the yaw stick is in the leftmost position |
595 | // and if the yaw stick is in the leftmost position |
Line 692... | Line 706... | ||
692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
706 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) |
707 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) |
694 | { |
708 | { |
695 | if(++delay_startmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
709 | if(++delay_startmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
696 | { |
710 | { |
697 | delay_startmotors = 200; // do not repeat if once executed |
711 | delay_startmotors = 0; // do not repeat if once executed |
698 | Model_Is_Flying = 1; |
712 | Model_Is_Flying = 1; |
699 | MKFlags |= (MKFLAG_MOTOR_RUN|MKFLAG_START); // set flag RUN and START |
713 | MKFlags |= (MKFLAG_MOTOR_RUN|MKFLAG_START); // set flag RUN and START |
700 | SetPointYaw = 0; |
714 | SetPointYaw = 0; |
701 | Reading_IntegralGyroYaw = 0; |
715 | Reading_IntegralGyroYaw = 0; |
702 | Reading_IntegralGyroNick = 0; |
716 | Reading_IntegralGyroNick = 0; |
Line 713... | Line 727... | ||
713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
727 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
714 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
728 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
715 | { |
729 | { |
716 | if(++delay_stopmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
730 | if(++delay_stopmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
717 | { |
731 | { |
718 | delay_stopmotors = 200; // do not repeat if once executed |
732 | delay_stopmotors = 0; // do not repeat if once executed |
719 | Model_Is_Flying = 0; |
733 | Model_Is_Flying = 0; |
720 | MKFlags &= ~(MKFLAG_MOTOR_RUN); |
734 | MKFlags &= ~(MKFLAG_MOTOR_RUN); |
721 | } |
735 | } |
722 | } |
736 | } |
723 | else delay_stopmotors = 0; // reset delay timer if sticks are not in this position |
737 | else delay_stopmotors = 0; // reset delay timer if sticks are not in this position |
Line 1229... | Line 1243... | ||
1229 | DebugOut.Analog[2] = Mean_AccNick; |
1243 | DebugOut.Analog[2] = Mean_AccNick; |
1230 | DebugOut.Analog[3] = Mean_AccRoll; |
1244 | DebugOut.Analog[3] = Mean_AccRoll; |
1231 | DebugOut.Analog[4] = Reading_GyroYaw; |
1245 | DebugOut.Analog[4] = Reading_GyroYaw; |
1232 | DebugOut.Analog[5] = ReadingHeight; |
1246 | DebugOut.Analog[5] = ReadingHeight; |
1233 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
1247 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
1234 | DebugOut.Analog[8] = CompassHeading; |
1248 | // DebugOut.Analog[8] = CompassHeading; |
- | 1249 | DebugOut.Analog[8] = RC_Quality; |
|
1235 | DebugOut.Analog[9] = UBat; |
1250 | DebugOut.Analog[9] = UBat; |
- | 1251 | ||
- | 1252 | #ifdef HEXAKOPTER |
|
- | 1253 | DebugOut.Analog[10] = Motor_FrontLeft; |
|
- | 1254 | DebugOut.Analog[11] = Motor_FrontRight; |
|
- | 1255 | DebugOut.Analog[12] = Motor_RearLeft; |
|
- | 1256 | DebugOut.Analog[13] = Motor_RearRight; |
|
- | 1257 | DebugOut.Analog[14] = Motor_Left; |
|
1236 | DebugOut.Analog[10] = RC_Quality; |
1258 | DebugOut.Analog[15] = Motor_Right; |
- | 1259 | #else |
|
1237 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
1260 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
- | 1261 | ||
- | 1262 | DebugOut.Analog[12] = Motor_Front; |
|
- | 1263 | DebugOut.Analog[13] = Motor_Rear; |
|
- | 1264 | DebugOut.Analog[14] = Motor_Left; |
|
- | 1265 | DebugOut.Analog[15] = Motor_Right; |
|
- | 1266 | #endif |
|
- | 1267 | ||
1238 | //DebugOut.Analog[16] = Mean_AccTop; |
1268 | DebugOut.Analog[16] = Mean_AccTop; |
Line 1239... | Line 1269... | ||
1239 | 1269 | ||
Line 1386... | Line 1416... | ||
1386 | 1416 | ||
1387 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(GasMixFraction + abs(YawMixFraction)/2)) / 64; |
1417 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(GasMixFraction + abs(YawMixFraction)/2)) / 64; |
1388 | if(pd_result > tmp_int) pd_result = tmp_int; |
1418 | if(pd_result > tmp_int) pd_result = tmp_int; |
Line 1389... | Line -... | ||
1389 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
- | |
1390 | - | ||
1391 | // Motor Front |
1419 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
1392 | MotorValue = GasMixFraction + pd_result + YawMixFraction; // Mixer |
- | |
1393 | MotorValue /= STICK_GAIN; |
- | |
1394 | if ((MotorValue < 0)) MotorValue = 0; |
- | |
1395 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
- | |
Line 1396... | Line -... | ||
1396 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
- | |
1397 | Motor_Front = MotorValue; |
- | |
1398 | - | ||
1399 | // Motor Rear |
- | |
1400 | MotorValue = GasMixFraction - pd_result + YawMixFraction; // Mixer |
- | |
1401 | MotorValue /= STICK_GAIN; |
- | |
1402 | if ((MotorValue < 0)) MotorValue = 0; |
- | |
1403 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1420 | |
1404 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1421 | NickMixFraction = pd_result; |
1405 | Motor_Rear = MotorValue; |
1422 | |
1406 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1423 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1407 | // Roll-Axis |
1424 | // Roll-Axis |
Line 1414... | Line 1431... | ||
1414 | pd_result = DiffRoll + Ki * SumRoll; // PI-controller for roll |
1431 | pd_result = DiffRoll + Ki * SumRoll; // PI-controller for roll |
1415 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(GasMixFraction + abs(YawMixFraction)/2)) / 64; |
1432 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(GasMixFraction + abs(YawMixFraction)/2)) / 64; |
1416 | if(pd_result > tmp_int) pd_result = tmp_int; |
1433 | if(pd_result > tmp_int) pd_result = tmp_int; |
1417 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
1434 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
Line -... | Line 1435... | ||
- | 1435 | ||
- | 1436 | RollMixFraction = pd_result; |
|
- | 1437 | ||
- | 1438 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1439 | // Calculate Motor Mixes |
|
- | 1440 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1441 | ||
- | 1442 | #ifdef HEXAKOPTER |
|
- | 1443 | // Motor FrontLeft |
|
- | 1444 | MotorValue = GasMixFraction |
|
- | 1445 | + NickMixFraction |
|
- | 1446 | + RollMixFraction/2 |
|
- | 1447 | - YawMixFraction; // Mixer |
|
- | 1448 | MotorValue /= STICK_GAIN; |
|
- | 1449 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1450 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1451 | Motor_FrontLeft = MotorValue; |
|
- | 1452 | ||
- | 1453 | // Motor FrontRight |
|
- | 1454 | MotorValue = GasMixFraction |
|
- | 1455 | + NickMixFraction |
|
- | 1456 | - RollMixFraction/2 |
|
- | 1457 | + YawMixFraction; // Mixer |
|
- | 1458 | MotorValue /= STICK_GAIN; |
|
- | 1459 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1460 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1461 | Motor_FrontRight = MotorValue; |
|
- | 1462 | ||
- | 1463 | // Motor RearLeft |
|
- | 1464 | MotorValue = GasMixFraction |
|
- | 1465 | - NickMixFraction |
|
- | 1466 | + RollMixFraction/2 |
|
- | 1467 | - YawMixFraction; // Mixer |
|
- | 1468 | MotorValue /= STICK_GAIN; |
|
- | 1469 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1470 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1471 | Motor_RearLeft = MotorValue; |
|
- | 1472 | ||
- | 1473 | // Motor RearRight |
|
- | 1474 | MotorValue = GasMixFraction |
|
- | 1475 | - NickMixFraction |
|
- | 1476 | - RollMixFraction/2 |
|
- | 1477 | + YawMixFraction; // Mixer |
|
- | 1478 | MotorValue /= STICK_GAIN; |
|
- | 1479 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1480 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1481 | Motor_RearRight= MotorValue; |
|
- | 1482 | ||
- | 1483 | // Motor Left |
|
- | 1484 | MotorValue = GasMixFraction |
|
- | 1485 | + RollMixFraction |
|
- | 1486 | + YawMixFraction; // Mixer |
|
- | 1487 | MotorValue /= STICK_GAIN; |
|
- | 1488 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1489 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1490 | Motor_Left = MotorValue; |
|
- | 1491 | ||
- | 1492 | // Motor Right |
|
- | 1493 | MotorValue = GasMixFraction |
|
- | 1494 | - RollMixFraction |
|
- | 1495 | - YawMixFraction; // Mixer |
|
- | 1496 | MotorValue /= STICK_GAIN; |
|
- | 1497 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1498 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1499 | Motor_Right = MotorValue; |
|
- | 1500 | ||
- | 1501 | #else |
|
- | 1502 | ||
- | 1503 | // Motor Front |
|
- | 1504 | MotorValue = GasMixFraction + NickMixFraction + YawMixFraction; // Mixer |
|
- | 1505 | MotorValue /= STICK_GAIN; |
|
- | 1506 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1507 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1508 | Motor_Front = MotorValue; |
|
- | 1509 | ||
- | 1510 | // Motor Rear |
|
- | 1511 | MotorValue = GasMixFraction - NickMixFraction + YawMixFraction; // Mixer |
|
- | 1512 | MotorValue /= STICK_GAIN; |
|
- | 1513 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
|
- | 1514 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
- | 1515 | Motor_Rear = MotorValue; |
|
- | 1516 | ||
1418 | 1517 | ||
1419 | // Motor Left |
1518 | // Motor Left |
1420 | MotorValue = GasMixFraction + pd_result - YawMixFraction; // Mixer |
1519 | MotorValue = GasMixFraction + RollMixFraction - YawMixFraction; // Mixer |
1421 | MotorValue /= STICK_GAIN; |
- | |
1422 | if ((MotorValue < 0)) MotorValue = 0; |
1520 | MotorValue /= STICK_GAIN; |
1423 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1521 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1424 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1522 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
Line -... | Line 1523... | ||
- | 1523 | Motor_Left = MotorValue; |
|
1425 | Motor_Left = MotorValue; |
1524 | |
1426 | 1525 | ||
1427 | // Motor Right |
1526 | // Motor Right |
1428 | MotorValue = GasMixFraction - pd_result - YawMixFraction; // Mixer |
- | |
1429 | MotorValue /= STICK_GAIN; |
1527 | MotorValue = GasMixFraction - RollMixFraction - YawMixFraction; // Mixer |
1430 | if ((MotorValue < 0)) MotorValue = 0; |
1528 | MotorValue /= STICK_GAIN; |
1431 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1529 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
- | 1530 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
1432 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1531 | Motor_Right = MotorValue; |