2 * Copyright Droids Corporation (2009)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: commands_traj.c,v 1.6 2009-05-02 10:08:09 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
26 #include <aversive/pgmspace.h>
27 #include <aversive/wait.h>
28 #include <aversive/error.h>
33 #include <encoders_microb.h>
37 #include <control_system_manager.h>
38 #include <trajectory_manager.h>
39 #include <blocking_detection_manager.h>
40 #include <robot_system.h>
41 #include <position_manager.h>
45 #include <parse_string.h>
46 #include <parse_num.h>
49 #include "strat_base.h"
50 #include "strat_utils.h"
54 /**********************************************************/
55 /* Traj_Speeds for trajectory_manager */
57 /* this structure is filled when cmd_traj_speed is parsed successfully */
58 struct cmd_traj_speed_result {
64 /* function called when cmd_traj_speed is parsed successfully */
65 static void cmd_traj_speed_parsed(void *parsed_result, void *data)
67 struct cmd_traj_speed_result * res = parsed_result;
69 if (!strcmp_P(res->arg1, PSTR("angle"))) {
70 trajectory_set_speed(&mainboard.traj, mainboard.traj.d_speed, res->s);
72 else if (!strcmp_P(res->arg1, PSTR("distance"))) {
73 trajectory_set_speed(&mainboard.traj, res->s, mainboard.traj.a_speed);
75 /* else it is a "show" */
77 printf_P(PSTR("angle %u, distance %u\r\n"),
78 mainboard.traj.a_speed,
79 mainboard.traj.d_speed);
82 prog_char str_traj_speed_arg0[] = "traj_speed";
83 parse_pgm_token_string_t cmd_traj_speed_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_traj_speed_result, arg0, str_traj_speed_arg0);
84 prog_char str_traj_speed_arg1[] = "angle#distance";
85 parse_pgm_token_string_t cmd_traj_speed_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_traj_speed_result, arg1, str_traj_speed_arg1);
86 parse_pgm_token_num_t cmd_traj_speed_s = TOKEN_NUM_INITIALIZER(struct cmd_traj_speed_result, s, UINT16);
88 prog_char help_traj_speed[] = "Set traj_speed values for trajectory manager";
89 parse_pgm_inst_t cmd_traj_speed = {
90 .f = cmd_traj_speed_parsed, /* function to call */
91 .data = NULL, /* 2nd arg of func */
92 .help_str = help_traj_speed,
93 .tokens = { /* token list, NULL terminated */
94 (prog_void *)&cmd_traj_speed_arg0,
95 (prog_void *)&cmd_traj_speed_arg1,
96 (prog_void *)&cmd_traj_speed_s,
103 prog_char str_traj_speed_show_arg[] = "show";
104 parse_pgm_token_string_t cmd_traj_speed_show_arg = TOKEN_STRING_INITIALIZER(struct cmd_traj_speed_result, arg1, str_traj_speed_show_arg);
106 prog_char help_traj_speed_show[] = "Show traj_speed values for trajectory manager";
107 parse_pgm_inst_t cmd_traj_speed_show = {
108 .f = cmd_traj_speed_parsed, /* function to call */
109 .data = NULL, /* 2nd arg of func */
110 .help_str = help_traj_speed_show,
111 .tokens = { /* token list, NULL terminated */
112 (prog_void *)&cmd_traj_speed_arg0,
113 (prog_void *)&cmd_traj_speed_show_arg,
118 /**********************************************************/
119 /* trajectory window configuration */
121 /* this structure is filled when cmd_trajectory is parsed successfully */
122 struct cmd_trajectory_result {
131 /* function called when cmd_trajectory is parsed successfully */
132 static void cmd_trajectory_parsed(void * parsed_result, void * data)
134 struct cmd_trajectory_result * res = parsed_result;
136 if (!strcmp_P(res->arg1, PSTR("set"))) {
137 trajectory_set_windows(&mainboard.traj, res->d_win,
138 res->a_win, res->a_start);
141 printf_P(PSTR("trajectory %2.2f %2.2f %2.2f\r\n"), mainboard.traj.d_win,
142 DEG(mainboard.traj.a_win_rad), DEG(mainboard.traj.a_start_rad));
145 prog_char str_trajectory_arg0[] = "trajectory";
146 parse_pgm_token_string_t cmd_trajectory_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_trajectory_result, arg0, str_trajectory_arg0);
147 prog_char str_trajectory_arg1[] = "set";
148 parse_pgm_token_string_t cmd_trajectory_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_trajectory_result, arg1, str_trajectory_arg1);
149 parse_pgm_token_num_t cmd_trajectory_d = TOKEN_NUM_INITIALIZER(struct cmd_trajectory_result, d_win, FLOAT);
150 parse_pgm_token_num_t cmd_trajectory_a = TOKEN_NUM_INITIALIZER(struct cmd_trajectory_result, a_win, FLOAT);
151 parse_pgm_token_num_t cmd_trajectory_as = TOKEN_NUM_INITIALIZER(struct cmd_trajectory_result, a_start, FLOAT);
153 prog_char help_trajectory[] = "Set trajectory windows (distance, angle, angle_start)";
154 parse_pgm_inst_t cmd_trajectory = {
155 .f = cmd_trajectory_parsed, /* function to call */
156 .data = NULL, /* 2nd arg of func */
157 .help_str = help_trajectory,
158 .tokens = { /* token list, NULL terminated */
159 (prog_void *)&cmd_trajectory_arg0,
160 (prog_void *)&cmd_trajectory_arg1,
161 (prog_void *)&cmd_trajectory_d,
162 (prog_void *)&cmd_trajectory_a,
163 (prog_void *)&cmd_trajectory_as,
170 prog_char str_trajectory_show_arg[] = "show";
171 parse_pgm_token_string_t cmd_trajectory_show_arg = TOKEN_STRING_INITIALIZER(struct cmd_trajectory_result, arg1, str_trajectory_show_arg);
173 prog_char help_trajectory_show[] = "Show trajectory window configuration";
174 parse_pgm_inst_t cmd_trajectory_show = {
175 .f = cmd_trajectory_parsed, /* function to call */
176 .data = NULL, /* 2nd arg of func */
177 .help_str = help_trajectory_show,
178 .tokens = { /* token list, NULL terminated */
179 (prog_void *)&cmd_trajectory_arg0,
180 (prog_void *)&cmd_trajectory_show_arg,
185 /**********************************************************/
186 /* rs_gains configuration */
188 /* this structure is filled when cmd_rs_gains is parsed successfully */
189 struct cmd_rs_gains_result {
196 /* function called when cmd_rs_gains is parsed successfully */
197 static void cmd_rs_gains_parsed(void * parsed_result, void * data)
199 struct cmd_rs_gains_result * res = parsed_result;
201 if (!strcmp_P(res->arg1, PSTR("set"))) {
202 rs_set_left_ext_encoder(&mainboard.rs, encoders_microb_get_value,
203 LEFT_ENCODER, res->left); // en augmentant on tourne à gauche
204 rs_set_right_ext_encoder(&mainboard.rs, encoders_microb_get_value,
205 RIGHT_ENCODER, res->right); //en augmentant on tourne à droite
207 printf_P(PSTR("rs_gains set %f %f"),
208 mainboard.rs.left_ext_gain,
209 mainboard.rs.right_ext_gain);
210 /* f64_print(mainboard.rs.left_ext_gain); */
211 /* printf_P(PSTR(" ")); */
212 /* f64_print(mainboard.rs.right_ext_gain); */
213 printf_P(PSTR("\r\n"));
216 prog_char str_rs_gains_arg0[] = "rs_gains";
217 parse_pgm_token_string_t cmd_rs_gains_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_rs_gains_result, arg0, str_rs_gains_arg0);
218 prog_char str_rs_gains_arg1[] = "set";
219 parse_pgm_token_string_t cmd_rs_gains_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_rs_gains_result, arg1, str_rs_gains_arg1);
220 parse_pgm_token_num_t cmd_rs_gains_l = TOKEN_NUM_INITIALIZER(struct cmd_rs_gains_result, left, FLOAT);
221 parse_pgm_token_num_t cmd_rs_gains_r = TOKEN_NUM_INITIALIZER(struct cmd_rs_gains_result, right, FLOAT);
223 prog_char help_rs_gains[] = "Set rs_gains (left, right)";
224 parse_pgm_inst_t cmd_rs_gains = {
225 .f = cmd_rs_gains_parsed, /* function to call */
226 .data = NULL, /* 2nd arg of func */
227 .help_str = help_rs_gains,
228 .tokens = { /* token list, NULL terminated */
229 (prog_void *)&cmd_rs_gains_arg0,
230 (prog_void *)&cmd_rs_gains_arg1,
231 (prog_void *)&cmd_rs_gains_l,
232 (prog_void *)&cmd_rs_gains_r,
239 prog_char str_rs_gains_show_arg[] = "show";
240 parse_pgm_token_string_t cmd_rs_gains_show_arg = TOKEN_STRING_INITIALIZER(struct cmd_rs_gains_result, arg1, str_rs_gains_show_arg);
242 prog_char help_rs_gains_show[] = "Show rs_gains";
243 parse_pgm_inst_t cmd_rs_gains_show = {
244 .f = cmd_rs_gains_parsed, /* function to call */
245 .data = NULL, /* 2nd arg of func */
246 .help_str = help_rs_gains_show,
247 .tokens = { /* token list, NULL terminated */
248 (prog_void *)&cmd_rs_gains_arg0,
249 (prog_void *)&cmd_rs_gains_show_arg,
254 /**********************************************************/
255 /* track configuration */
257 /* this structure is filled when cmd_track is parsed successfully */
258 struct cmd_track_result {
264 /* function called when cmd_track is parsed successfully */
265 static void cmd_track_parsed(void * parsed_result, void * data)
267 struct cmd_track_result * res = parsed_result;
269 if (!strcmp_P(res->arg1, PSTR("set"))) {
270 position_set_physical_params(&mainboard.pos, res->val, DIST_IMP_MM);
272 printf_P(PSTR("track set %f\r\n"), mainboard.pos.phys.track_mm);
275 prog_char str_track_arg0[] = "track";
276 parse_pgm_token_string_t cmd_track_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_track_result, arg0, str_track_arg0);
277 prog_char str_track_arg1[] = "set";
278 parse_pgm_token_string_t cmd_track_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_track_result, arg1, str_track_arg1);
279 parse_pgm_token_num_t cmd_track_val = TOKEN_NUM_INITIALIZER(struct cmd_track_result, val, FLOAT);
281 prog_char help_track[] = "Set track in mm";
282 parse_pgm_inst_t cmd_track = {
283 .f = cmd_track_parsed, /* function to call */
284 .data = NULL, /* 2nd arg of func */
285 .help_str = help_track,
286 .tokens = { /* token list, NULL terminated */
287 (prog_void *)&cmd_track_arg0,
288 (prog_void *)&cmd_track_arg1,
289 (prog_void *)&cmd_track_val,
296 prog_char str_track_show_arg[] = "show";
297 parse_pgm_token_string_t cmd_track_show_arg = TOKEN_STRING_INITIALIZER(struct cmd_track_result, arg1, str_track_show_arg);
299 prog_char help_track_show[] = "Show track";
300 parse_pgm_inst_t cmd_track_show = {
301 .f = cmd_track_parsed, /* function to call */
302 .data = NULL, /* 2nd arg of func */
303 .help_str = help_track_show,
304 .tokens = { /* token list, NULL terminated */
305 (prog_void *)&cmd_track_arg0,
306 (prog_void *)&cmd_track_show_arg,
313 /**********************************************************/
314 /* Pt_Lists for testing traj */
316 #define PT_LIST_SIZE 10
317 static struct xy_point pt_list[PT_LIST_SIZE];
318 static uint16_t pt_list_len = 0;
320 /* this structure is filled when cmd_pt_list is parsed successfully */
321 struct cmd_pt_list_result {
329 /* function called when cmd_pt_list is parsed successfully */
330 static void cmd_pt_list_parsed(void * parsed_result, void * data)
332 struct cmd_pt_list_result * res = parsed_result;
335 if (!strcmp_P(res->arg1, PSTR("append"))) {
336 res->arg2 = pt_list_len;
339 if (!strcmp_P(res->arg1, PSTR("insert")) ||
340 !strcmp_P(res->arg1, PSTR("append"))) {
341 if (res->arg2 > pt_list_len) {
342 printf_P(PSTR("Index too large\r\n"));
345 if (pt_list_len >= PT_LIST_SIZE) {
346 printf_P(PSTR("List is too large\r\n"));
349 memmove(&pt_list[res->arg2+1], &pt_list[res->arg2],
350 PT_LIST_SIZE-1-res->arg2);
351 pt_list[res->arg2].x = res->arg3;
352 pt_list[res->arg2].y = res->arg4;
355 else if (!strcmp_P(res->arg1, PSTR("del"))) {
356 if (pt_list_len <= 0) {
357 printf_P(PSTR("Error: list empty\r\n"));
360 if (res->arg2 > pt_list_len) {
361 printf_P(PSTR("Index too large\r\n"));
364 memmove(&pt_list[res->arg2], &pt_list[res->arg2+1],
365 (PT_LIST_SIZE-1-res->arg2)*sizeof(struct xy_point));
368 else if (!strcmp_P(res->arg1, PSTR("reset"))) {
372 /* else it is a "show" or a "start" */
373 if (pt_list_len == 0) {
374 printf_P(PSTR("List empty\r\n"));
377 for (i=0 ; i<pt_list_len ; i++) {
378 printf_P(PSTR("%d: x=%d y=%d\r\n"), i, pt_list[i].x, pt_list[i].y);
379 if (!strcmp_P(res->arg1, PSTR("start"))) {
380 trajectory_goto_xy_abs(&mainboard.traj, pt_list[i].x, pt_list[i].y);
381 why = wait_traj_end(0xFF); /* all */
383 else if (!strcmp_P(res->arg1, PSTR("avoid_start"))) {
385 //why = goto_and_avoid(pt_list[i].x, pt_list[i].y, 0xFF, 0xFF);
386 printf("next point\r\n");
387 if (why != END_OBSTACLE)
391 if (why & (~(END_TRAJ | END_NEAR)))
392 trajectory_stop(&mainboard.traj);
396 prog_char str_pt_list_arg0[] = "pt_list";
397 parse_pgm_token_string_t cmd_pt_list_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_pt_list_result, arg0, str_pt_list_arg0);
398 prog_char str_pt_list_arg1[] = "insert";
399 parse_pgm_token_string_t cmd_pt_list_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_pt_list_result, arg1, str_pt_list_arg1);
400 parse_pgm_token_num_t cmd_pt_list_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_pt_list_result, arg2, UINT16);
401 parse_pgm_token_num_t cmd_pt_list_arg3 = TOKEN_NUM_INITIALIZER(struct cmd_pt_list_result, arg3, INT16);
402 parse_pgm_token_num_t cmd_pt_list_arg4 = TOKEN_NUM_INITIALIZER(struct cmd_pt_list_result, arg4, INT16);
404 prog_char help_pt_list[] = "Insert point in pt_list (idx,x,y)";
405 parse_pgm_inst_t cmd_pt_list = {
406 .f = cmd_pt_list_parsed, /* function to call */
407 .data = NULL, /* 2nd arg of func */
408 .help_str = help_pt_list,
409 .tokens = { /* token list, NULL terminated */
410 (prog_void *)&cmd_pt_list_arg0,
411 (prog_void *)&cmd_pt_list_arg1,
412 (prog_void *)&cmd_pt_list_arg2,
413 (prog_void *)&cmd_pt_list_arg3,
414 (prog_void *)&cmd_pt_list_arg4,
421 prog_char str_pt_list_arg1_append[] = "append";
422 parse_pgm_token_string_t cmd_pt_list_arg1_append = TOKEN_STRING_INITIALIZER(struct cmd_pt_list_result, arg1, str_pt_list_arg1_append);
424 prog_char help_pt_list_append[] = "Append point in pt_list (x,y)";
425 parse_pgm_inst_t cmd_pt_list_append = {
426 .f = cmd_pt_list_parsed, /* function to call */
427 .data = NULL, /* 2nd arg of func */
428 .help_str = help_pt_list_append,
429 .tokens = { /* token list, NULL terminated */
430 (prog_void *)&cmd_pt_list_arg0,
431 (prog_void *)&cmd_pt_list_arg1_append,
432 (prog_void *)&cmd_pt_list_arg3,
433 (prog_void *)&cmd_pt_list_arg4,
440 prog_char str_pt_list_del_arg[] = "del";
441 parse_pgm_token_string_t cmd_pt_list_del_arg = TOKEN_STRING_INITIALIZER(struct cmd_pt_list_result, arg1, str_pt_list_del_arg);
443 prog_char help_pt_list_del[] = "Del or insert point in pt_list (num)";
444 parse_pgm_inst_t cmd_pt_list_del = {
445 .f = cmd_pt_list_parsed, /* function to call */
446 .data = NULL, /* 2nd arg of func */
447 .help_str = help_pt_list_del,
448 .tokens = { /* token list, NULL terminated */
449 (prog_void *)&cmd_pt_list_arg0,
450 (prog_void *)&cmd_pt_list_del_arg,
451 (prog_void *)&cmd_pt_list_arg2,
457 prog_char str_pt_list_show_arg[] = "show#reset#start#avoid_start";
458 parse_pgm_token_string_t cmd_pt_list_show_arg = TOKEN_STRING_INITIALIZER(struct cmd_pt_list_result, arg1, str_pt_list_show_arg);
460 prog_char help_pt_list_show[] = "Show, start or reset pt_list";
461 parse_pgm_inst_t cmd_pt_list_show = {
462 .f = cmd_pt_list_parsed, /* function to call */
463 .data = NULL, /* 2nd arg of func */
464 .help_str = help_pt_list_show,
465 .tokens = { /* token list, NULL terminated */
466 (prog_void *)&cmd_pt_list_arg0,
467 (prog_void *)&cmd_pt_list_show_arg,
474 /**********************************************************/
477 /* this structure is filled when cmd_goto is parsed successfully */
478 struct cmd_goto_result {
486 /* function called when cmd_goto is parsed successfully */
487 static void cmd_goto_parsed(void * parsed_result, void * data)
489 struct cmd_goto_result * res = parsed_result;
493 interrupt_traj_reset();
494 if (!strcmp_P(res->arg1, PSTR("a_rel"))) {
495 trajectory_a_rel(&mainboard.traj, res->arg2);
497 else if (!strcmp_P(res->arg1, PSTR("d_rel"))) {
498 trajectory_d_rel(&mainboard.traj, res->arg2);
500 else if (!strcmp_P(res->arg1, PSTR("a_abs"))) {
501 trajectory_a_abs(&mainboard.traj, res->arg2);
503 else if (!strcmp_P(res->arg1, PSTR("a_to_xy"))) {
504 trajectory_turnto_xy(&mainboard.traj, res->arg2, res->arg3);
506 else if (!strcmp_P(res->arg1, PSTR("a_behind_xy"))) {
507 trajectory_turnto_xy_behind(&mainboard.traj, res->arg2, res->arg3);
509 else if (!strcmp_P(res->arg1, PSTR("xy_rel"))) {
510 trajectory_goto_xy_rel(&mainboard.traj, res->arg2, res->arg3);
512 else if (!strcmp_P(res->arg1, PSTR("xy_abs"))) {
513 trajectory_goto_xy_abs(&mainboard.traj, res->arg2, res->arg3);
515 else if (!strcmp_P(res->arg1, PSTR("avoid"))) {
516 //err = goto_and_avoid_forward(res->arg2, res->arg3, 0xFF, 0xFF);
518 if (err != END_TRAJ && err != END_NEAR)
521 else if (!strcmp_P(res->arg1, PSTR("avoid_bw"))) {
522 //err = goto_and_avoid_backward(res->arg2, res->arg3, 0xFF, 0xFF);
524 if (err != END_TRAJ && err != END_NEAR)
527 else if (!strcmp_P(res->arg1, PSTR("xy_abs_fow"))) {
528 trajectory_goto_forward_xy_abs(&mainboard.traj, res->arg2, res->arg3);
530 else if (!strcmp_P(res->arg1, PSTR("xy_abs_back"))) {
531 trajectory_goto_backward_xy_abs(&mainboard.traj, res->arg2, res->arg3);
533 else if (!strcmp_P(res->arg1, PSTR("da_rel"))) {
534 trajectory_d_a_rel(&mainboard.traj, res->arg2, res->arg3);
537 while ((err = test_traj_end(0xFF)) == 0) {
539 if (t2 - t1 > 200000) {
540 dump_cs_debug("angle", &mainboard.angle.cs);
541 dump_cs_debug("distance", &mainboard.distance.cs);
545 if (err != END_TRAJ && err != END_NEAR)
547 printf_P(PSTR("returned %s\r\n"), get_err(err));
550 prog_char str_goto_arg0[] = "goto";
551 parse_pgm_token_string_t cmd_goto_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_goto_result, arg0, str_goto_arg0);
552 prog_char str_goto_arg1_a[] = "d_rel#a_rel#a_abs";
553 parse_pgm_token_string_t cmd_goto_arg1_a = TOKEN_STRING_INITIALIZER(struct cmd_goto_result, arg1, str_goto_arg1_a);
554 parse_pgm_token_num_t cmd_goto_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_goto_result, arg2, INT32);
557 prog_char help_goto1[] = "Change orientation of the mainboard";
558 parse_pgm_inst_t cmd_goto1 = {
559 .f = cmd_goto_parsed, /* function to call */
560 .data = NULL, /* 2nd arg of func */
561 .help_str = help_goto1,
562 .tokens = { /* token list, NULL terminated */
563 (prog_void *)&cmd_goto_arg0,
564 (prog_void *)&cmd_goto_arg1_a,
565 (prog_void *)&cmd_goto_arg2,
570 prog_char str_goto_arg1_b[] = "xy_rel#xy_abs#xy_abs_fow#xy_abs_back#da_rel#a_to_xy#avoid#avoid_bw#a_behind_xy";
571 parse_pgm_token_string_t cmd_goto_arg1_b = TOKEN_STRING_INITIALIZER(struct cmd_goto_result, arg1, str_goto_arg1_b);
572 parse_pgm_token_num_t cmd_goto_arg3 = TOKEN_NUM_INITIALIZER(struct cmd_goto_result, arg3, INT32);
575 prog_char help_goto2[] = "Go to a (x,y) or (d,a) position";
576 parse_pgm_inst_t cmd_goto2 = {
577 .f = cmd_goto_parsed, /* function to call */
578 .data = NULL, /* 2nd arg of func */
579 .help_str = help_goto2,
580 .tokens = { /* token list, NULL terminated */
581 (prog_void *)&cmd_goto_arg0,
582 (prog_void *)&cmd_goto_arg1_b,
583 (prog_void *)&cmd_goto_arg2,
584 (prog_void *)&cmd_goto_arg3,
589 /**********************************************************/
592 /* this structure is filled when cmd_position is parsed successfully */
593 struct cmd_position_result {
601 #define AUTOPOS_SPEED_FAST 200
602 static void auto_position(void)
605 uint16_t old_spdd, old_spda;
607 interrupt_traj_reset();
608 strat_get_speed(&old_spdd, &old_spda);
609 strat_set_speed(AUTOPOS_SPEED_FAST, AUTOPOS_SPEED_FAST);
611 trajectory_d_rel(&mainboard.traj, -300);
612 err = wait_traj_end(END_INTR|END_TRAJ|END_BLOCKING);
616 strat_reset_pos(ROBOT_LENGTH/2, 0, 0);
618 trajectory_d_rel(&mainboard.traj, 120);
619 err = wait_traj_end(END_INTR|END_TRAJ);
623 trajectory_a_rel(&mainboard.traj, 90);
624 err = wait_traj_end(END_INTR|END_TRAJ);
628 trajectory_d_rel(&mainboard.traj, -300);
629 err = wait_traj_end(END_INTR|END_TRAJ|END_BLOCKING);
633 strat_reset_pos(DO_NOT_SET_POS, ROBOT_LENGTH/2,
636 trajectory_d_rel(&mainboard.traj, 120);
637 err = wait_traj_end(END_INTR|END_TRAJ);
642 trajectory_a_rel(&mainboard.traj, -40);
643 err = wait_traj_end(END_INTR|END_TRAJ);
648 strat_set_speed(old_spdd, old_spda);
653 strat_set_speed(old_spdd, old_spda);
656 /* function called when cmd_position is parsed successfully */
657 static void cmd_position_parsed(void * parsed_result, void * data)
659 struct cmd_position_result * res = parsed_result;
661 /* display raw position values */
662 if (!strcmp_P(res->arg1, PSTR("reset"))) {
663 position_set(&mainboard.pos, 0, 0, 0);
665 else if (!strcmp_P(res->arg1, PSTR("set"))) {
666 position_set(&mainboard.pos, res->arg2, res->arg3, res->arg4);
668 else if (!strcmp_P(res->arg1, PSTR("autoset_green"))) {
671 else if (!strcmp_P(res->arg1, PSTR("autoset_red"))) {
675 /* else it's just a "show" */
676 printf_P(PSTR("x=%.2f y=%.2f a=%.2f\r\n"),
677 position_get_x_double(&mainboard.pos),
678 position_get_y_double(&mainboard.pos),
679 DEG(position_get_a_rad_double(&mainboard.pos)));
682 prog_char str_position_arg0[] = "position";
683 parse_pgm_token_string_t cmd_position_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_position_result, arg0, str_position_arg0);
684 prog_char str_position_arg1[] = "show#reset#autoset_green#autoset_red";
685 parse_pgm_token_string_t cmd_position_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_position_result, arg1, str_position_arg1);
687 prog_char help_position[] = "Show/reset (x,y,a) position";
688 parse_pgm_inst_t cmd_position = {
689 .f = cmd_position_parsed, /* function to call */
690 .data = NULL, /* 2nd arg of func */
691 .help_str = help_position,
692 .tokens = { /* token list, NULL terminated */
693 (prog_void *)&cmd_position_arg0,
694 (prog_void *)&cmd_position_arg1,
700 prog_char str_position_arg1_set[] = "set";
701 parse_pgm_token_string_t cmd_position_arg1_set = TOKEN_STRING_INITIALIZER(struct cmd_position_result, arg1, str_position_arg1_set);
702 parse_pgm_token_num_t cmd_position_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_position_result, arg2, INT32);
703 parse_pgm_token_num_t cmd_position_arg3 = TOKEN_NUM_INITIALIZER(struct cmd_position_result, arg3, INT32);
704 parse_pgm_token_num_t cmd_position_arg4 = TOKEN_NUM_INITIALIZER(struct cmd_position_result, arg4, INT32);
706 prog_char help_position_set[] = "Set (x,y,a) position";
707 parse_pgm_inst_t cmd_position_set = {
708 .f = cmd_position_parsed, /* function to call */
709 .data = NULL, /* 2nd arg of func */
710 .help_str = help_position_set,
711 .tokens = { /* token list, NULL terminated */
712 (prog_void *)&cmd_position_arg0,
713 (prog_void *)&cmd_position_arg1_set,
714 (prog_void *)&cmd_position_arg2,
715 (prog_void *)&cmd_position_arg3,
716 (prog_void *)&cmd_position_arg4,