diff --git a/flight/libraries/alarms.c b/flight/libraries/alarms.c index 8805ee8a6..db555ad8e 100644 --- a/flight/libraries/alarms.c +++ b/flight/libraries/alarms.c @@ -28,7 +28,6 @@ */ #include -#include #include "inc/alarms.h" // Private constants @@ -83,9 +82,9 @@ int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity SystemAlarmsAlarmGet(&alarms); uint16_t flightTime = (uint16_t)xTaskGetTickCount() * (uint16_t)portTICK_RATE_MS; // this deliberately overflows every 2^16 milliseconds to save memory if (((uint16_t)(flightTime - lastAlarmChange[alarm]) > PIOS_ALARM_GRACETIME && - cast_struct_to_array(alarms, alarms.Actuator)[alarm] != severity) - || cast_struct_to_array(alarms, alarms.Actuator)[alarm] < severity) { - cast_struct_to_array(alarms, alarms.Actuator)[alarm] = severity; + SystemAlarmsAlarmToArray(alarms)[alarm] != severity) + || SystemAlarmsAlarmToArray(alarms)[alarm] < severity) { + SystemAlarmsAlarmToArray(alarms)[alarm] = severity; lastAlarmChange[alarm] = flightTime; SystemAlarmsAlarmSet(&alarms); } @@ -122,11 +121,11 @@ int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsGet(&alarms); uint16_t flightTime = (uint16_t)xTaskGetTickCount() * (uint16_t)portTICK_RATE_MS; // this deliberately overflows every 2^16 milliseconds to save memory if (((uint16_t)(flightTime - lastAlarmChange[alarm]) > PIOS_ALARM_GRACETIME && - cast_struct_to_array(alarms.Alarm, alarms.Alarm.Actuator)[alarm] != severity) - || cast_struct_to_array(alarms.Alarm, alarms.Alarm.Actuator)[alarm] < severity) { - cast_struct_to_array(alarms.ExtendedAlarmStatus, alarms.ExtendedAlarmStatus.BootFault)[alarm] = status; - cast_struct_to_array(alarms.ExtendedAlarmSubStatus, alarms.ExtendedAlarmStatus.BootFault)[alarm] = subStatus; - cast_struct_to_array(alarms.Alarm, alarms.Alarm.Actuator)[alarm] = severity; + SystemAlarmsAlarmToArray(alarms.Alarm)[alarm] != severity) + || SystemAlarmsAlarmToArray(alarms.Alarm)[alarm] < severity) { + SystemAlarmsExtendedAlarmStatusToArray(alarms.ExtendedAlarmStatus)[alarm] = status; + SystemAlarmsExtendedAlarmSubStatusToArray(alarms.ExtendedAlarmSubStatus)[alarm] = subStatus; + SystemAlarmsAlarmToArray(alarms.Alarm)[alarm] = severity; lastAlarmChange[alarm] = flightTime; SystemAlarmsSet(&alarms); } @@ -152,7 +151,7 @@ SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) // Read alarm SystemAlarmsAlarmGet(&alarms); - return cast_struct_to_array(alarms, alarms.Actuator)[alarm]; + return SystemAlarmsAlarmToArray(alarms)[alarm]; } /** @@ -244,7 +243,7 @@ static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) // Go through alarms and check if any are of the given severity or higher for (uint32_t n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { - if (cast_struct_to_array(alarms, alarms.Actuator)[n] >= severity) { + if (SystemAlarmsAlarmToArray(alarms)[n] >= severity) { xSemaphoreGiveRecursive(lock); return 1; } @@ -272,8 +271,8 @@ SystemAlarmsAlarmOptions AlarmsGetHighestSeverity() // Go through alarms and find the highest severity uint32_t n = 0; while (n < SYSTEMALARMS_ALARM_NUMELEM && highest != SYSTEMALARMS_ALARM_CRITICAL) { - if (cast_struct_to_array(alarmsData, alarmsData.Actuator)[n] > highest) { - highest = cast_struct_to_array(alarmsData, alarmsData.Actuator)[n]; + if (SystemAlarmsAlarmToArray(alarmsData)[n] > highest) { + highest = SystemAlarmsAlarmToArray(alarmsData)[n]; } n++; } diff --git a/flight/libraries/notification.c b/flight/libraries/notification.c index 9015e4dd3..2d11d224a 100644 --- a/flight/libraries/notification.c +++ b/flight/libraries/notification.c @@ -25,7 +25,6 @@ */ #include "inc/notification.h" #include -#include #include #include #include diff --git a/flight/modules/CameraStab/camerastab.c b/flight/modules/CameraStab/camerastab.c index 9d479c530..27ba36d28 100644 --- a/flight/modules/CameraStab/camerastab.c +++ b/flight/modules/CameraStab/camerastab.c @@ -52,7 +52,6 @@ #include "camerastabsettings.h" #include "cameradesired.h" #include "hwsettings.h" -#include // // Configuration @@ -172,22 +171,22 @@ static void attitudeUpdated(UAVObjEvent *ev) // process axes for (uint8_t i = 0; i < CAMERASTABSETTINGS_INPUT_NUMELEM; i++) { // read and process control input - if (cast_struct_to_array(cameraStab.Input, cameraStab.Input.Roll)[i] != CAMERASTABSETTINGS_INPUT_NONE) { - if (AccessoryDesiredInstGet(cast_struct_to_array(cameraStab.Input, cameraStab.Input.Roll)[i] - + if (CameraStabSettingsInputToArray(cameraStab.Input)[i] != CAMERASTABSETTINGS_INPUT_NONE) { + if (AccessoryDesiredInstGet(CameraStabSettingsInputToArray(cameraStab.Input)[i] - CAMERASTABSETTINGS_INPUT_ACCESSORY0, &accessory) == 0) { float input_rate; - switch (cast_struct_to_array(cameraStab.StabilizationMode, cameraStab.StabilizationMode.Roll)[i]) { + switch (CameraStabSettingsStabilizationModeToArray(cameraStab.StabilizationMode)[i]) { case CAMERASTABSETTINGS_STABILIZATIONMODE_ATTITUDE: csd->inputs[i] = accessory.AccessoryVal * - cast_struct_to_array(cameraStab.InputRange, cameraStab.InputRange.Roll)[i]; + CameraStabSettingsInputRangeToArray(cameraStab.InputRange)[i]; break; case CAMERASTABSETTINGS_STABILIZATIONMODE_AXISLOCK: input_rate = accessory.AccessoryVal * - cast_struct_to_array(cameraStab.InputRate, cameraStab.InputRate.Roll)[i]; + CameraStabSettingsInputRateToArray(cameraStab.InputRate)[i]; if (fabsf(input_rate) > cameraStab.MaxAxisLockRate) { csd->inputs[i] = boundf(csd->inputs[i] + input_rate * 0.001f * dT_millis, - -cast_struct_to_array(cameraStab.InputRange, cameraStab.InputRange.Roll)[i], - cast_struct_to_array(cameraStab.InputRange, cameraStab.InputRange.Roll)[i]); + -CameraStabSettingsInputRangeToArray(cameraStab.InputRange)[i], + CameraStabSettingsInputRangeToArray(cameraStab.InputRange)[i]); } break; default: @@ -214,14 +213,14 @@ static void attitudeUpdated(UAVObjEvent *ev) } #ifdef USE_GIMBAL_LPF - if (cast_struct_to_array(cameraStab.ResponseTime, cameraStab.ResponseTime.Roll)[i]) { - float rt = (float)cast_struct_to_array(cameraStab.ResponseTime, cameraStab.ResponseTime.Roll)[i]; + if (CameraStabSettingsResponseTimeToArray(cameraStab.ResponseTime)[i]) { + float rt = (float)CameraStabSettingsResponseTimeToArray(cameraStab.ResponseTime)[i]; attitude = csd->attitudeFiltered[i] = ((rt * csd->attitudeFiltered[i]) + (dT_millis * attitude)) / (rt + dT_millis); } #endif #ifdef USE_GIMBAL_FF - if (cast_struct_to_array(cameraStab.FeedForward, cameraStab.FeedForward.Roll)[i]) { + if (CameraStabSettingsFeedForwardToArray(cameraStab.FeedForward)[i]) { applyFeedForward(i, dT_millis, &attitude, &cameraStab); } #endif @@ -229,7 +228,7 @@ static void attitudeUpdated(UAVObjEvent *ev) // bounding for elevon mixing occurs on the unmixed output // to limit the range of the mixed output you must limit the range // of both the unmixed pitch and unmixed roll - float output = boundf((attitude + csd->inputs[i]) / cast_struct_to_array(cameraStab.OutputRange, cameraStab.OutputRange.Roll)[i], -1.0f, 1.0f); + float output = boundf((attitude + csd->inputs[i]) / CameraStabSettingsOutputRangeToArray(cameraStab.OutputRange)[i], -1.0f, 1.0f); // set output channels switch (i) { @@ -316,12 +315,12 @@ void applyFeedForward(uint8_t index, float dT_millis, float *attitude, CameraSta // apply feed forward float accumulator = csd->ffFilterAccumulator[index]; accumulator += (*attitude - csd->ffLastAttitude[index]) * - (float)cast_struct_to_array(cameraStab->FeedForward, cameraStab->FeedForward.Roll)[index] * gimbalTypeCorrection; + (float)CameraStabSettingsFeedForwardToArray(cameraStab->FeedForward)[index] * gimbalTypeCorrection; csd->ffLastAttitude[index] = *attitude; *attitude += accumulator; - float filter = (float)((accumulator > 0.0f) ? cast_struct_to_array(cameraStab->AccelTime, cameraStab->AccelTime.Roll)[index] : - cast_struct_to_array(cameraStab->DecelTime, cameraStab->DecelTime.Roll)[index]) / dT_millis; + float filter = (float)((accumulator > 0.0f) ? CameraStabSettingsAccelTimeToArray(cameraStab->AccelTime)[index] : + CameraStabSettingsDecelTimeToArray(cameraStab->DecelTime)[index]) / dT_millis; if (filter < 1.0f) { filter = 1.0f; } diff --git a/flight/modules/ComUsbBridge/ComUsbBridge.c b/flight/modules/ComUsbBridge/ComUsbBridge.c index 5c0541b80..ad3cad4ce 100644 --- a/flight/modules/ComUsbBridge/ComUsbBridge.c +++ b/flight/modules/ComUsbBridge/ComUsbBridge.c @@ -42,7 +42,7 @@ static void com2UsbBridgeTask(void *parameters); static void usb2ComBridgeTask(void *parameters); -static void updateSettings(); +static void updateSettings(UAVObjEvent *ev); // **************** // Private constants @@ -106,8 +106,7 @@ static int32_t comUsbBridgeInitialize(void) HwSettingsOptionalModulesGet(&optionalModules); - if (usart_port && vcp_port && - (optionalModules.ComUsbBridge == HWSETTINGS_OPTIONALMODULES_ENABLED)) { + if (usart_port && vcp_port) { bridge_enabled = true; } else { bridge_enabled = false; @@ -119,8 +118,8 @@ static int32_t comUsbBridgeInitialize(void) PIOS_Assert(com2usb_buf); usb2com_buf = pios_malloc(BRIDGE_BUF_LEN); PIOS_Assert(usb2com_buf); - - updateSettings(); + HwSettingsConnectCallback(&updateSettings); + updateSettings(0); } return 0; @@ -170,7 +169,7 @@ static void usb2ComBridgeTask(__attribute__((unused)) void *parameters) } -static void updateSettings() +static void updateSettings(__attribute__((unused)) UAVObjEvent *ev) { if (usart_port) { // Retrieve settings diff --git a/flight/modules/ManualControl/armhandler.c b/flight/modules/ManualControl/armhandler.c index 7dbf79336..dbaefa779 100644 --- a/flight/modules/ManualControl/armhandler.c +++ b/flight/modules/ManualControl/armhandler.c @@ -29,7 +29,6 @@ */ #include "inc/manualcontrol.h" -#include #include #include #include @@ -259,7 +258,7 @@ static bool okToArm(void) // Check each alarm for (int i = 0; i < SYSTEMALARMS_ALARM_NUMELEM; i++) { - if (cast_struct_to_array(alarms.Alarm, alarms.Alarm.Actuator)[i] >= SYSTEMALARMS_ALARM_CRITICAL) { // found an alarm thats set + if (SystemAlarmsAlarmToArray(alarms.Alarm)[i] >= SYSTEMALARMS_ALARM_CRITICAL) { // found an alarm thats set if (i == SYSTEMALARMS_ALARM_GPS || i == SYSTEMALARMS_ALARM_TELEMETRY) { continue; } diff --git a/flight/modules/ManualControl/stabilizedhandler.c b/flight/modules/ManualControl/stabilizedhandler.c index 2ab4222f9..582929425 100644 --- a/flight/modules/ManualControl/stabilizedhandler.c +++ b/flight/modules/ManualControl/stabilizedhandler.c @@ -29,7 +29,6 @@ */ #include "inc/manualcontrol.h" -#include #include #include #include @@ -70,27 +69,27 @@ void stabilizedHandler(bool newinit) FlightStatusGet(&flightStatus); switch (flightStatus.FlightMode) { case FLIGHTSTATUS_FLIGHTMODE_STABILIZED1: - stab_settings = cast_struct_to_array(settings.Stabilization1Settings, settings.Stabilization1Settings.Roll); + stab_settings = FlightModeSettingsStabilization1SettingsToArray(settings.Stabilization1Settings); break; case FLIGHTSTATUS_FLIGHTMODE_STABILIZED2: - stab_settings = cast_struct_to_array(settings.Stabilization2Settings, settings.Stabilization2Settings.Roll); + stab_settings = FlightModeSettingsStabilization2SettingsToArray(settings.Stabilization2Settings); break; case FLIGHTSTATUS_FLIGHTMODE_STABILIZED3: - stab_settings = cast_struct_to_array(settings.Stabilization3Settings, settings.Stabilization3Settings.Roll); + stab_settings = FlightModeSettingsStabilization3SettingsToArray(settings.Stabilization3Settings); break; case FLIGHTSTATUS_FLIGHTMODE_STABILIZED4: - stab_settings = cast_struct_to_array(settings.Stabilization4Settings, settings.Stabilization4Settings.Roll); + stab_settings = FlightModeSettingsStabilization4SettingsToArray(settings.Stabilization4Settings); break; case FLIGHTSTATUS_FLIGHTMODE_STABILIZED5: - stab_settings = cast_struct_to_array(settings.Stabilization5Settings, settings.Stabilization5Settings.Roll); + stab_settings = FlightModeSettingsStabilization5SettingsToArray(settings.Stabilization5Settings); break; case FLIGHTSTATUS_FLIGHTMODE_STABILIZED6: - stab_settings = cast_struct_to_array(settings.Stabilization6Settings, settings.Stabilization6Settings.Roll); + stab_settings = FlightModeSettingsStabilization6SettingsToArray(settings.Stabilization6Settings); break; default: // Major error, this should not occur because only enter this block when one of these is true AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); - stab_settings = cast_struct_to_array(settings.Stabilization1Settings, settings.Stabilization1Settings.Roll); + stab_settings = FlightModeSettingsStabilization1SettingsToArray(settings.Stabilization1Settings); return; } diff --git a/flight/modules/PathFollower/pathfollower.c b/flight/modules/PathFollower/pathfollower.c index 67226589b..039e85722 100644 --- a/flight/modules/PathFollower/pathfollower.c +++ b/flight/modules/PathFollower/pathfollower.c @@ -51,7 +51,6 @@ #include #include #include -#include #include #include #include diff --git a/flight/modules/PathPlanner/pathplanner.c b/flight/modules/PathPlanner/pathplanner.c index 32d2afbae..2ab9f1a61 100644 --- a/flight/modules/PathPlanner/pathplanner.c +++ b/flight/modules/PathPlanner/pathplanner.c @@ -43,7 +43,6 @@ #include "waypoint.h" #include "waypointactive.h" #include "flightmodesettings.h" -#include #include "paths.h" #include "plans.h" diff --git a/flight/modules/Receiver/receiver.c b/flight/modules/Receiver/receiver.c index 6f79ba16d..cf3230751 100644 --- a/flight/modules/Receiver/receiver.c +++ b/flight/modules/Receiver/receiver.c @@ -33,7 +33,6 @@ */ #include -#include #include #include #include @@ -210,12 +209,12 @@ static void receiverTask(__attribute__((unused)) void *parameters) for (uint8_t n = 0; n < MANUALCONTROLSETTINGS_CHANNELGROUPS_NUMELEM && n < MANUALCONTROLCOMMAND_CHANNEL_NUMELEM; ++n) { extern uint32_t pios_rcvr_group_map[]; - if (cast_struct_to_array(settings.ChannelGroups, settings.ChannelGroups.Roll)[n] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) { + if (ManualControlSettingsChannelGroupsToArray(settings.ChannelGroups)[n] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) { cmd.Channel[n] = PIOS_RCVR_INVALID; } else { cmd.Channel[n] = PIOS_RCVR_Read(pios_rcvr_group_map[ - cast_struct_to_array(settings.ChannelGroups, settings.ChannelGroups.Pitch)[n]], - cast_struct_to_array(settings.ChannelNumber, settings.ChannelNumber.Pitch)[n]); + ManualControlSettingsChannelGroupsToArray(settings.ChannelGroups)[n]], + ManualControlSettingsChannelNumberToArray(settings.ChannelNumber)[n]); } // If a channel has timed out this is not valid data and we shouldn't update anything @@ -224,9 +223,9 @@ static void receiverTask(__attribute__((unused)) void *parameters) valid_input_detected = false; } else { scaledChannel[n] = scaleChannel(cmd.Channel[n], - cast_struct_to_array(settings.ChannelMax, settings.ChannelMax.Pitch)[n], - cast_struct_to_array(settings.ChannelMin, settings.ChannelMin.Pitch)[n], - cast_struct_to_array(settings.ChannelNeutral, settings.ChannelNeutral.Pitch)[n]); + ManualControlSettingsChannelMaxToArray(settings.ChannelMax)[n], + ManualControlSettingsChannelMinToArray(settings.ChannelMin)[n], + ManualControlSettingsChannelNeutralToArray(settings.ChannelNeutral)[n]); } } @@ -445,8 +444,8 @@ static void receiverTask(__attribute__((unused)) void *parameters) if (pios_usb_rctx_id) { PIOS_USB_RCTX_Update(pios_usb_rctx_id, cmd.Channel, - cast_struct_to_array(settings.ChannelMin, settings.ChannelMin.Roll), - cast_struct_to_array(settings.ChannelMax, settings.ChannelMax.Roll), + ManualControlSettingsChannelMinToArray(settings.ChannelMin), + ManualControlSettingsChannelMaxToArray(settings.ChannelMax), NELEMENTS(cmd.Channel)); } #endif /* PIOS_INCLUDE_USB_RCTX */ @@ -661,8 +660,8 @@ static void applyDeadband(float *value, float deadband) */ static void applyLPF(float *value, ManualControlSettingsResponseTimeElem channel, ManualControlSettingsData *settings, float dT) { - if (cast_struct_to_array(settings->ResponseTime, settings->ResponseTime.Roll)[channel]) { - float rt = (float)cast_struct_to_array(settings->ResponseTime, settings->ResponseTime.Roll)[channel]; + if (ManualControlSettingsResponseTimeToArray(settings->ResponseTime)[channel]) { + float rt = (float)ManualControlSettingsResponseTimeToArray(settings->ResponseTime)[channel]; inputFiltered[channel] = ((rt * inputFiltered[channel]) + (dT * (*value))) / (rt + dT); *value = inputFiltered[channel]; } diff --git a/flight/modules/Sensors/sensors.c b/flight/modules/Sensors/sensors.c index b24e34317..fb51af90e 100644 --- a/flight/modules/Sensors/sensors.c +++ b/flight/modules/Sensors/sensors.c @@ -62,7 +62,6 @@ #include #include -#include // Private constants #define STACK_SIZE_BYTES 1000 @@ -495,7 +494,7 @@ static void settingsUpdatedCb(__attribute__((unused)) UAVObjEvent *objEv) } else { Quaternion2R(rotationQuat, R); } - matrix_mult_3x3f((float(*)[3])cast_struct_to_array(cal.mag_transform, cal.mag_transform.r0c0), R, mag_transform); + matrix_mult_3x3f((float(*)[3])RevoCalibrationmag_transformToArray(cal.mag_transform), R, mag_transform); } /** * @} diff --git a/flight/modules/Stabilization/inc/stabilization.h b/flight/modules/Stabilization/inc/stabilization.h index 8314ae97e..44ab8917c 100644 --- a/flight/modules/Stabilization/inc/stabilization.h +++ b/flight/modules/Stabilization/inc/stabilization.h @@ -76,7 +76,7 @@ extern StabilizationData stabSettings; // must be same as eventdispatcher to avoid needing additional mutexes #define CBTASK_PRIORITY CALLBACK_TASK_FLIGHTCONTROL -// outer loop only executes every 4th uavobject update to safe CPU +// outer loop only executes every 4th uavobject update to save CPU #define OUTERLOOP_SKIPCOUNT 4 #endif // STABILIZATION_H diff --git a/flight/modules/Stabilization/innerloop.c b/flight/modules/Stabilization/innerloop.c index e7254b933..68d6499da 100644 --- a/flight/modules/Stabilization/innerloop.c +++ b/flight/modules/Stabilization/innerloop.c @@ -32,7 +32,6 @@ */ #include -#include #include #include #include @@ -165,21 +164,21 @@ static void stabilizationInnerloopTask() dT = PIOS_DELTATIME_GetAverageSeconds(&timeval); for (t = 0; t < AXES; t++) { - bool reinit = (cast_struct_to_array(enabled, enabled.Roll)[t] != previous_mode[t]); - previous_mode[t] = cast_struct_to_array(enabled, enabled.Roll)[t]; + bool reinit = (StabilizationStatusInnerLoopToArray(enabled)[t] != previous_mode[t]); + previous_mode[t] = StabilizationStatusInnerLoopToArray(enabled)[t]; if (t < STABILIZATIONSTATUS_INNERLOOP_THRUST) { if (reinit) { stabSettings.innerPids[t].iAccumulator = 0; } - switch (cast_struct_to_array(enabled, enabled.Roll)[t]) { + switch (StabilizationStatusInnerLoopToArray(enabled)[t]) { case STABILIZATIONSTATUS_INNERLOOP_VIRTUALFLYBAR: stabilization_virtual_flybar(gyro_filtered[t], rate[t], &actuatorDesiredAxis[t], dT, reinit, t, &stabSettings.settings); break; case STABILIZATIONSTATUS_INNERLOOP_RELAYTUNING: rate[t] = boundf(rate[t], - -cast_struct_to_array(stabSettings.stabBank.MaximumRate, stabSettings.stabBank.MaximumRate.Roll)[t], - cast_struct_to_array(stabSettings.stabBank.MaximumRate, stabSettings.stabBank.MaximumRate.Roll)[t] + -StabilizationBankMaximumRateToArray(stabSettings.stabBank.MaximumRate)[t], + StabilizationBankMaximumRateToArray(stabSettings.stabBank.MaximumRate)[t] ); stabilization_relay_rate(rate[t] - gyro_filtered[t], &actuatorDesiredAxis[t], t, reinit); break; @@ -198,8 +197,8 @@ static void stabilizationInnerloopTask() case STABILIZATIONSTATUS_INNERLOOP_RATE: // limit rate to maximum configured limits (once here instead of 5 times in outer loop) rate[t] = boundf(rate[t], - -cast_struct_to_array(stabSettings.stabBank.MaximumRate, stabSettings.stabBank.MaximumRate.Roll)[t], - cast_struct_to_array(stabSettings.stabBank.MaximumRate, stabSettings.stabBank.MaximumRate.Roll)[t] + -StabilizationBankMaximumRateToArray(stabSettings.stabBank.MaximumRate)[t], + StabilizationBankMaximumRateToArray(stabSettings.stabBank.MaximumRate)[t] ); actuatorDesiredAxis[t] = pid_apply_setpoint(&stabSettings.innerPids[t], speedScaleFactor, rate[t], gyro_filtered[t], dT); break; @@ -209,7 +208,7 @@ static void stabilizationInnerloopTask() break; } } else { - switch (cast_struct_to_array(enabled, enabled.Roll)[t]) { + switch (StabilizationStatusInnerLoopToArray(enabled)[t]) { case STABILIZATIONSTATUS_INNERLOOP_CRUISECONTROL: actuatorDesiredAxis[t] = cruisecontrol_apply_factor(rate[t]); break; diff --git a/flight/modules/Stabilization/outerloop.c b/flight/modules/Stabilization/outerloop.c index 7d865b556..a1f8d37c1 100644 --- a/flight/modules/Stabilization/outerloop.c +++ b/flight/modules/Stabilization/outerloop.c @@ -32,7 +32,6 @@ */ #include -#include #include #include #include @@ -115,7 +114,7 @@ static void stabilizationOuterloopTask() float q_error[4]; for (t = 0; t < 3; t++) { - switch (cast_struct_to_array(enabled, enabled.Roll)[t]) { + switch (StabilizationStatusOuterLoopToArray(enabled)[t]) { case STABILIZATIONSTATUS_OUTERLOOP_ATTITUDE: case STABILIZATIONSTATUS_OUTERLOOP_RATTITUDE: case STABILIZATIONSTATUS_OUTERLOOP_WEAKLEVELING: @@ -150,14 +149,14 @@ static void stabilizationOuterloopTask() #endif /* if defined(PIOS_QUATERNION_STABILIZATION) */ } for (t = 0; t < AXES; t++) { - bool reinit = (cast_struct_to_array(enabled, enabled.Roll)[t] != previous_mode[t]); - previous_mode[t] = cast_struct_to_array(enabled, enabled.Roll)[t]; + bool reinit = (StabilizationStatusOuterLoopToArray(enabled)[t] != previous_mode[t]); + previous_mode[t] = StabilizationStatusOuterLoopToArray(enabled)[t]; if (t < STABILIZATIONSTATUS_OUTERLOOP_THRUST) { if (reinit) { stabSettings.outerPids[t].iAccumulator = 0; } - switch (cast_struct_to_array(enabled, enabled.Roll)[t]) { + switch (StabilizationStatusOuterLoopToArray(enabled)[t]) { case STABILIZATIONSTATUS_OUTERLOOP_ATTITUDE: rateDesiredAxis[t] = pid_apply(&stabSettings.outerPids[t], local_error[t], dT); break; @@ -167,11 +166,11 @@ static void stabilizationOuterloopTask() stickinput[0] = boundf(stabilizationDesiredAxis[0] / stabSettings.stabBank.RollMax, -1.0f, 1.0f); stickinput[1] = boundf(stabilizationDesiredAxis[1] / stabSettings.stabBank.PitchMax, -1.0f, 1.0f); stickinput[2] = boundf(stabilizationDesiredAxis[2] / stabSettings.stabBank.YawMax, -1.0f, 1.0f); - float rateDesiredAxisRate = stickinput[t] * cast_struct_to_array(stabSettings.stabBank.ManualRate, stabSettings.stabBank.ManualRate.Roll)[t]; + float rateDesiredAxisRate = stickinput[t] * StabilizationBankManualRateToArray(stabSettings.stabBank.ManualRate)[t]; // limit corrective rate to maximum rates to not give it overly large impact over manual rate when joined together rateDesiredAxis[t] = boundf(pid_apply(&stabSettings.outerPids[t], local_error[t], dT), - -cast_struct_to_array(stabSettings.stabBank.ManualRate, stabSettings.stabBank.ManualRate.Roll)[t], - cast_struct_to_array(stabSettings.stabBank.ManualRate, stabSettings.stabBank.ManualRate.Roll)[t] + -StabilizationBankManualRateToArray(stabSettings.stabBank.ManualRate)[t], + StabilizationBankManualRateToArray(stabSettings.stabBank.ManualRate)[t] ); // Compute the weighted average rate desired // Using max() rather than sqrt() for cpu speed; @@ -232,7 +231,7 @@ static void stabilizationOuterloopTask() stickinput[0] = boundf(stabilizationDesiredAxis[0] / stabSettings.stabBank.RollMax, -1.0f, 1.0f); stickinput[1] = boundf(stabilizationDesiredAxis[1] / stabSettings.stabBank.PitchMax, -1.0f, 1.0f); stickinput[2] = boundf(stabilizationDesiredAxis[2] / stabSettings.stabBank.YawMax, -1.0f, 1.0f); - float rate_input = stickinput[t] * cast_struct_to_array(stabSettings.stabBank.ManualRate, stabSettings.stabBank.ManualRate.Roll)[t]; + float rate_input = stickinput[t] * StabilizationBankManualRateToArray(stabSettings.stabBank.ManualRate)[t]; float weak_leveling = local_error[t] * stabSettings.settings.WeakLevelingKp; weak_leveling = boundf(weak_leveling, -stabSettings.settings.MaxWeakLevelingRate, stabSettings.settings.MaxWeakLevelingRate); @@ -246,7 +245,7 @@ static void stabilizationOuterloopTask() break; } } else { - switch (cast_struct_to_array(enabled, enabled.Roll)[t]) { + switch (StabilizationStatusOuterLoopToArray(enabled)[t]) { #ifdef REVOLUTION case STABILIZATIONSTATUS_OUTERLOOP_ALTITUDE: rateDesiredAxis[t] = stabilizationAltitudeHold(stabilizationDesiredAxis[t], ALTITUDEHOLD, reinit); @@ -286,10 +285,10 @@ static void stabilizationOuterloopTask() static void AttitudeStateUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { - // to reduce CPU utilisation, outer loop is not executed every state update - static uint8_t cpusafer = 0; + // to reduce CPU utilization, outer loop is not executed on every state update + static uint8_t cpusaver = 0; - if ((cpusafer++ % OUTERLOOP_SKIPCOUNT) == 0) { + if ((cpusaver++ % OUTERLOOP_SKIPCOUNT) == 0) { // this does not need mutex protection as both eventdispatcher and stabi run in same callback task! AttitudeStateGet(&attitude); PIOS_CALLBACKSCHEDULER_Dispatch(callbackHandle); diff --git a/flight/modules/Stabilization/relay_tuning.c b/flight/modules/Stabilization/relay_tuning.c index 316340f1b..d4e4c8320 100644 --- a/flight/modules/Stabilization/relay_tuning.c +++ b/flight/modules/Stabilization/relay_tuning.c @@ -32,7 +32,6 @@ */ #include "openpilot.h" -#include #include "stabilization.h" #include "relaytuning.h" #include "relaytuningsettings.h" @@ -72,8 +71,8 @@ int stabilization_relay_rate(float error, float *output, int axis, bool reinit) // On first run initialize estimates to something reasonable if (reinit) { rateRelayRunning[axis] = false; - cast_struct_to_array(relay.Period, relay.Period.Roll)[axis] = 200; - cast_struct_to_array(relay.Gain, relay.Gain.Roll)[axis] = 0; + RelayTuningPeriodToArray(relay.Period)[axis] = 200; + RelayTuningGainToArray(relay.Gain)[axis] = 0; accum_sin = 0; accum_cos = 0; @@ -96,14 +95,14 @@ int stabilization_relay_rate(float error, float *output, int axis, bool reinit) /**** The code below here is to estimate the properties of the oscillation ****/ // Make sure the period can't go below limit - if (cast_struct_to_array(relay.Period, relay.Period.Roll)[axis] < DEGLITCH_TIME) { - cast_struct_to_array(relay.Period, relay.Period.Roll)[axis] = DEGLITCH_TIME; + if (RelayTuningPeriodToArray(relay.Period)[axis] < DEGLITCH_TIME) { + RelayTuningPeriodToArray(relay.Period)[axis] = DEGLITCH_TIME; } // Project the error onto a sine and cosine of the same frequency // to accumulate the average amplitude int32_t dT = thisTime - lastHighTime; - float phase = ((float)360 * (float)dT) / cast_struct_to_array(relay.Period, relay.Period.Roll)[axis]; + float phase = ((float)360 * (float)dT) / RelayTuningPeriodToArray(relay.Period)[axis]; if (phase >= 360) { phase = 0; } @@ -126,15 +125,15 @@ int stabilization_relay_rate(float error, float *output, int axis, bool reinit) if (rateRelayRunning[axis] == false) { rateRelayRunning[axis] = true; - cast_struct_to_array(relay.Period, relay.Period.Roll)[axis] = 200; - cast_struct_to_array(relay.Gain, relay.Gain.Roll)[axis] = 0; + RelayTuningPeriodToArray(relay.Period)[axis] = 200; + RelayTuningGainToArray(relay.Gain)[axis] = 0; } else { // Low pass filter each amplitude and period - cast_struct_to_array(relay.Gain, relay.Gain.Roll)[axis] = - cast_struct_to_array(relay.Gain, relay.Gain.Roll)[axis] * + RelayTuningGainToArray(relay.Gain)[axis] = + RelayTuningGainToArray(relay.Gain)[axis] * AMPLITUDE_ALPHA + this_gain * (1 - AMPLITUDE_ALPHA); - cast_struct_to_array(relay.Period, relay.Period.Roll)[axis] = - cast_struct_to_array(relay.Period, relay.Period.Roll)[axis] * + RelayTuningPeriodToArray(relay.Period)[axis] = + RelayTuningPeriodToArray(relay.Period)[axis] * PERIOD_ALPHA + dT * (1 - PERIOD_ALPHA); } lastHighTime = thisTime; diff --git a/flight/modules/Stabilization/stabilization.c b/flight/modules/Stabilization/stabilization.c index 92b9081d0..202a5c89f 100644 --- a/flight/modules/Stabilization/stabilization.c +++ b/flight/modules/Stabilization/stabilization.c @@ -33,7 +33,6 @@ #include -#include #include #include #include @@ -134,54 +133,54 @@ static void StabilizationDesiredUpdatedCb(__attribute__((unused)) UAVObjEvent *e StabilizationDesiredStabilizationModeGet(&mode); for (t = 0; t < AXES; t++) { - switch (cast_struct_to_array(mode, mode.Roll)[t]) { + switch (StabilizationDesiredStabilizationModeToArray(mode)[t]) { case STABILIZATIONDESIRED_STABILIZATIONMODE_MANUAL: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_DIRECT; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_DIRECT; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_RATE: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_ATTITUDE; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_ATTITUDE; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_AXISLOCK: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_AXISLOCK; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_AXISLOCK; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_WEAKLEVELING: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_WEAKLEVELING; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_WEAKLEVELING; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_VIRTUALBAR: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_VIRTUALFLYBAR; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_VIRTUALFLYBAR; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_RATTITUDE: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_RATTITUDE; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_RATTITUDE; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_RATE; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_RELAYRATE: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_RELAYTUNING; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_RELAYTUNING; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_RELAYATTITUDE: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_ATTITUDE; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_RELAYTUNING; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_ATTITUDE; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_RELAYTUNING; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_ALTITUDEHOLD: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_ALTITUDE; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_CRUISECONTROL; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_ALTITUDE; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_CRUISECONTROL; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_ALTITUDEVARIO: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_ALTITUDEVARIO; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_CRUISECONTROL; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_ALTITUDEVARIO; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_CRUISECONTROL; break; case STABILIZATIONDESIRED_STABILIZATIONMODE_CRUISECONTROL: - cast_struct_to_array(status.OuterLoop, status.OuterLoop.Roll)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; - cast_struct_to_array(status.InnerLoop, status.InnerLoop.Roll)[t] = STABILIZATIONSTATUS_INNERLOOP_CRUISECONTROL; + StabilizationStatusOuterLoopToArray(status.OuterLoop)[t] = STABILIZATIONSTATUS_OUTERLOOP_DIRECT; + StabilizationStatusInnerLoopToArray(status.InnerLoop)[t] = STABILIZATIONSTATUS_INNERLOOP_CRUISECONTROL; break; } } diff --git a/flight/modules/Stabilization/virtualflybar.c b/flight/modules/Stabilization/virtualflybar.c index cc1a284f1..a815fe034 100644 --- a/flight/modules/Stabilization/virtualflybar.c +++ b/flight/modules/Stabilization/virtualflybar.c @@ -32,7 +32,6 @@ #include "openpilot.h" #include -#include #include "stabilization.h" #include "stabilizationsettings.h" @@ -78,7 +77,7 @@ int stabilization_virtual_flybar(float gyro, float command, float *output, float } // Command signal is composed of stick input added to the gyro and virtual flybar - *output = command * cast_struct_to_array(settings->VbarSensitivity, settings->VbarSensitivity.Roll)[axis] - + *output = command * StabilizationSettingsVbarSensitivityToArray(settings->VbarSensitivity)[axis] - gyro_gain * (vbar_integral[axis] * ki + gyro * kp); return 0; diff --git a/flight/modules/StateEstimation/filterekf.c b/flight/modules/StateEstimation/filterekf.c index 320a9ef35..3931226e4 100644 --- a/flight/modules/StateEstimation/filterekf.c +++ b/flight/modules/StateEstimation/filterekf.c @@ -31,7 +31,6 @@ */ #include "inc/stateestimation.h" -#include #include #include @@ -165,17 +164,17 @@ static int32_t maininit(stateFilter *self) int t; // plausibility check for (t = 0; t < EKFCONFIGURATION_P_NUMELEM; t++) { - if (invalid_var(cast_struct_to_array(this->ekfConfiguration.P, this->ekfConfiguration.P.AttitudeQ1)[t])) { + if (invalid_var(EKFConfigurationPToArray(this->ekfConfiguration.P)[t])) { return 2; } } for (t = 0; t < EKFCONFIGURATION_Q_NUMELEM; t++) { - if (invalid_var(cast_struct_to_array(this->ekfConfiguration.Q, this->ekfConfiguration.Q.AccelX)[t])) { + if (invalid_var(EKFConfigurationQToArray(this->ekfConfiguration.Q)[t])) { return 2; } } for (t = 0; t < EKFCONFIGURATION_R_NUMELEM; t++) { - if (invalid_var(cast_struct_to_array(this->ekfConfiguration.R, this->ekfConfiguration.R.BaroZ)[t])) { + if (invalid_var(EKFConfigurationRToArray(this->ekfConfiguration.R)[t])) { return 2; } } @@ -295,7 +294,7 @@ static filterResult filter(stateFilter *self, stateEstimation *state) INSSetState(this->work.pos, (float *)zeros, this->work.attitude, (float *)zeros, (float *)zeros); - INSResetP(cast_struct_to_array(this->ekfConfiguration.P, this->ekfConfiguration.P.AttitudeQ1)); + INSResetP(EKFConfigurationPToArray(this->ekfConfiguration.P)); } else { // Run prediction a bit before any corrections @@ -422,12 +421,12 @@ static filterResult filter(stateFilter *self, stateEstimation *state) EKFStateVarianceData vardata; EKFStateVarianceGet(&vardata); - INSGetP(cast_struct_to_array(vardata.P, vardata.P.AttitudeQ1)); + INSGetP(EKFStateVariancePToArray(vardata.P)); EKFStateVarianceSet(&vardata); int t; for (t = 0; t < EKFSTATEVARIANCE_P_NUMELEM; t++) { - if (!IS_REAL(cast_struct_to_array(vardata.P, vardata.P.AttitudeQ1)[t]) || cast_struct_to_array(vardata.P, vardata.P.AttitudeQ1)[t] <= 0.0f) { - INSResetP(cast_struct_to_array(this->ekfConfiguration.P, this->ekfConfiguration.P.AttitudeQ1)); + if (!IS_REAL(EKFStateVariancePToArray(vardata.P)[t]) || EKFStateVariancePToArray(vardata.P)[t] <= 0.0f) { + INSResetP(EKFConfigurationPToArray(this->ekfConfiguration.P)); this->init_stage = -1; break; } diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index aa6a8f54d..97ff55f3d 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -39,7 +39,6 @@ */ #include -#include // private includes #include "inc/systemmod.h" #include "notification.h" @@ -420,9 +419,9 @@ static void taskMonitorForEachCallback(uint16_t task_id, const struct pios_task_ // By convention, there is a direct mapping between task monitor task_id's and members // of the TaskInfoXXXXElem enums PIOS_DEBUG_Assert(task_id < TASKINFO_RUNNING_NUMELEM); - cast_struct_to_array(taskData->Running, taskData->Running.System)[task_id] = task_info->is_running ? TASKINFO_RUNNING_TRUE : TASKINFO_RUNNING_FALSE; - ((uint16_t *)&taskData->StackRemaining)[task_id] = task_info->stack_remaining; - ((uint8_t *)&taskData->RunningTime)[task_id] = task_info->running_time_percentage; + TaskInfoRunningToArray(taskData->Running)[task_id] = task_info->is_running ? TASKINFO_RUNNING_TRUE : TASKINFO_RUNNING_FALSE; + ((uint16_t *)&taskData->StackRemaining)[task_id] = task_info->stack_remaining; + ((uint8_t *)&taskData->RunningTime)[task_id] = task_info->running_time_percentage; } static void callbackSchedulerForEachCallback(int16_t callback_id, const struct pios_callback_info *callback_info, void *context) diff --git a/flight/modules/TxPID/txpid.c b/flight/modules/TxPID/txpid.c index 20670ae1b..a1e5fd995 100644 --- a/flight/modules/TxPID/txpid.c +++ b/flight/modules/TxPID/txpid.c @@ -51,7 +51,6 @@ */ #include "openpilot.h" -#include #include "txpidsettings.h" #include "accessorydesired.h" #include "manualcontrolcommand.h" @@ -195,26 +194,26 @@ static void updatePIDs(UAVObjEvent *ev) // Loop through every enabled instance for (uint8_t i = 0; i < TXPIDSETTINGS_PIDS_NUMELEM; i++) { - if (cast_struct_to_array(inst.PIDs, inst.PIDs.Instance1)[i] != TXPIDSETTINGS_PIDS_DISABLED) { + if (TxPIDSettingsPIDsToArray(inst.PIDs)[i] != TXPIDSETTINGS_PIDS_DISABLED) { float value; - if (cast_struct_to_array(inst.Inputs, inst.Inputs.Instance1)[i] == TXPIDSETTINGS_INPUTS_THROTTLE) { + if (TxPIDSettingsInputsToArray(inst.Inputs)[i] == TXPIDSETTINGS_INPUTS_THROTTLE) { ManualControlCommandThrottleGet(&value); value = scale(value, inst.ThrottleRange.Min, inst.ThrottleRange.Max, - cast_struct_to_array(inst.MinPID, inst.MinPID.Instance1)[i], - cast_struct_to_array(inst.MaxPID, inst.MaxPID.Instance1)[i]); + TxPIDSettingsMinPIDToArray(inst.MinPID)[i], + TxPIDSettingsMaxPIDToArray(inst.MaxPID)[i]); } else if (AccessoryDesiredInstGet( - cast_struct_to_array(inst.Inputs, inst.Inputs.Instance1)[i] - TXPIDSETTINGS_INPUTS_ACCESSORY0, + TxPIDSettingsInputsToArray(inst.Inputs)[i] - TXPIDSETTINGS_INPUTS_ACCESSORY0, &accessory) == 0) { value = scale(accessory.AccessoryVal, -1.0f, 1.0f, - cast_struct_to_array(inst.MinPID, inst.MinPID.Instance1)[i], - cast_struct_to_array(inst.MaxPID, inst.MaxPID.Instance1)[i]); + TxPIDSettingsMinPIDToArray(inst.MinPID)[i], + TxPIDSettingsMaxPIDToArray(inst.MaxPID)[i]); } else { continue; } - switch (cast_struct_to_array(inst.PIDs, inst.PIDs.Instance1)[i]) { + switch (TxPIDSettingsPIDsToArray(inst.PIDs)[i]) { case TXPIDSETTINGS_PIDS_ROLLRATEKP: needsUpdateBank |= update(&bank.RollRatePID.Kp, value); break; diff --git a/flight/pios/inc/pios_struct_helper.h b/flight/pios/inc/pios_struct_helper.h index 65bae405a..1198b6fb1 100644 --- a/flight/pios/inc/pios_struct_helper.h +++ b/flight/pios/inc/pios_struct_helper.h @@ -17,13 +17,4 @@ (type *)((char *)__mptr - offsetof(type, member)); } \ ) -/** - * cast_struct_to_array casts an homogeneous structure instance to an array - * of typeof(struct_field). struct_field need to be any of the fields - * containing inside the struct - * @instance: homogeneous structure to cast - * @struct_field: a field contained inside the structure - */ -#define cast_struct_to_array(instance, struct_field) \ - ((typeof(struct_field) *) & (instance)) #endif /* PIOS_STRUCT_HELPER_H */ diff --git a/flight/uavobjects/inc/uavobjectmanager.h b/flight/uavobjects/inc/uavobjectmanager.h index bbd3fc5b7..442c59cb5 100644 --- a/flight/uavobjects/inc/uavobjectmanager.h +++ b/flight/uavobjects/inc/uavobjectmanager.h @@ -51,6 +51,43 @@ typedef void *UAVObjHandle; #define MetaObjectId(id) ((id) + 1) +/** + * helper macro to access multi-element fields as array + */ +#define UAVObjectFieldToArray(type, var) \ + (*({ type *const dummy = &(var); \ + &(((type##Array *)dummy)->array); } \ + )) + +// we have limited trust in our compiler +// make sure this macro actually works on all platforms + +typedef struct __attribute__((__packed__)) { + uint16_t element1; + uint16_t element2; + uint16_t element3; +} +__DummyUAVObjectFieldData; + +typedef struct __attribute__((__packed__)) { + uint16_t array[3]; +} +__DummyUAVObjectFieldDataArray; + +#define __DummyTA(var) UAVObjectFieldToArray(__DummyUAVObjectFieldData, var) + +__attribute__((unused)) static void __DummyTAtest(void) +{ + __DummyUAVObjectFieldData t; + + PIOS_STATIC_ASSERT(sizeof(t) == sizeof(__DummyTA(t))); + PIOS_STATIC_ASSERT(sizeof(t.element1) == sizeof(__DummyTA(t)[0])); + PIOS_STATIC_ASSERT((void *)&t == (void *)&__DummyTA(t)); + PIOS_STATIC_ASSERT((void *)&t.element1 == (void *)&__DummyTA(t)[0]); + PIOS_STATIC_ASSERT((void *)&t.element2 == (void *)&__DummyTA(t)[1]); + PIOS_STATIC_ASSERT((void *)&t.element3 == (void *)&__DummyTA(t)[2]); +} + /** * Object update mode, used by multiple modules (e.g. telemetry and logger) */ diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp index 887bf5fdf..14df42f0c 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp @@ -176,7 +176,6 @@ void ConfigFixedWingWidget::setupUI(QString frameType) scene->setSceneRect(planeimg->boundingRect()); m_aircraft->planeShape->fitInView(planeimg, Qt::KeepAspectRatio); m_aircraft->planeShape->setScene(scene); - } void ConfigFixedWingWidget::registerWidgets(ConfigTaskWidget &parent) @@ -428,7 +427,7 @@ bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType) if (channel > -1) { setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO); value = (double)(m_aircraft->elevonSlider2->value() * 1.27); - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, value); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, -value); value = (double)(m_aircraft->elevonSlider1->value() * 1.27); setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, value); @@ -437,7 +436,7 @@ bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType) value = (double)(m_aircraft->elevonSlider2->value() * 1.27); setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, value); value = (double)(m_aircraft->elevonSlider1->value() * 1.27); - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, -value); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, value); } m_aircraft->fwStatusLabel->setText("Mixer generated"); @@ -499,7 +498,7 @@ bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType) channel = m_aircraft->fwAileron2ChannelBox->currentIndex() - 1; setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO); - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, -127); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, 127); } // vtail diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h index e4bc8f115..7955e7b9c 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h @@ -71,7 +71,6 @@ protected: private slots: virtual void setupUI(QString airframeType); virtual bool throwConfigError(QString airframeType); - }; #endif // CONFIGFIXEDWINGWIDGET_H diff --git a/ground/openpilotgcs/src/plugins/config/configrevohwwidget.cpp b/ground/openpilotgcs/src/plugins/config/configrevohwwidget.cpp index d7e947216..902716058 100644 --- a/ground/openpilotgcs/src/plugins/config/configrevohwwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configrevohwwidget.cpp @@ -123,15 +123,6 @@ void ConfigRevoHWWidget::updateObjectsFromWidgets() data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = HwSettings::OPTIONALMODULES_DISABLED; } - // If any port is configured to be ComBridge port, enable UsbComBridge module if it is not enabled. - // Otherwise disable UsbComBridge module. - if (m_ui->cbFlexi->currentIndex() == HwSettings::RM_FLEXIPORT_COMBRIDGE || m_ui->cbMain->currentIndex() == HwSettings::RM_MAINPORT_COMBRIDGE || - m_ui->cbUSBVCPFunction->currentIndex() == HwSettings::USB_VCPPORT_COMBRIDGE) { - data.OptionalModules[HwSettings::OPTIONALMODULES_COMUSBBRIDGE] = HwSettings::OPTIONALMODULES_ENABLED; - } else { - data.OptionalModules[HwSettings::OPTIONALMODULES_COMUSBBRIDGE] = HwSettings::OPTIONALMODULES_DISABLED; - } - hwSettings->setData(data); } diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.cpp b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.cpp index f609379f6..0e37d5128 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.cpp @@ -1636,8 +1636,8 @@ void VehicleConfigurationHelper::setupElevon() channels[0].type = MIXER_TYPE_SERVO; channels[0].throttle1 = 0; channels[0].throttle2 = 0; - channels[0].roll = -100; - channels[0].pitch = 100; + channels[0].roll = 100; + channels[0].pitch = -100; channels[0].yaw = 0; // Elevon Servo 1 (Chan 2) @@ -1645,12 +1645,12 @@ void VehicleConfigurationHelper::setupElevon() channels[1].throttle1 = 0; channels[1].throttle2 = 0; channels[1].roll = 100; - channels[1].pitch = -100; + channels[1].pitch = 100; channels[1].yaw = 0; guiSettings.fixedwing.FixedWingThrottle = 3; - guiSettings.fixedwing.FixedWingPitch1 = 1; - guiSettings.fixedwing.FixedWingPitch2 = 2; + guiSettings.fixedwing.FixedWingRoll1 = 1; + guiSettings.fixedwing.FixedWingRoll2 = 2; applyMixerConfiguration(channels); applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON, guiSettings); diff --git a/ground/openpilotgcs/src/plugins/welcome/qml/main.qml b/ground/openpilotgcs/src/plugins/welcome/qml/main.qml index 7a58a8fa3..7425d906d 100644 --- a/ground/openpilotgcs/src/plugins/welcome/qml/main.qml +++ b/ground/openpilotgcs/src/plugins/welcome/qml/main.qml @@ -30,10 +30,10 @@ Rectangle { anchors.horizontalCenter: parent.horizontalCenter // distribute a vertical space between the icons blocks an community widget as: // top - 48% - Icons - 27% - CommunityWidget - 25% - bottom - y: (parent.height - buttons.height - communityPanel.height) * 0.48 + y: (parent.height - buttons.height - communityPanel.height - versionInfo.height) * 0.48 width: parent.width height: 600 - spacing: (parent.height - buttons.height - communityPanel.height) * 0.1 + spacing: (parent.height - buttons.height - communityPanel.height - versionInfo.height) * 0.1 Row { //if the buttons grid overlaps vertically with the wizard buttons, @@ -109,5 +109,43 @@ Rectangle { width: Math.min(sourceSize.width, container.width) height: Math.min(450, container.height*0.5) } + + Row { + id: versionInfo + + height: 18 + anchors.horizontalCenter: parent.horizontalCenter + width: textOpVersion.width + textOpVersionAvailable.width + spacing: 16 + + Text { + id: textOpVersion + color: "#c4c0c0" + text: welcomePlugin.versionString + verticalAlignment: Text.AlignTop + anchors.left: parent.anchors.left + font.bold: true + styleColor: "#00000000" + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 14 + } + Text { + id: textOpVersionAvailable + color: "#5fcf07" + text: welcomePlugin.newVersionText + anchors.rightMargin: 0 + font.bold: true + styleColor: "#00000000" + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 14 + anchors.left: textOpVersion.right + + MouseArea{ + width: parent.width + height: parent.height + onClicked: welcomePlugin.openUrl("http://wiki.openpilot.org/display/BUILDS/OpenPilot+Software+Downloads") + } + } + } } } diff --git a/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri b/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri index 7f369f632..04c4323a7 100644 --- a/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri +++ b/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri @@ -1,2 +1,3 @@ include(../../plugins/coreplugin/coreplugin.pri) include(../../libs/utils/utils.pri) +include(../../libs/version_info/version_info.pri) diff --git a/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp b/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp index 381fd226a..a451e2115 100644 --- a/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp +++ b/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp @@ -45,6 +45,9 @@ #include #include +#include +#include + #include #include #include @@ -68,13 +71,29 @@ WelcomeModePrivate::WelcomeModePrivate() // --- WelcomeMode WelcomeMode::WelcomeMode() : m_d(new WelcomeModePrivate), - m_priority(Core::Constants::P_MODE_WELCOME) + m_priority(Core::Constants::P_MODE_WELCOME), + m_newVersionText("") { m_d->quickView = new QQuickView; m_d->quickView->setResizeMode(QQuickView::SizeRootObjectToView); m_d->quickView->engine()->rootContext()->setContextProperty("welcomePlugin", this); m_d->quickView->setSource(QUrl("qrc:/welcome/qml/main.qml")); m_container = NULL; + + QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager; + + // Only attempt to request our version info if the network is accessible + if (networkAccessManager->networkAccessible() == QNetworkAccessManager::Accessible) { + connect(networkAccessManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkResponseReady(QNetworkReply *))); + + // This will delete the network access manager instance when we're done + connect(networkAccessManager, SIGNAL(finished(QNetworkReply *)), networkAccessManager, SLOT(deleteLater())); + + networkAccessManager->get(QNetworkRequest(QUrl("http://www.openpilot.org/opver"))); + } else { + // No network, can delete this now as we don't need it. + delete networkAccessManager; + } } WelcomeMode::~WelcomeMode() @@ -135,4 +154,19 @@ void WelcomeMode::triggerAction(const QString &actionId) { Core::ModeManager::instance()->triggerAction(actionId); } + +void WelcomeMode::networkResponseReady(QNetworkReply *reply) +{ + if (reply != NULL) { + QString version(reply->readAll()); + version = version.trimmed(); + + reply->deleteLater(); + + if (version != VersionInfo::tagOrHash8()) { + m_newVersionText = tr("(Update Available: %1)").arg(version); + emit newVersionTextChanged(); + } + } +} } // namespace Welcome diff --git a/ground/openpilotgcs/src/plugins/welcome/welcomemode.h b/ground/openpilotgcs/src/plugins/welcome/welcomemode.h index b6e837cc9..a51cf3909 100644 --- a/ground/openpilotgcs/src/plugins/welcome/welcomemode.h +++ b/ground/openpilotgcs/src/plugins/welcome/welcomemode.h @@ -29,6 +29,7 @@ #ifndef WELCOMEMODE_H #define WELCOMEMODE_H +#include "version_info/version_info.h" #include "welcome_global.h" #include @@ -37,13 +38,15 @@ QT_BEGIN_NAMESPACE class QWidget; class QUrl; +class QNetworkReply; QT_END_NAMESPACE namespace Welcome { struct WelcomeModePrivate; class WELCOME_EXPORT WelcomeMode : public Core::IMode { - Q_OBJECT + Q_OBJECT Q_PROPERTY(QString versionString READ versionString) + Q_PROPERTY(QString newVersionText READ newVersionText NOTIFY newVersionTextChanged) public: WelcomeMode(); @@ -65,6 +68,17 @@ public: { m_priority = priority; } + QString versionString() const + { + return tr("OpenPilot GCS Version: %1 ").arg(VersionInfo::tagOrHash8()); + } + QString newVersionText() const + { + return m_newVersionText; + } + +signals: + void newVersionTextChanged(); public slots: void openUrl(const QString &url); @@ -75,6 +89,10 @@ private: QWidget *m_container; WelcomeModePrivate *m_d; int m_priority; + QString m_newVersionText; + +private slots: + void networkResponseReady(QNetworkReply *reply); }; } // namespace Welcome diff --git a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp index 72d4c1a63..1cc41bbf7 100644 --- a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp +++ b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp @@ -131,7 +131,11 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo *info) for (int f = 0; f < info->fields[n]->elementNames.count(); f++) { structType.append(QString(" %1 %2;\n").arg(type).arg(info->fields[n]->elementNames[f])); } - structType.append(QString("} %1 ;\n\n").arg(structTypeName)); + structType.append(QString("} %1 ;\n").arg(structTypeName)); + structType.append(QString("typedef struct __attribute__ ((__packed__)) {\n")); + structType.append(QString(" %1 array[%2];\n").arg(type).arg(info->fields[n]->elementNames.count())); + structType.append(QString("} %1Array ;\n").arg(structTypeName)); + structType.append(QString("#define %1%2ToArray( var ) UAVObjectFieldToArray( %3, var )\n\n").arg(info->name).arg(info->fields[n]->name).arg(structTypeName)); dataStructures.append(structType); diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index c41187009..7fa821da4 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -15,14 +15,14 @@ - + - +