Subversion Repositories FlightCtrl

Rev

Rev 1946 | Rev 1956 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1946 Rev 1955
Line 132... Line 132...
132
  yawPFactor = _yawPFactor;
132
  yawPFactor = _yawPFactor;
133
  yawIFactor = _yawIFactor;
133
  yawIFactor = _yawIFactor;
134
}
134
}
Line 135... Line 135...
135
 
135
 
136
void setNormalFlightParameters(void) {
136
void setNormalFlightParameters(void) {
-
 
137
  setFlightParameters(dynamicParams.IFactor,
137
  setFlightParameters(dynamicParams.IFactor, dynamicParams.GyroP,
138
      dynamicParams.GyroP,
-
 
139
      staticParams.GlobalConfig & CFG_HEADING_HOLD ? 0 : dynamicParams.GyroI,
138
      staticParams.GlobalConfig & CFG_HEADING_HOLD ? 0 : dynamicParams.GyroI,
140
      dynamicParams.GyroP,
-
 
141
      dynamicParams.UserParams[6]
139
      dynamicParams.GyroP, dynamicParams.UserParams[6]);
142
  );
Line 140... Line 143...
140
}
143
}
141
 
144
 
142
void setStableFlightParameters(void) {
145
void setStableFlightParameters(void) {
Line 353... Line 356...
353
   * between current throttle and maximum throttle).
356
   * between current throttle and maximum throttle).
354
   */
357
   */
355
#define MIN_YAWGAS (40 * CONTROL_SCALING)  // yaw also below this gas value
358
#define MIN_YAWGAS (40 * CONTROL_SCALING)  // yaw also below this gas value
356
  yawTerm = PDPartYaw - controls[CONTROL_YAW] * CONTROL_SCALING;
359
  yawTerm = PDPartYaw - controls[CONTROL_YAW] * CONTROL_SCALING;
357
  // Limit yawTerm
360
  // Limit yawTerm
358
  DebugOut.Digital[0] &= ~DEBUG_CLIP;
361
  debugOut.digital[0] &= ~DEBUG_CLIP;
359
  if (throttleTerm > MIN_YAWGAS) {
362
  if (throttleTerm > MIN_YAWGAS) {
360
    if (yawTerm < -throttleTerm / 2) {
363
    if (yawTerm < -throttleTerm / 2) {
361
      DebugOut.Digital[0] |= DEBUG_CLIP;
364
      debugOut.digital[0] |= DEBUG_CLIP;
362
      yawTerm = -throttleTerm / 2;
365
      yawTerm = -throttleTerm / 2;
363
    } else if (yawTerm > throttleTerm / 2) {
366
    } else if (yawTerm > throttleTerm / 2) {
364
      DebugOut.Digital[0] |= DEBUG_CLIP;
367
      debugOut.digital[0] |= DEBUG_CLIP;
365
      yawTerm = throttleTerm / 2;
368
      yawTerm = throttleTerm / 2;
366
    }
369
    }
367
    //CHECK_MIN_MAX(yawTerm, - (throttleTerm / 2), (throttleTerm / 2));
370
    //CHECK_MIN_MAX(yawTerm, - (throttleTerm / 2), (throttleTerm / 2));
368
  } else {
371
  } else {
369
    if (yawTerm < -MIN_YAWGAS / 2) {
372
    if (yawTerm < -MIN_YAWGAS / 2) {
370
      DebugOut.Digital[0] |= DEBUG_CLIP;
373
      debugOut.digital[0] |= DEBUG_CLIP;
371
      yawTerm = -MIN_YAWGAS / 2;
374
      yawTerm = -MIN_YAWGAS / 2;
372
    } else if (yawTerm > MIN_YAWGAS / 2) {
375
    } else if (yawTerm > MIN_YAWGAS / 2) {
373
      DebugOut.Digital[0] |= DEBUG_CLIP;
376
      debugOut.digital[0] |= DEBUG_CLIP;
374
      yawTerm = MIN_YAWGAS / 2;
377
      yawTerm = MIN_YAWGAS / 2;
375
    }
378
    }
376
    //CHECK_MIN_MAX(yawTerm, - (MIN_YAWGAS / 2), (MIN_YAWGAS / 2));
379
    //CHECK_MIN_MAX(yawTerm, - (MIN_YAWGAS / 2), (MIN_YAWGAS / 2));
377
  }
380
  }
