-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fied wing updates #304
base: master
Are you sure you want to change the base?
Fied wing updates #304
Changes from 9 commits
ce866ac
39a986b
f2066ac
e5b6ad3
57a4b9d
e9f73c0
a8b4ff1
912220a
c80cc71
a75f59f
f90a1d1
e912073
5991dc9
9905832
4b3564a
0bbef09
44b2f32
c32a76e
9d83e01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,16 @@ | |
// from gps.c | ||
extern int32_t nav_bearing; | ||
extern int32_t wp_distance; | ||
extern int32_t GPS_WP[2]; | ||
extern float GPS_scaleLonDown; | ||
|
||
extern PID_PARAM navPID_PARAM; | ||
extern PID_PARAM altPID_PARAM; | ||
|
||
#define GPS_UPD_HZ 5 // Set loop time for NavUpdate 5 Hz is enough | ||
#define PITCH_COMP 0.5f // Compensate throttle relative angle of attack | ||
// Candidates for CLI | ||
#define SAFE_NAV_ALT 20 // Safe Altitude during climbouts Wings Level below this Alt. (ex. trees & buildings..) | ||
#define SAFE_NAV_ALT 25 // Safe Altitude during climbouts Wings Level below this Alt. (ex. trees & buildings..) | ||
#define SAFE_DECSCEND_ZONE 50 // Radius around home where descending is OK | ||
// For speedBoost | ||
#define GPS_MINSPEED 500 // 500= ~18km/h | ||
|
@@ -40,6 +43,19 @@ void fw_nav_reset(void) | |
} | ||
} | ||
|
||
void fw_FlyTo(void) // PatrikE CruiseMode version | ||
{ | ||
#define GEO_SKALEFACT 89.832f // Scale to match meters | ||
int32_t holdHeading = GPS_ground_course / 10; | ||
if (holdHeading > 180) | ||
holdHeading -= 360; | ||
float scaler = ( GEO_SKALEFACT / GPS_scaleLonDown) * cfg.fw_cruise_distance; | ||
float wp_lat_diff = cos(holdHeading * 0.0174532925f); | ||
float wp_lon_diff = sin(holdHeading * 0.0174532925f) * GPS_scaleLonDown; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variables must be declared at start of scope, not in the middle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing spaces from the float wp_lon_diff = line (you will do it anyway when you move the variables to top of scope) |
||
GPS_WP[LAT] += wp_lat_diff * scaler; | ||
GPS_WP[LON] += wp_lon_diff * scaler; | ||
} | ||
|
||
void fw_nav(void) | ||
{ | ||
int16_t GPS_Heading = GPS_ground_course; // Store current bearing | ||
|
@@ -130,7 +146,6 @@ void fw_nav(void) | |
if (abs(navDiff) > 170) | ||
navDiff = 175; // Forced turn. | ||
|
||
|
||
// PID for Navigating planes. | ||
navDT = (float) (millis() - nav_loopT) / 1000; | ||
nav_loopT = millis(); | ||
|
@@ -201,16 +216,15 @@ void fw_nav(void) | |
// Elevator compensation depending on behaviour. | ||
// Prevent stall with Disarmed motor | ||
if (f.MOTORS_STOPPED) | ||
GPS_angle[PITCH] = constrain(GPS_angle[PITCH], 0, cfg.fw_gps_maxdive * 10); | ||
GPS_angle[PITCH] = constrain(GPS_angle[PITCH], -cfg.fw_glide_angle, cfg.fw_gps_maxdive * 10); | ||
|
||
// Add elevator compared with rollAngle | ||
if (!f.CLIMBOUT_FW) | ||
GPS_angle[PITCH] -= (abs(angle[ROLL]) * cfg.fw_roll_comp); | ||
GPS_angle[PITCH] -= (abs(angle[ROLL]) * (cfg.fw_roll_comp / 100)); | ||
|
||
// Throttle compensation depending on behaviour. | ||
// Compensate throttle with pitch Angle | ||
NAV_Thro -= constrain(angle[PITCH] * PITCH_COMP, 0, 450); | ||
NAV_Thro = constrain(NAV_Thro, cfg.fw_idle_throttle, cfg.fw_climb_throttle); | ||
|
||
// Force the Plane move forward in headwind with speedBoost | ||
groundSpeed = GPS_speed; | ||
|
@@ -221,6 +235,9 @@ void fw_nav(void) | |
|
||
speedBoost = constrain(speedBoost, 0, 500); | ||
NAV_Thro += speedBoost; | ||
|
||
// constrain throttle to Max climb. | ||
NAV_Thro = constrain(NAV_Thro, cfg.fw_idle_throttle, cfg.fw_climb_throttle); | ||
} | ||
// End of NavTimer | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,7 @@ const mixer_t mixers[] = { | |
{ 8, 0, mixerOctoX8 }, // MULTITYPE_OCTOX8 | ||
{ 8, 0, mixerOctoFlatP }, // MULTITYPE_OCTOFLATP | ||
{ 8, 0, mixerOctoFlatX }, // MULTITYPE_OCTOFLATX | ||
{ 1, 1, NULL }, // * MULTITYPE_AIRPLANE | ||
{ 2, 1, mixerTrustVector }, // * MULTITYPE_AIRPLANE | ||
{ 0, 1, NULL }, // * MULTITYPE_HELI_120_CCPM | ||
{ 0, 1, NULL }, // * MULTITYPE_HELI_90_DEG | ||
{ 4, 0, mixerVtail4 }, // MULTITYPE_VTAIL4 | ||
|
@@ -166,7 +166,7 @@ const mixer_t mixers[] = { | |
{ 1, 1, NULL }, // MULTITYPE_SINGLECOPTER | ||
{ 4, 0, mixerAtail4 }, // MULTITYPE_ATAIL4 | ||
{ 0, 0, NULL }, // MULTITYPE_CUSTOM | ||
{ 1, 1, NULL }, // MULTITYPE_CUSTOM_PLANE | ||
{ 2, 1, mixerTrustVector }, // MULTITYPE_CUSTOM_PLANE | ||
}; | ||
|
||
// mixer rule format servo, input, rate, speed, min, max, box | ||
|
@@ -549,13 +549,27 @@ void mixTable(void) | |
for (i = 0; i < numberMotor; i++) | ||
motor[i] = rcCommand[THROTTLE] * currentMixer[i].throttle + axisPID[PITCH] * currentMixer[i].pitch + axisPID[ROLL] * currentMixer[i].roll + -cfg.yaw_direction * axisPID[YAW] * currentMixer[i].yaw; | ||
|
||
if (f.FIXED_WING) { | ||
if (!f.ARMED) | ||
motor[0] = mcfg.mincommand; // Kill throttle when disarmed | ||
else | ||
motor[0] = constrain(rcCommand[THROTTLE], mcfg.minthrottle, mcfg.maxthrottle); | ||
if (f.FIXED_WING) { // vector_trust handeling | ||
if (cfg.fw_vector_trust && f.ARMED) { | ||
if (f.PASSTHRU_MODE) { | ||
motor[0] = rcCommand[THROTTLE] - rcCommand[YAW] * 0.5f; | ||
motor[1] = rcCommand[THROTTLE] + rcCommand[YAW] * 0.5f; | ||
} else { | ||
motor[0] = rcCommand[THROTTLE] - axisPID[YAW] * 0.5f; | ||
motor[1] = rcCommand[THROTTLE] + axisPID[YAW] * 0.5f; | ||
} | ||
} | ||
if (!cfg.fw_vector_trust) { | ||
motor[0] = rcCommand[THROTTLE]; | ||
motor[1] = rcCommand[THROTTLE]; | ||
} | ||
if (!f.ARMED || ((rcData[THROTTLE]) < mcfg.mincheck && feature(FEATURE_MOTOR_STOP))) { | ||
motor[0] = mcfg.mincommand; | ||
motor[1] = mcfg.mincommand; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There has to be a better way to write the above, I don't understand what current version does so surely there's a simpler way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I'm actually not understanding why this is necessary?
Is this correct?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's vector THRUST. if cfg.fw_vector_trust = false The for loop is used to write motor[i] = |
||
|
||
|
||
// airplane / servo mixes | ||
switch (mcfg.mixerConfiguration) { | ||
case MULTITYPE_CUSTOM_PLANE: | ||
|
@@ -639,6 +653,7 @@ void mixTable(void) | |
} | ||
if (!f.ARMED) { | ||
motor[i] = motor_disarmed[i]; | ||
f.MOTORS_STOPPED = 1; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,17 +109,39 @@ void annexCode(void) | |
static int64_t mAhdrawnRaw = 0; | ||
static int32_t vbatCycleTime = 0; | ||
|
||
// PITCH & ROLL only dynamic PID adjustemnt, depending on throttle value | ||
if (rcData[THROTTLE] < cfg.tpa_breakpoint) { | ||
prop2 = 100; | ||
} else { | ||
if (rcData[THROTTLE] < 2000) { | ||
prop2 = 100 - (uint16_t)cfg.dynThrPID * (rcData[THROTTLE] - cfg.tpa_breakpoint) / (2000 - cfg.tpa_breakpoint); | ||
if (!f.FIXED_WING) { // Baseflight original dynamic PID adjustemnt | ||
// PITCH & ROLL only dynamic PID adjustemnt, depending on throttle value | ||
if (rcData[THROTTLE] < cfg.tpa_breakpoint) { | ||
prop2 = 100; | ||
} else { | ||
prop2 = 100 - cfg.dynThrPID; | ||
if (rcData[THROTTLE] < 2000) { | ||
prop2 = 100 - (uint16_t)cfg.dynThrPID * (rcData[THROTTLE] - cfg.tpa_breakpoint) / (2000 - cfg.tpa_breakpoint); | ||
} else { | ||
prop2 = 100 - cfg.dynThrPID; | ||
} | ||
} | ||
} else { // Throttle & Angle combined PID adjustemnt | ||
// PITCH & ROLL only dynamic PID adjustemnt, depending on throttle value | ||
prop2 = 128; // prop2 was 100, is 128 now | ||
if (rcData[THROTTLE] < cfg.tpa_breakpoint) { | ||
prop2 = 128; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing space here |
||
} else { | ||
if (rcCommand[THROTTLE] > cfg.dynThrPID) { | ||
if (rcCommand[THROTTLE] < 2000) { | ||
prop2 -= ((uint16_t)cfg.dynThrPID * (rcCommand[THROTTLE] - cfg.dynThrPID) >> 9); // /512 instead of /500 | ||
} else { | ||
prop2 -= cfg.dynThrPID; | ||
} | ||
} | ||
} | ||
// APA dynamic PID adjustemnt, depending on Angle of attack | ||
uint16_t MaxBrkpoint = 300; // Max angle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this variable is not at start of scope |
||
if (angle[1] > 20) | ||
prop2 -= ((uint16_t)cfg.dynThrPID * (min(angle[1], MaxBrkpoint)) >> 8); | ||
prop2 = max((128 - cfg.dynThrPID), prop2); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's copypasted code here and its function is unclear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding Dive angle to TPA for Fixed wing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but this code duplicates already stupid code. what does it acutally do and can it be rewritten better?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. High speed can cause Wobbling (overcorrection) The function works good and i don't know how to improve it atm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but if that's what it does, then the whole shit can be replaced with On Sun, Jan 3, 2016 at 3:11 AM, EmilsPa [email protected] wrote:
|
||
|
||
|
||
for (axis = 0; axis < 3; axis++) { | ||
tmp = min(abs(rcData[axis] - mcfg.midrc), 500); | ||
if (axis != 2) { // ROLL & PITCH | ||
|
@@ -691,6 +713,11 @@ void loop(void) | |
auxState |= (rcData[AUX1 + i] < 1300) << (3 * i) | (1300 < rcData[AUX1 + i] && rcData[AUX1 + i] < 1700) << (3 * i + 1) | (rcData[AUX1 + i] > 1700) << (3 * i + 2); | ||
for (i = 0; i < CHECKBOXITEMS; i++) | ||
rcOptions[i] = (auxState & cfg.activate[i]) > 0; | ||
f.CRUISE_MODE = rcOptions[BOXGCRUISE]; | ||
if (f.CRUISE_MODE) { | ||
rcOptions[BOXGPSHOLD] = true; | ||
rcOptions[BOXHORIZON] = true; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will above change somehow affect quads if selected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No |
||
// note: if FAILSAFE is disable, failsafeCnt > 5 * FAILSAVE_DELAY is always false | ||
if ((rcOptions[BOXANGLE] || (failsafeCnt > 5 * cfg.failsafe_delay)) && (sensors(SENSOR_ACC))) { | ||
|
@@ -782,6 +809,9 @@ void loop(void) | |
#ifdef GPS | ||
if (sensors(SENSOR_GPS)) { | ||
if (f.GPS_FIX && GPS_numSat >= 5) { | ||
if (nav_mode != NAV_MODE_NONE && (!f.HORIZON_MODE && !f.ANGLE_MODE)) | ||
f.ANGLE_MODE = true; // Force a stable mode in GPS Mode | ||
|
||
// if both GPS_HOME & GPS_HOLD are checked => GPS_HOME is the priority | ||
if (rcOptions[BOXGPSHOME] || f.FW_FAILSAFE_RTH_ENABLE ) { | ||
if (!f.GPS_HOME_MODE) { | ||
|
@@ -832,7 +862,7 @@ void loop(void) | |
f.PASSTHRU_MODE = 0; | ||
} | ||
|
||
if (mcfg.mixerConfiguration == MULTITYPE_FLYING_WING || mcfg.mixerConfiguration == MULTITYPE_AIRPLANE || mcfg.mixerConfiguration == MULTITYPE_CUSTOM_PLANE) { | ||
if (f.FIXED_WING) { | ||
f.HEADFREE_MODE = 0; | ||
if (feature(FEATURE_FAILSAFE) && failsafeCnt > (6 * cfg.failsafe_delay)) { | ||
f.PASSTHRU_MODE = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#defines do not belong inside functions.
move it outside.