mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-02 13:27:32 +08:00
improvement for averaged channels
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
pprz_t rc_values[PPM_NB_PULSES];
|
pprz_t rc_values[PPM_NB_PULSES];
|
||||||
uint8_t rc_status;
|
uint8_t rc_status;
|
||||||
pprz_t avg_rc_values[PPM_NB_PULSES];
|
int32_t avg_rc_values[PPM_NB_PULSES];
|
||||||
uint8_t rc_values_contains_avg_channels = FALSE;
|
uint8_t rc_values_contains_avg_channels = FALSE;
|
||||||
uint8_t time_since_last_ppm;
|
uint8_t time_since_last_ppm;
|
||||||
uint8_t ppm_cpt, last_ppm_cpt;
|
uint8_t ppm_cpt, last_ppm_cpt;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
extern pprz_t rc_values[PPM_NB_PULSES];
|
extern pprz_t rc_values[PPM_NB_PULSES];
|
||||||
extern uint8_t rc_status;
|
extern uint8_t rc_status;
|
||||||
extern pprz_t avg_rc_values[PPM_NB_PULSES];
|
extern int32_t avg_rc_values[PPM_NB_PULSES];
|
||||||
extern uint8_t rc_values_contains_avg_channels;
|
extern uint8_t rc_values_contains_avg_channels;
|
||||||
extern uint8_t time_since_last_ppm;
|
extern uint8_t time_since_last_ppm;
|
||||||
extern uint8_t ppm_cpt, last_ppm_cpt;
|
extern uint8_t ppm_cpt, last_ppm_cpt;
|
||||||
|
|||||||
+16
-13
@@ -68,36 +68,39 @@ let parse_channel =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let norm1_ppm = fun c ->
|
||||||
|
if c.neutral = c.min then
|
||||||
|
sprintf "tmp_radio * (MAX_PPRZ / (float)(SIGNED_SYS_TICS_OF_USEC(%d-%d)))" c.max c.min, "0"
|
||||||
|
else
|
||||||
|
sprintf "tmp_radio * (tmp_radio >=0 ? (MAX_PPRZ/(float)(SIGNED_SYS_TICS_OF_USEC(%d-%d))) : (MIN_PPRZ/(float)(SIGNED_SYS_TICS_OF_USEC(%d-%d))))" c.max c.neutral c.min c.neutral, "MIN_PPRZ"
|
||||||
|
|
||||||
let gen_normalize_ppm = fun channels ->
|
let gen_normalize_ppm = fun channels ->
|
||||||
printf "#define NormalizePpm() {\\\n";
|
printf "#define NormalizePpm() {\\\n";
|
||||||
printf " static uint8_t avg_cpt = 0; /* Counter for averaging */\\\n";
|
printf " static uint8_t avg_cpt = 0; /* Counter for averaging */\\\n";
|
||||||
printf " int16_t tmp_radio;\\\n";
|
printf " int16_t tmp_radio;\\\n";
|
||||||
List.iter
|
List.iter
|
||||||
(fun c ->
|
(fun c ->
|
||||||
printf " tmp_radio = ppm_pulses[RADIO_%s] - SYS_TICS_OF_USEC(%d);\\\n" c.name c.neutral;
|
let value, min_pprz = norm1_ppm c in
|
||||||
let period = if c.averaged then "RC_AVG_PERIOD" else "1" in
|
|
||||||
let value, min_pprz =
|
|
||||||
if c.neutral = c.min then
|
|
||||||
sprintf "tmp_radio * (MAX_PPRZ / %s / (float)(SIGNED_SYS_TICS_OF_USEC(%d-%d)))" period c.max c.min, "0"
|
|
||||||
else
|
|
||||||
sprintf "tmp_radio * (tmp_radio >=0 ? (MAX_PPRZ/%s/(float)(SIGNED_SYS_TICS_OF_USEC(%d-%d))) : (MIN_PPRZ/%s/(float)(SIGNED_SYS_TICS_OF_USEC(%d-%d))))" period c.max c.neutral period c.min c.neutral, "MIN_PPRZ" in
|
|
||||||
if c.averaged then begin
|
if c.averaged then begin
|
||||||
printf " avg_rc_values[RADIO_%s] += %s;\\\n" c.name value
|
printf " avg_rc_values[RADIO_%s] += ppm_pulses[RADIO_%s];\\\n" c.name c.name
|
||||||
end else begin
|
end else begin
|
||||||
|
printf " tmp_radio = ppm_pulses[RADIO_%s] - SYS_TICS_OF_USEC(%d);\\\n" c.name c.neutral;
|
||||||
printf " rc_values[RADIO_%s] = %s;\\\n" c.name value;
|
printf " rc_values[RADIO_%s] = %s;\\\n" c.name value;
|
||||||
printf " if (rc_values[RADIO_%s] > MAX_PPRZ) rc_values[RADIO_%s] = MAX_PPRZ;\\\n else if (rc_values[RADIO_%s] < %s) rc_values[RADIO_%s] = %s; \\\n\\\n" c.name c.name c.name min_pprz c.name min_pprz;
|
printf " Bound(rc_values[RADIO_%s], %s, MAX_PPRZ); \\\n\\\n" c.name min_pprz;
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
channels;
|
channels;
|
||||||
printf "avg_cpt++;\\\n";
|
printf " avg_cpt++;\\\n";
|
||||||
printf " if (avg_cpt == RC_AVG_PERIOD) {\\\n";
|
printf " if (avg_cpt == RC_AVG_PERIOD) {\\\n";
|
||||||
printf " avg_cpt = 0;\\\n";
|
printf " avg_cpt = 0;\\\n";
|
||||||
List.iter
|
List.iter
|
||||||
(fun c ->
|
(fun c ->
|
||||||
if c.averaged then begin
|
if c.averaged then begin
|
||||||
printf " rc_values[RADIO_%s] = avg_rc_values[RADIO_%s];\\\n" c.name c.name;
|
let value, min_pprz = norm1_ppm c in
|
||||||
|
printf " tmp_radio = avg_rc_values[RADIO_%s] / RC_AVG_PERIOD - SYS_TICS_OF_USEC(%d);\\\n" c.name c.neutral;
|
||||||
|
printf " rc_values[RADIO_%s] = %s;\\\n" c.name value;
|
||||||
printf " avg_rc_values[RADIO_%s] = 0;\\\n" c.name;
|
printf " avg_rc_values[RADIO_%s] = 0;\\\n" c.name;
|
||||||
printf " if (rc_values[RADIO_%s] > MAX_PPRZ) rc_values[RADIO_%s] = MAX_PPRZ;\\\n else if (rc_values[RADIO_%s] < MIN_PPRZ) rc_values[RADIO_%s] = MIN_PPRZ; \\\n\\\n" c.name c.name c.name c.name;
|
printf " Bound(rc_values[RADIO_%s], %s, MAX_PPRZ); \\\n\\\n" c.name min_pprz;
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
channels;
|
channels;
|
||||||
|
|||||||
Reference in New Issue
Block a user