Skip to content
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

Added 'small_angle' indicator to OSD flip arrow. #7250

Merged
merged 2 commits into from Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/fc/core.c
Expand Up @@ -519,8 +519,9 @@ void updateMagHold(void)
if (dif >= +180)
dif -= 360;
dif *= -GET_DIRECTION(rcControlsConfig()->yaw_control_reversed);
if (STATE(SMALL_ANGLE))
if (STATE(SMALL_ANGLE)) {
rcCommand[YAW] -= dif * currentPidProfile->pid[PID_MAG].P / 30; // 18 deg
}
} else
magHold = DECIDEGREES_TO_DEGREES(attitude.values.yaw);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/flight/imu.c
Expand Up @@ -157,7 +157,8 @@ void imuConfigure(uint16_t throttle_correction_angle, uint8_t throttle_correctio
{
imuRuntimeConfig.dcm_kp = imuConfig()->dcm_kp / 10000.0f;
imuRuntimeConfig.dcm_ki = imuConfig()->dcm_ki / 10000.0f;
imuRuntimeConfig.small_angle = imuConfig()->small_angle;

smallAngleCosZ = cos_approx(degreesToRadians(imuConfig()->small_angle));

fc_acc = calculateAccZLowPassFilterRCTimeConstant(5.0f); // Set to fix value
throttleAngleScale = calculateThrottleAngleScale(throttle_correction_angle);
Expand All @@ -167,7 +168,6 @@ void imuConfigure(uint16_t throttle_correction_angle, uint8_t throttle_correctio

void imuInit(void)
{
smallAngleCosZ = cos_approx(degreesToRadians(imuRuntimeConfig.small_angle));
accVelScale = 9.80665f * acc.dev.acc_1G_rec / 10000.0f;

#ifdef USE_GPS
Expand Down
1 change: 0 additions & 1 deletion src/main/flight/imu.h
Expand Up @@ -67,7 +67,6 @@ PG_DECLARE(imuConfig_t, imuConfig);
typedef struct imuRuntimeConfig_s {
float dcm_ki;
float dcm_kp;
uint8_t small_angle;
} imuRuntimeConfig_t;

void imuConfigure(uint16_t throttle_correction_angle, uint8_t throttle_correction_value);
Expand Down
52 changes: 36 additions & 16 deletions src/main/io/osd.c
Expand Up @@ -528,7 +528,6 @@ void changeOsdProfileIndex(uint8_t profileIndex)
}
#endif


static bool osdDrawSingleElement(uint8_t item)
{
if (!VISIBLE(osdConfig()->item_pos[item]) || BLINK(item)) {
Expand All @@ -542,25 +541,46 @@ static bool osdDrawSingleElement(uint8_t item)
switch (item) {
case OSD_FLIP_ARROW:
{
const int angleR = attitude.values.roll / 10;
const int angleP = attitude.values.pitch / 10; // still gotta update all angleR and angleP pointers.
if (isFlipOverAfterCrashActive()) {
if (angleP > 0 && ((angleR > 175 && angleR < 180) || (angleR > -180 && angleR < -175))) {
buff[0] = SYM_ARROW_SOUTH;
} else if (angleP > 0 && angleR > 0 && angleR < 175) {
buff[0] = (SYM_ARROW_EAST + 2);
} else if (angleP > 0 && angleR < 0 && angleR > -175) {
buff[0] = (SYM_ARROW_WEST + 2);
} else if (angleP <= 0 && ((angleR > 175 && angleR < 180) || (angleR > -180 && angleR < -175))) {
buff[0] = SYM_ARROW_NORTH;
} else if (angleP <= 0 && angleR > 0 && angleR < 175) {
buff[0] = (SYM_ARROW_NORTH + 2);
} else if (angleP <= 0 && angleR < 0 && angleR > -175) {
buff[0] = (SYM_ARROW_SOUTH + 2);
int rollAngle = attitude.values.roll / 10;
const int pitchAngle = attitude.values.pitch / 10;
if (abs(rollAngle) > 90) {
rollAngle = (rollAngle < 0 ? -180 : 180) - rollAngle;
}

if ((isFlipOverAfterCrashActive() || (!ARMING_FLAG(ARMED) && !STATE(SMALL_ANGLE))) && !((imuConfig()->small_angle < 180) && STATE(SMALL_ANGLE)) && (rollAngle || pitchAngle)) {
if (abs(pitchAngle) < 2 * abs(rollAngle) && abs(rollAngle) < 2 * abs(pitchAngle)) {
if (pitchAngle > 0) {
if (rollAngle > 0) {
buff[0] = SYM_ARROW_WEST + 2;
} else {
buff[0] = SYM_ARROW_EAST - 2;
}
} else {
if (rollAngle > 0) {
buff[0] = SYM_ARROW_WEST - 2;
} else {
buff[0] = SYM_ARROW_EAST + 2;
}
}
} else {
if (abs(pitchAngle) > abs(rollAngle)) {
if (pitchAngle > 0) {
buff[0] = SYM_ARROW_SOUTH;
} else {
buff[0] = SYM_ARROW_NORTH;
}
} else {
if (rollAngle > 0) {
buff[0] = SYM_ARROW_WEST;
} else {
buff[0] = SYM_ARROW_EAST;
}
}
}
} else {
buff[0] = ' ';
}

buff[1] = '\0';
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/test/unit/osd_unittest.cc
Expand Up @@ -89,6 +89,7 @@ extern "C" {
PG_REGISTER(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0);
PG_REGISTER(pilotConfig_t, pilotConfig, PG_PILOT_CONFIG, 0);
PG_REGISTER(gpsRescueConfig_t, gpsRescueConfig, PG_GPS_RESCUE, 0);
PG_REGISTER(imuConfig_t, imuConfig, PG_IMU_CONFIG, 0);

timeUs_t simulationTime = 0;
batteryState_e simulationBatteryState;
Expand Down