mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-28 07:20:35 +08:00
mixer: move scale() and scale_check() to SimpleMixer
This commit is contained in:
@@ -64,47 +64,6 @@ Mixer::get_control(uint8_t group, uint8_t index)
|
||||
return value;
|
||||
}
|
||||
|
||||
float
|
||||
Mixer::scale(const mixer_scaler_s &scaler, float input)
|
||||
{
|
||||
float output;
|
||||
|
||||
if (input < 0.0f) {
|
||||
output = (input * scaler.negative_scale) + scaler.offset;
|
||||
|
||||
} else {
|
||||
output = (input * scaler.positive_scale) + scaler.offset;
|
||||
}
|
||||
|
||||
return math::constrain(output, scaler.min_output, scaler.max_output);
|
||||
}
|
||||
|
||||
int
|
||||
Mixer::scale_check(struct mixer_scaler_s &scaler)
|
||||
{
|
||||
if (scaler.offset > 1.001f) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (scaler.offset < -1.001f) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (scaler.min_output > scaler.max_output) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (scaler.min_output < -1.001f) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (scaler.max_output > 1.001f) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
Mixer::findtag(const char *buf, unsigned &buflen, char tag)
|
||||
{
|
||||
|
||||
@@ -153,23 +153,6 @@ protected:
|
||||
*/
|
||||
float get_control(uint8_t group, uint8_t index);
|
||||
|
||||
/**
|
||||
* Perform simpler linear scaling.
|
||||
*
|
||||
* @param scaler The scaler configuration.
|
||||
* @param input The value to be scaled.
|
||||
* @return The scaled value.
|
||||
*/
|
||||
static float scale(const mixer_scaler_s &scaler, float input);
|
||||
|
||||
/**
|
||||
* Validate a scaler
|
||||
*
|
||||
* @param scaler The scaler to be validated.
|
||||
* @return Zero if good, nonzero otherwise.
|
||||
*/
|
||||
static int scale_check(struct mixer_scaler_s &scaler);
|
||||
|
||||
/**
|
||||
* Find a tag
|
||||
*
|
||||
|
||||
@@ -314,3 +314,44 @@ SimpleMixer::check()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
float
|
||||
SimpleMixer::scale(const mixer_scaler_s &scaler, float input)
|
||||
{
|
||||
float output;
|
||||
|
||||
if (input < 0.0f) {
|
||||
output = (input * scaler.negative_scale) + scaler.offset;
|
||||
|
||||
} else {
|
||||
output = (input * scaler.positive_scale) + scaler.offset;
|
||||
}
|
||||
|
||||
return math::constrain(output, scaler.min_output, scaler.max_output);
|
||||
}
|
||||
|
||||
int
|
||||
SimpleMixer::scale_check(mixer_scaler_s &scaler)
|
||||
{
|
||||
if (scaler.offset > 1.001f) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (scaler.offset < -1.001f) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (scaler.min_output > scaler.max_output) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (scaler.min_output < -1.001f) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (scaler.max_output > 1.001f) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -104,9 +104,28 @@ public:
|
||||
unsigned get_trim(float *trim) override;
|
||||
|
||||
private:
|
||||
mixer_simple_s *_pinfo{nullptr};
|
||||
|
||||
/**
|
||||
* Perform simpler linear scaling.
|
||||
*
|
||||
* @param scaler The scaler configuration.
|
||||
* @param input The value to be scaled.
|
||||
* @return The scaled value.
|
||||
*/
|
||||
static float scale(const mixer_scaler_s &scaler, float input);
|
||||
|
||||
/**
|
||||
* Validate a scaler
|
||||
*
|
||||
* @param scaler The scaler to be validated.
|
||||
* @return Zero if good, nonzero otherwise.
|
||||
*/
|
||||
static int scale_check(struct mixer_scaler_s &scaler);
|
||||
|
||||
static int parse_output_scaler(const char *buf, unsigned &buflen, mixer_scaler_s &scaler);
|
||||
static int parse_control_scaler(const char *buf, unsigned &buflen, mixer_scaler_s &scaler, uint8_t &control_group,
|
||||
uint8_t &control_index);
|
||||
|
||||
mixer_simple_s *_pinfo{nullptr};
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user