Line 378... Line 381...
378
 
381
 
379
  // FIXME: Throttle may exceed maxThrottle (there is no check no more).
382
  // FIXME: Throttle may exceed maxThrottle (there is no check no more).
380
  tmp_int = staticParams.MaxThrottle * CONTROL_SCALING;
383
  tmp_int = staticParams.MaxThrottle * CONTROL_SCALING;
381
  if (yawTerm < -(tmp_int - throttleTerm)) {
384
  if (yawTerm < -(tmp_int - throttleTerm)) {
382
    yawTerm = -(tmp_int - throttleTerm);
385
    yawTerm = -(tmp_int - throttleTerm);
383
    DebugOut.Digital[0] |= DEBUG_CLIP;
386
    debugOut.digital[0] |= DEBUG_CLIP;
384
  } else if (yawTerm > (tmp_int - throttleTerm)) {
387
  } else if (yawTerm > (tmp_int - throttleTerm)) {
385
    yawTerm = (tmp_int - throttleTerm);
388
    yawTerm = (tmp_int - throttleTerm);
386
    DebugOut.Digital[0] |= DEBUG_CLIP;
389
    debugOut.digital[0] |= DEBUG_CLIP;
Line 387... Line 390...
387
  }
390
  }
388
 
391
 
389
  // CHECK_MIN_MAX(yawTerm, -(tmp_int - throttleTerm), (tmp_int - throttleTerm));
392
  // CHECK_MIN_MAX(yawTerm, -(tmp_int - throttleTerm), (tmp_int - throttleTerm));
390
  DebugOut.Digital[1] &= ~DEBUG_CLIP;
393
  debugOut.digital[1] &= ~DEBUG_CLIP;
391
  for (axis = PITCH; axis <= ROLL; axis++) {
394
  for (axis = PITCH; axis <= ROLL; axis++) {
392
    /*
395
    /*
393
     * Compose pitch and roll terms. This is finally where the sticks come into play.
396
     * Compose pitch and roll terms. This is finally where the sticks come into play.
Line 416... Line 419...
416
     * The higher the dynamic stability parameter, the wider the bounds. 64 seems to be a kind of unity
419
     * The higher the dynamic stability parameter, the wider the bounds. 64 seems to be a kind of unity
417
     * (max. pitch or roll term is the throttle value).
420
     * (max. pitch or roll term is the throttle value).
418
     * TODO: Why a growing function of yaw?
421
     * TODO: Why a growing function of yaw?
419
     */
422
     */
420
    if (term[axis] < -tmp_int) {
423
    if (term[axis] < -tmp_int) {
421
      DebugOut.Digital[1] |= DEBUG_CLIP;
424
      debugOut.digital[1] |= DEBUG_CLIP;
422
    } else if (term[axis] > tmp_int) {
425
    } else if (term[axis] > tmp_int) {
423
      DebugOut.Digital[1] |= DEBUG_CLIP;
426
      debugOut.digital[1] |= DEBUG_CLIP;
424
    }
427
    }
425
    CHECK_MIN_MAX(term[axis], -tmp_int, tmp_int);
428
    CHECK_MIN_MAX(term[axis], -tmp_int, tmp_int);
426
  }
429
  }
Line 427... Line 430...
427
 
430
 
428
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
431
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
429
  // Universal Mixer
432
  // Universal Mixer
430
  // Each (pitch, roll, throttle, yaw) term is in the range [0..255 * CONTROL_SCALING].
