summaryrefslogtreecommitdiff
path: root/n/asserv/src/asserv/pos.c
diff options
context:
space:
mode:
authorschodet2006-03-26 14:16:20 +0000
committerschodet2006-03-26 14:16:20 +0000
commit98f731d45cb51040bb6ee364920cb0de34939e0a (patch)
treece769578f3fac0c4925de5d5d99625ce00272fb7 /n/asserv/src/asserv/pos.c
parenta0966ea8b0ed34d2a95a33c311e60a9a331290b8 (diff)
Ajout du déplacement avec consigne donnée en position, controlé en vitesse.
Ajout des stats sur la vitesse. Ajout d'explications sur le PID. Correction de la formule de tension dans la simulation à cause du mode PWM fast.
Diffstat (limited to 'n/asserv/src/asserv/pos.c')
-rw-r--r--n/asserv/src/asserv/pos.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/n/asserv/src/asserv/pos.c b/n/asserv/src/asserv/pos.c
index b6bee63..d4204c7 100644
--- a/n/asserv/src/asserv/pos.c
+++ b/n/asserv/src/asserv/pos.c
@@ -55,7 +55,21 @@ int32_t pos_theta_e_old, pos_alpha_e_old;
/* +AutoDec */
/* -AutoDec */
-/** Compute a PID. */
+/** Compute a PID.
+ * How to compute maximum numbers size:
+ * Result is 24 bits (16 bits kept after shift).
+ * If e_sat == 1023, e max is 11 bits (do not forget the sign bit), and diff
+ * max is 12 bits.
+ * If int_sat == 1023, i max is 11 bits.
+ * In the final addition, let's give 23 bits to the p part, and 22 bits to the
+ * i and d part (23b + 22b + 22b => 23b + 23b => 24b).
+ * Therefore, kp can be 23 - 11 = 12 bits (f4.8).
+ * ki can be 22 - 11 = 11 bits (f3.8).
+ * kd can be 22 - 12 = 10 bits (f2.8).
+ * How to increase this number:
+ * - lower the shift.
+ * - bound the value returned.
+ * - lower e & int saturation. */
static inline int16_t
pos_compute_pid (int32_t e, int32_t *i, int32_t *e_old,
uint16_t kp, uint16_t ki, uint16_t kd)
@@ -72,7 +86,7 @@ pos_compute_pid (int32_t e, int32_t *i, int32_t *e_old,
pid = e * kp + *i * ki + diff * kd;
/* Save result. */
*e_old = e;
- return pid >> 12;
+ return pid >> 8;
}
/** Update PWM according to consign. */