diff --git a/UAV-ControlSystem/inc/utilities.h b/UAV-ControlSystem/inc/utilities.h index 26fdf58..446ddea 100644 --- a/UAV-ControlSystem/inc/utilities.h +++ b/UAV-ControlSystem/inc/utilities.h @@ -83,6 +83,6 @@ void Error_Handler(void); uint8_t reverse(uint8_t byte); -uint16_t constrain(uint16_t value, uint16_t min, uint16_t max); +int16_t constrain(int16_t value, int16_t min, int16_t max); #endif /* UTILITIES_H_ */ diff --git a/UAV-ControlSystem/src/drivers/motormix.c b/UAV-ControlSystem/src/drivers/motormix.c index ea8dd04..22624cf 100644 --- a/UAV-ControlSystem/src/drivers/motormix.c +++ b/UAV-ControlSystem/src/drivers/motormix.c @@ -199,14 +199,16 @@ void mix() PidProfile[PID_ID_GYRO].PID_Out[YAW] * mixerUAV[i].yaw * ((mixerConfig.yaw_reverse_direction) ? -1 : 1); } - for (int i = 0; i < MOTOR_COUNT; i++) - // Find the minimum and maximum motor output - if (RPY_Mix[i] < RPY_Mix_Min) RPY_Mix_Min = RPY_Mix[i]; + /* Mixer Low Scale - Scaling output around low throttle */ if (flags_IsSet_ID(systemFlags_mixerlowscale_id)) { + for (int i = 0; i < MOTOR_COUNT; i++) + // Find the minimum and maximum motor output + if (RPY_Mix[i] < RPY_Mix_Min) RPY_Mix_Min = RPY_Mix[i]; + uint16_t RPY_Mix_Min_Overshoot = (RPY_Mix_Min < mixerConfig.minThrottle) ? mixerConfig.minThrottle - RPY_Mix_Min : 0; if (RPY_Mix_Min_Overshoot > 0 ) //|| RPY_Mix_Max_Overshoot > 0) @@ -221,10 +223,11 @@ void mix() for (int i = 0; i < MOTOR_COUNT; i++) RPY_Mix[i] = (((float)(RPY_Mix[i] - throttle)) * (1 - mix_scale_reduction)) + throttle; } + /* Recalculating RPY_Mix_Min */ + RPY_Mix_Min = throttleMid; } - /* Recalculating RPY_Mix_Min */ - RPY_Mix_Min = throttleMid; + for (int i = 0; i < MOTOR_COUNT; i++) { diff --git a/UAV-ControlSystem/src/utilities.c b/UAV-ControlSystem/src/utilities.c index 2e22185..7c2192c 100644 --- a/UAV-ControlSystem/src/utilities.c +++ b/UAV-ControlSystem/src/utilities.c @@ -219,7 +219,7 @@ uint8_t reverse(uint8_t byte) return byte; } -uint16_t constrain(uint16_t value, uint16_t min, uint16_t max) +int16_t constrain(int16_t value, int16_t min, int16_t max) { if (value < min) return min;