433
  // Each (pitch, roll, throttle, yaw) term is in the range [0..255 * CONTROL_SCALING].
Line 431... Line 434...
431
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
434
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
432
 
435
 
433
  DebugOut.Analog[12] = term[PITCH];
436
  debugOut.analog[12] = term[PITCH];
434
  DebugOut.Analog[13] = term[ROLL];
437
  debugOut.analog[13] = term[ROLL];
Line 435... Line 438...
435
  //DebugOut.Analog[14] = yawTerm;
438
  debugOut.analog[14] = yawTerm;
436
  DebugOut.Analog[15] = throttleTerm;
439
  debugOut.analog[15] = throttleTerm;
437
 
440
 
Line 456... Line 459...
456
    // --> WRONG. This caused motors to stall completely in tight maneuvers.
459
    // --> WRONG. This caused motors to stall completely in tight maneuvers.
457
    // Apply to individual signals instead.
460
    // Apply to individual signals instead.
458
    CHECK_MIN_MAX(tmp, 1, 255);
461
    CHECK_MIN_MAX(tmp, 1, 255);
459
    throttle = tmp;
462
    throttle = tmp;
Line 460... Line 463...
460
 
463
 
Line 461... Line 464...
461
    if (i < 4) DebugOut.Analog[22 + i] = throttle;
464
    if (i < 4) debugOut.analog[22 + i] = throttle;
462
 
465
 
463
    if (MKFlags & MKFLAG_MOTOR_RUN && Mixer.Motor[i][MIX_THROTTLE] > 0) {
466
    if ((MKFlags & MKFLAG_MOTOR_RUN) && Mixer.Motor[i][MIX_THROTTLE] > 0) {
464
      motor[i].SetPoint = throttle;
467
      motor[i].SetPoint = throttle;
465
    } else if (motorTestActive) {
468
    } else if (motorTestActive) {
466
      motor[i].SetPoint = motorTest[i];
469
      motor[i].SetPoint = motorTest[i];
Line 474... Line 477...
474
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
477
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
475
  // Debugging
478
  // Debugging
476
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
479
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
477
  if (!(--debugDataTimer)) {
480
  if (!(--debugDataTimer)) {
478
    debugDataTimer = 24; // update debug outputs at 488 / 24 = 20.3 Hz.
481
    debugDataTimer = 24; // update debug outputs at 488 / 24 = 20.3 Hz.
479
    DebugOut.Analog[0] = (10 * angle[PITCH]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
482
    debugOut.analog[0] = (10 * angle[PITCH]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
480
    DebugOut.Analog[1] = (10 * angle[ROLL]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
483
    debugOut.analog[1] = (10 * angle[ROLL]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
481
    DebugOut.Analog[2] = yawGyroHeading / GYRO_DEG_FACTOR_YAW;
484
    debugOut.analog[2] = yawGyroHeading / GYRO_DEG_FACTOR_YAW;
482
 
485
 
483
    DebugOut.Analog[6] = 64 >> 4;
486
    debugOut.analog[16] = gyroPFactor;
484
    DebugOut.Analog[7] = -64 >> 4;
487
    debugOut.analog[17] = gyroIFactor;
485
 
-
 
486
    /*
-
 
487
     DebugOut.Analog[23] = (yawRate * 2 * (int32_t)yawPFactor) / (256L / CONTROL_SCALING);
-
 
488
     DebugOut.Analog[24] = controlYaw;
-
 
489
     DebugOut.Analog[25] = yawAngleDiff / 100L;
-
 
490
     DebugOut.Analog[26] = accNoisePeak[PITCH];
-
 
491
     DebugOut.Analog[27] = accNoisePeak[ROLL];
-
 
492
     DebugOut.Analog[30] = gyroNoisePeak[PITCH];
488
    debugOut.analog[18] = dynamicParams.GyroD;
493
     DebugOut.Analog[31] = gyroNoisePeak[ROLL];
-
 
494
     */
-
 
495
  }
489
  }
496
}
490
}