clothoid
[aversive.git] / modules / devices / robot / trajectory_manager / trajectory_manager.c
1 /*
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  *
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.
8  *
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.
13  *
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
17  *
18  *  Revision : $Id: trajectory_manager.c,v 1.4.4.17 2009-05-18 12:28:36 zer0 Exp $
19  *
20  */
21
22 /* Trajectory Manager v3 - zer0 - for Eurobot 2010 */
23
24 #include <string.h>
25 #include <stdlib.h>
26 #include <math.h>
27
28 #include <aversive.h>
29 #include <aversive/error.h>
30 #include <scheduler.h>
31 #include <vect2.h>
32
33 #include <position_manager.h>
34 #include <robot_system.h>
35 #include <control_system_manager.h>
36 #include <quadramp.h>
37
38 #include <trajectory_manager.h>
39 #include "trajectory_manager_utils.h"
40
41 /************ INIT FUNCS */
42
43 /** structure initialization */
44 void trajectory_init(struct trajectory *traj, double cs_hz)
45 {
46         uint8_t flags;
47
48         IRQ_LOCK(flags);
49         memset(traj, 0, sizeof(struct trajectory));
50         traj->cs_hz = cs_hz;
51         traj->state = READY;
52         traj->scheduler_task = -1;
53         IRQ_UNLOCK(flags);
54 }
55
56 /** structure initialization */
57 void trajectory_set_cs(struct trajectory *traj, struct cs *cs_d,
58                        struct cs *cs_a)
59 {
60         uint8_t flags;
61
62         IRQ_LOCK(flags);
63         traj->csm_distance = cs_d;
64         traj->csm_angle = cs_a;
65         IRQ_UNLOCK(flags);
66 }
67
68 /** structure initialization */
69 void trajectory_set_robot_params(struct trajectory *traj,
70                                  struct robot_system *rs,
71                                  struct robot_position *pos)
72 {
73         uint8_t flags;
74         IRQ_LOCK(flags);
75         traj->robot = rs;
76         traj->position = pos;
77         IRQ_UNLOCK(flags);
78 }
79
80 /** set speed consign */
81 void trajectory_set_speed(struct trajectory *traj, double d_speed, double a_speed)
82 {
83         uint8_t flags;
84         IRQ_LOCK(flags);
85         traj->d_speed = d_speed;
86         traj->a_speed = a_speed;
87         IRQ_UNLOCK(flags);
88 }
89
90 /** set acc consign */
91 void trajectory_set_acc(struct trajectory *traj, double d_acc, double a_acc)
92 {
93         uint8_t flags;
94         IRQ_LOCK(flags);
95         traj->d_acc = d_acc;
96         traj->a_acc = a_acc;
97         IRQ_UNLOCK(flags);
98 }
99
100 /** set windows for trajectory */
101 void trajectory_set_windows(struct trajectory *traj, double d_win,
102                             double a_win_deg, double a_start_deg)
103 {
104         uint8_t flags;
105         IRQ_LOCK(flags);
106         traj->d_win = d_win ;
107         traj->a_win_rad = RAD(a_win_deg);
108         traj->a_start_rad = RAD(a_start_deg);
109         IRQ_UNLOCK(flags);
110 }
111
112 /** set corrective coef for circle */
113 void trajectory_set_circle_coef(struct trajectory *traj, double coef)
114 {
115         uint8_t flags;
116         IRQ_LOCK(flags);
117         traj->circle_coef = coef ;
118         IRQ_UNLOCK(flags);
119 }