5fe3865d6db8032962daa79c3fbf58c117143b5d
[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)
45 {
46         uint8_t flags;
47
48         IRQ_LOCK(flags);
49         memset(traj, 0, sizeof(struct trajectory));
50         traj->state = READY;
51         traj->scheduler_task = -1;
52         IRQ_UNLOCK(flags);
53 }
54
55 /** structure initialization */
56 void trajectory_set_cs(struct trajectory *traj, struct cs *cs_d,
57                        struct cs *cs_a)
58 {
59         uint8_t flags;
60
61         IRQ_LOCK(flags);
62         traj->csm_distance = cs_d;
63         traj->csm_angle = cs_a;
64         IRQ_UNLOCK(flags);
65 }
66
67 /** structure initialization */
68 void trajectory_set_robot_params(struct trajectory *traj,
69                                  struct robot_system *rs,
70                                  struct robot_position *pos)
71 {
72         uint8_t flags;
73         IRQ_LOCK(flags);
74         traj->robot = rs;
75         traj->position = pos;
76         IRQ_UNLOCK(flags);
77 }
78
79 /** set speed consign */
80 void trajectory_set_speed( struct trajectory *traj, int16_t d_speed, int16_t a_speed)
81 {
82         uint8_t flags;
83         IRQ_LOCK(flags);
84         traj->d_speed = d_speed;
85         traj->a_speed = a_speed;
86         IRQ_UNLOCK(flags);
87 }
88
89 /** set windows for trajectory */
90 void trajectory_set_windows(struct trajectory *traj, double d_win,
91                             double a_win_deg, double a_start_deg)
92 {
93         uint8_t flags;
94         IRQ_LOCK(flags);
95         traj->d_win = d_win ;
96         traj->a_win_rad = RAD(a_win_deg);
97         traj->a_start_rad = RAD(a_start_deg);
98         IRQ_UNLOCK(flags);
99 }
100
101
102