summaryrefslogtreecommitdiff
path: root/n/asserv/src/speed.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/asserv/src/speed.c')
-rw-r--r--n/asserv/src/speed.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/n/asserv/src/speed.c b/n/asserv/src/speed.c
index 8c67207..84f6f39 100644
--- a/n/asserv/src/speed.c
+++ b/n/asserv/src/speed.c
@@ -30,7 +30,7 @@ int8_t speed_left_aim, speed_right_aim;
/** Max speed. */
int8_t speed_max = 0x20;
/** Acceleration value. */
-uint8_t speed_acc = 8;
+uint8_t speed_acc = 4;
/** Acceleration counter, speed gets updated when it reachs 0. */
uint8_t speed_acc_cpt;
/** Integral term. */
@@ -40,13 +40,15 @@ int16_t speed_int_max = 1024;
/** Last error value. */
int16_t speed_left_e_old, speed_right_e_old;
/** P coeficients. 4.8 fixed point format. */
-uint16_t speed_kp = 5 * 255;
+uint16_t speed_kp = 0x0200;
/** I coeficients. 3.8 fixed point format. */
-uint16_t speed_ki = 1 * 255;
+uint16_t speed_ki = 0x0004;
/** D coeficients. 3.8 fixed point format. */
-uint16_t speed_kd = 1 * 255;
+uint16_t speed_kd = 0x0100;
/** Counter value wanted. */
uint16_t speed_left_counter, speed_right_counter;
+/** Do not update counter. */
+uint8_t speed_counter_updated = 0;
/* +AutoDec */
@@ -77,10 +79,6 @@ speed_restart (void);
static inline void
speed_init (void)
{
- speed_acc = 8;
- speed_int_max = 1024;
- speed_kp = 2 * 255;
- speed_ki = 1 * 255;
}
/** Update speeds according to the wanted speeds and the acceleration. */
@@ -110,8 +108,15 @@ speed_update (void)
speed_right = speed_right_aim;
}
/* Update counter. */
- speed_left_counter += speed_left;
- speed_right_counter += speed_right;
+ if (speed_counter_updated)
+ {
+ speed_counter_updated = 0;
+ }
+ else
+ {
+ speed_left_counter += speed_left;
+ speed_right_counter += speed_right;
+ }
}
/** Compute new pwm value for left motor. */