From 55f755ed3b97525b29a16e02a1ebda7e12980f56 Mon Sep 17 00:00:00 2001 From: Pavel Semerad Date: Mon, 14 May 2012 00:35:49 +0200 Subject: [PATCH] repair servo speed to not be dependent on ppm frame length --- ChangeLog | 2 ++ calc.c | 6 +++--- ppm.c | 13 +++++++------ ppm.h | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d70cc9..e8a0236 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ *0.6.1 () repaired ABS to use cycle length same as before PPM frame length changes added extra brake channel for throttle brake side + repaired steering/throttle/channel speed to not beeing dependent + on ppm frame length *0.6.0 (28 Apr 2012) increased model memories by using FLASH also diff --git a/calc.c b/calc.c index 094617a..56479ac 100644 --- a/calc.c +++ b/calc.c @@ -186,7 +186,7 @@ static s16 steering_speed(s16 val, u8 channel) { // calculate max delta if (stspd == 100) max_delta = PPM(1000); - else max_delta = PPM(1000) / 2 / (100 - stspd); + else max_delta = PPM(1000) / 2 / 20 * ppm_frame_length / (100 - stspd); // compare delta with max_delta if (delta < 0) { @@ -207,7 +207,7 @@ static s16 steering_speed(s16 val, u8 channel) { // check if it is moving from return to turn if (delta2) { if (cm.stspd_turn == 100) max_delta = PPM(1000); - else max_delta = PPM(1000) / 2 / (100 - cm.stspd_turn); + else max_delta = PPM(1000) / 2 / 20 * ppm_frame_length / (100 - cm.stspd_turn); if (delta2 < 0) { if (max_delta < -delta2) val = -max_delta; @@ -245,7 +245,7 @@ static s16 channel_speed(s16 val, u8 channel) { } } - max_delta = PPM(1000) / 2 / (100 - speed); + max_delta = PPM(1000) / 2 / 20 * ppm_frame_length / (100 - speed); if (delta < 0) { if (max_delta < -delta) val = last - max_delta; } diff --git a/ppm.c b/ppm.c index 2836924..2d444a3 100644 --- a/ppm.c +++ b/ppm.c @@ -57,6 +57,7 @@ u8 ppm_timer; // timer incremented every 1ms u8 ppm_start; // when to start servo pulses u8 ppm_end; // when must last PPM frame end (to not start again before) u8 ppm_calc_awake; // when to awake CALC task +u8 ppm_frame_length; // last length of ppm frame @@ -172,19 +173,19 @@ void ppm_calc_sync(void) { ppm_calc_len -= ppm_calc_awake; ppm_calc_len++; - // calculate new ppm_end - ppm_end = (u8)((ppm_microsecs01 + 9999) / 10000); + // calculate frame length and new ppm_end + ppm_frame_length = (u8)((ppm_microsecs01 + 9999) / 10000); if (cg.ppm_sync_frame) { // constant frame length u8 fl = (u8)(cg.ppm_length + 9); - ppm_end += PPM_SYNC_LENGTH_MIN; // minimal frame with SYNC signal - if (ppm_end < fl) ppm_end = fl; + ppm_frame_length += PPM_SYNC_LENGTH_MIN; // minimal frame with SYNC signal + if (ppm_frame_length < fl) ppm_frame_length = fl; } else { // constant sync length - ppm_end += (u8)(cg.ppm_length + 3); + ppm_frame_length += (u8)(cg.ppm_length + 3); } - ppm_end += ppm_start; + ppm_end = (u8)(ppm_start + ppm_frame_length); ppm_microsecs01 = 0; // set new ppm_calc_awake diff --git a/ppm.h b/ppm.h index 26611a0..ffd2bb1 100644 --- a/ppm.h +++ b/ppm.h @@ -48,6 +48,7 @@ extern u8 ppm_values[]; // as bytes for ppm_interrupt and timer_interrupt extern u8 ppm_timer; // timer incremented every 1ms extern u8 ppm_start; // when to start servo pulses extern u8 ppm_calc_awake; // when to awake CALC task +extern u8 ppm_frame_length; // last length of ppm frame // set actual number of channels extern void ppm_set_channels(u8 n);