The unified diff between revisions [be147b11..] and [dc88787e..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'stick.c'
# # old_revision [be147b11caac304fda1579ac71017eecc3bb79e0] # new_revision [dc88787ecd1d574feba045763baed2a7651ff33d] # # patch "stick.c" # from [4870f5f016221d25b0d8a4d093fda5dbe0f0b30c] # to [2f04655a185f179c9e8469822e089c308cb3a220] # ============================================================ --- stick.c 4870f5f016221d25b0d8a4d093fda5dbe0f0b30c +++ stick.c 2f04655a185f179c9e8469822e089c308cb3a220 @@ -12,45 +12,46 @@ #include "timer.h" #include "trig.h" #include "motor.h" -#include "wmp.h" #include "status.h" #include "watchdog.h" +#include "log.h" +#include "config.h" #define TWO_PI 6.28318531f #define PI 3.14159265f -#define MIN_X 14700 -#define MAX_X 29700 -#define CENTRE_X 22200 +#define MIN_X config.stick.timing.x.min +#define MAX_X config.stick.timing.x.max +#define CENTRE_X config.stick.timing.x.centre -#define MIN_Y 14700 -#define MAX_Y 29700 -#define CENTRE_Y 22200 +#define MIN_Y config.stick.timing.y.min +#define MAX_Y config.stick.timing.y.max +#define CENTRE_Y config.stick.timing.y.centre -#define MIN_Z 14700 -#define MAX_Z 29700 -#define CENTRE_Z 22200 +#define MIN_Z config.stick.timing.z.min +#define MAX_Z config.stick.timing.z.max +#define CENTRE_Z config.stick.timing.z.centre -#define MIN_THR 15700 -#define MAX_THR 29700 +#define MIN_THR config.stick.timing.throttle.min +#define MAX_THR config.stick.timing.throttle.max -#define MIN_REAL_THR 14700 +#define MIN_REAL_THR 8720 #define CENTRE_ZONE 100 -/* With new TX firmware: +/* With new TX firmware, CPPM: * x y thr z - * centre: 22192, 22222, 14687, 22196 - * min: 14686, 14701, 14686, 14687 - * max: 29740, 29740, 29725, 29725 + * centre: 16260, 16258, 16000, 16300 + * min: 8720, 8718, 8720, 8722 + * max: 23790, 23817, 23750, 23803 */ /* Full scale is a roll/pitch angle of 30 degrees from the vertical */ -#define SCALE_X (TWO_PI*30.0/360.0 / (MAX_X-CENTRE_X)) -#define SCALE_Y (TWO_PI*30.0/360.0 / (MAX_Y-CENTRE_Y)) +#define SCALE_X (TWO_PI*config.stick.sensitivity.x/360.0 / (MAX_X-CENTRE_X)) +#define SCALE_Y (TWO_PI*config.stick.sensitivity.y/360.0 / (MAX_Y-CENTRE_Y)) /* Full scale is a complete rotation in one second */ -#define SCALE_Z (TWO_PI / (MAX_Z-CENTRE_Z)) +#define SCALE_Z (TWO_PI*config.stick.sensitivity.z/360.0 / (MAX_Z-CENTRE_Z)) /* 0 is min throttle, 1 is max throttle */ #define SCALE_THROTTLE (1.0f/(MAX_THR - MIN_THR)) @@ -59,9 +60,9 @@ unsigned int stick_counter; unsigned int stick_counter; -void stick_update(float x, float y, float z) +void stick_update(vec3f stick) { - float tz = delta_t * z; + float tz = delta_t * stick.z; stick_yaw += tz; @@ -72,16 +73,16 @@ void stick_update(float x, float y, floa stick_yaw -= TWO_PI; #if 0 - z = stick_yaw; + stick.z = stick_yaw; #endif - x = sine(x); - y = sine(y); + stick.x = sine(stick.x); + stick.y = sine(stick.y); #if 0 - z = 1.0/fisqrt(1-x*x-y*y); + stick.z = 1.0/fisqrt(1-stick.x*stick.x-stick.y*stick.y); #endif - dcm_attitude_error(x, y, z); + dcm_attitude_error(stick); } #ifdef STICK_DEBUG_CALIBRATE @@ -105,14 +106,26 @@ void stick_input(void) { void stick_input(void) { float x, y, z, throttle; + unsigned int xi, yi, zi, throttlei; + if (timer_allvalid()) { - x = timer_input(0); - y = timer_input(1); - throttle = timer_input(2); - z = timer_input(3); + xi = timer_input(0); + yi = timer_input(1); + throttlei = timer_input(2); + zi = timer_input(3); + log_put_uint16(xi); + log_put_uint16(yi); + log_put_uint16(throttlei); + log_put_uint16(zi); + + x = xi; + y = yi; + throttle = throttlei; + z = zi; + #ifdef STICK_DEBUG_CALIBRATE - if ((stick_counter % 20) == 0) + if ((stick_counter % 100) == 0) stick_debug_calibrate(); #endif @@ -140,6 +153,10 @@ void stick_input(void) { if (throttle < 0.0) throttle = 0.0; } else { + log_put_uint16(0); + log_put_uint16(0); + log_put_uint16(0); + log_put_uint16(0); x = 0.0f; y = 0.0f; z = 0.0f; @@ -152,9 +169,7 @@ void stick_input(void) { watchdog_kick(WATCHDOG_STICK); /* So the controls are back to front. Let's fix that. */ - x = -x; - y = -y; - z = -z; + vec3f stick = {-x, -y, -z}; #if 0 if ((stick_counter % 100) == 0) { @@ -165,10 +180,10 @@ void stick_input(void) { #endif #if 1 - stick_update(x, y, z); + stick_update(stick); #else if ((stick_counter % 100) == 0) - stick_update(x, y, z); + stick_update(stick); #endif /*