36 #include <px4_platform_common/defines.h> 42 #define PROGRESS_INT_SCALING 10000 51 void output_limit_calc(
const bool armed,
const bool pre_armed,
const unsigned num_channels,
const uint16_t reverse_mask,
52 const uint16_t *disarmed_output,
const uint16_t *min_output,
const uint16_t *max_output,
53 const float *output, uint16_t *effective_output,
output_limit_t *limit)
57 switch (limit->
state) {
117 unsigned local_limit_state = limit->
state;
126 switch (local_limit_state) {
129 for (
unsigned i = 0; i < num_channels; i++) {
130 effective_output[i] = disarmed_output[i];
144 for (
unsigned i = 0; i < num_channels; i++) {
146 float control_value = output[i];
149 if (!PX4_ISFINITE(control_value)) {
150 effective_output[i] = disarmed_output[i];
154 uint16_t ramp_min_output;
157 if (disarmed_output[i] > 0) {
160 unsigned disarmed = disarmed_output[i];
162 if (disarmed > min_output[i]) {
163 disarmed = min_output[i];
166 unsigned disarmed_min_diff = min_output[i] - disarmed;
172 ramp_min_output = min_output[i];
175 if (reverse_mask & (1 << i)) {
176 control_value = -1.0f * control_value;
179 effective_output[i] = control_value * (max_output[i] - ramp_min_output) / 2 + (max_output[i] + ramp_min_output) / 2;
182 if (effective_output[i] < ramp_min_output) {
183 effective_output[i] = ramp_min_output;
185 }
else if (effective_output[i] > max_output[i]) {
186 effective_output[i] = max_output[i];
194 for (
unsigned i = 0; i < num_channels; i++) {
196 float control_value = output[i];
199 if (!PX4_ISFINITE(control_value)) {
200 effective_output[i] = disarmed_output[i];
204 if (reverse_mask & (1 << i)) {
205 control_value = -1.0f * control_value;
208 effective_output[i] = control_value * (max_output[i] - min_output[i]) / 2 + (max_output[i] + min_output[i]) / 2;
211 if (effective_output[i] < min_output[i]) {
212 effective_output[i] = min_output[i];
214 }
else if (effective_output[i] > max_output[i]) {
215 effective_output[i] = max_output[i];
void output_limit_calc(const bool armed, const bool pre_armed, const unsigned num_channels, const uint16_t reverse_mask, const uint16_t *disarmed_output, const uint16_t *min_output, const uint16_t *max_output, const float *output, uint16_t *effective_output, output_limit_t *limit)
bool ramp_up
if true, motors will ramp up from disarmed to min_output after arming
#define PROGRESS_INT_SCALING
High-resolution timer with callouts and timekeeping.
enum output_limit_state state
static struct actuator_armed_s armed
static hrt_abstime hrt_elapsed_time(const hrt_abstime *then)
Compute the delta between a timestamp taken in the past and now.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
void output_limit_init(output_limit_t *limit)
Library for output limiting (PWM for example)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).