summaryrefslogtreecommitdiff
path: root/n/asserv/src/asserv/main.c
diff options
context:
space:
mode:
authorschodet2006-01-17 16:39:17 +0000
committerschodet2006-01-17 16:39:17 +0000
commit435b5a9adaa251e8d72ccf5b744db80296b30908 (patch)
treebbb366c0826073f4a4111b2a5af4a295180aee8c /n/asserv/src/asserv/main.c
parent1e15fde47f958a7564c45e852bbb7e9b2c31a3ce (diff)
Ouh lala, plein de modifs, dont l'ajout d'un modèle de moteur à courant
continue, le changement du PID, de la PWM et l'ajout de commandes dans main.
Diffstat (limited to 'n/asserv/src/asserv/main.c')
-rw-r--r--n/asserv/src/asserv/main.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/n/asserv/src/asserv/main.c b/n/asserv/src/asserv/main.c
index 3bb0a5d..f56c662 100644
--- a/n/asserv/src/asserv/main.c
+++ b/n/asserv/src/asserv/main.c
@@ -29,6 +29,8 @@
#include "modules/utils/byte.h"
#include "io.h"
+#include "misc.h"
+
/* This is implementation include. */
#include "timer.c"
#include "counter.c"
@@ -61,7 +63,8 @@ uint8_t main_print_pin, main_print_pin_cpt;
/** Record timer value at different stage of computing. Used for performance
* analisys. */
-uint8_t main_timer_0, main_timer_1, main_timer_2, main_timer_3, main_timer_4;
+uint8_t main_timer_0, main_timer_1, main_timer_2, main_timer_3, main_timer_4,
+ main_timer_5;
/* +AutoDec */
@@ -73,11 +76,12 @@ main_loop (void);
/** Entry point. */
int
-main (void)
+main (int argc, char **argv)
{
DDRD = 0x60;
/* Pull-ups. */
- PORTA = _BV (7) | _BV (1) | _BV (0);
+ PORTA = 0xff;
+ PORTC = 0xff;
eeprom_read_params ();
pwm_init ();
timer_init ();
@@ -94,17 +98,22 @@ main (void)
static void
main_loop (void)
{
+ main_timer_5 = timer_read ();
timer_wait ();
/* Counter update. */
counter_update ();
+ main_timer_0 = timer_read ();
/* Postion control. */
if (main_mode >= 1)
pos_update ();
+ main_timer_1 = timer_read ();
/* Pwm setup. */
pwm_update ();
+ main_timer_2 = timer_read ();
/* Speed control. */
if (main_mode >= 2)
speed_update ();
+ main_timer_3 = timer_read ();
/* Stats. */
if (main_stat_counter && !--main_stat_counter_cpt)
{
@@ -124,8 +133,8 @@ main_loop (void)
}
if (main_stat_timer && !--main_stat_timer_cpt)
{
- proto_send5b ('T', main_timer_4, main_timer_3, main_timer_2,
- main_timer_1, main_timer_0);
+ proto_send6b ('T', main_timer_0, main_timer_2, main_timer_3,
+ main_timer_4, main_timer_4, main_timer_5);
main_stat_timer_cpt = main_stat_timer;
}
if (main_print_pin && !--main_print_pin_cpt)
@@ -136,6 +145,7 @@ main_loop (void)
/* Misc. */
while (uart0_poll ())
proto_accept (uart0_getc ());
+ main_timer_4 = timer_read ();
}
/** Handle incoming messages. */
@@ -165,6 +175,30 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
pwm_left = v8_to_v16 (args[0], args[1]);
pwm_right = v8_to_v16 (args[2], args[3]);
break;
+ case c ('c', 4):
+ /* Add to position consign.
+ * - w: theta consign offset.
+ * - w: alpha consign offset. */
+ main_mode = 1;
+ pos_theta_cons += v8_to_v16 (args[0], args[1]);
+ pos_alpha_cons += v8_to_v16 (args[2], args[3]);
+ break;
+ case c ('s', 0):
+ /* Stop (set zero speed). */
+ main_mode = 2;
+ speed_pos = 0;
+ speed_theta_cons = 0;
+ speed_alpha_cons = 0;
+ break;
+ case c ('s', 2):
+ /* Set speed.
+ * - b: theta speed.
+ * - b: alpha speed. */
+ main_mode = 2;
+ speed_pos = 0;
+ speed_theta_cons = args[0] << 8;
+ speed_alpha_cons = args[1] << 8;
+ break;
/* Stats.
* - b: interval between stats. */
case c ('C', 1):
@@ -193,6 +227,10 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
{
switch (c (args[0], size))
{
+ case c ('a', 5):
+ speed_theta_acc = v8_to_v16 (args[1], args[2]);
+ speed_alpha_acc = v8_to_v16 (args[3], args[4]);
+ break;
case c ('p', 3):
pos_theta_kp = pos_alpha_kp = v8_to_v16 (args[1], args[2]);
break;