87a955a3367bb252ab1bc6af088af83b155ab5e2
[aversive.git] / modules / devices / robot / trajectory_manager / trajectory_manager_core.h
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 /**
25  * update angle and/or distance
26  * this function is not called directly by the user
27  *   traj  : pointer to the trajectory structure
28  *   d_mm  : distance in mm
29  *   a_rad : angle in radian
30  *   flags : what to update (UPDATE_A, UPDATE_D)
31  */
32 void __trajectory_goto_d_a_rel(struct trajectory *traj, double d_mm,
33                                double a_rad, uint8_t state, uint8_t flags);
34
35 /** go straight forward (d is in mm) */
36 void trajectory_d_rel(struct trajectory *traj, double d_mm);
37
38 /** update distance consign without changing angle consign */
39 void trajectory_only_d_rel(struct trajectory *traj, double d_mm);
40
41 /** turn by 'a' degrees */
42 void trajectory_a_rel(struct trajectory *traj, double a_deg_rel);
43
44 /** turn by 'a' degrees */
45 void trajectory_a_abs(struct trajectory *traj, double a_deg_abs);
46
47 /** turn the robot until the point x,y is in front of us */
48 void trajectory_turnto_xy(struct trajectory *traj, double x_abs_mm, double y_abs_mm);
49
50
51 /** turn the robot until the point x,y is behind us */
52 void trajectory_turnto_xy_behind(struct trajectory *traj, double x_abs_mm, double y_abs_mm);
53
54
55 /** update angle consign without changing distance consign */
56 void trajectory_only_a_rel(struct trajectory *traj, double a_deg);
57
58 /** update angle consign without changing distance consign */
59 void trajectory_only_a_abs(struct trajectory *traj, double a_deg_abs);
60
61
62 /** turn by 'a' degrees */
63 void trajectory_d_a_rel(struct trajectory *traj, double d_mm, double a_deg);
64
65 /** set relative angle and distance consign to 0 */
66 void trajectory_stop(struct trajectory *traj);
67
68 /** set relative angle and distance consign to 0, and break any
69  * deceleration ramp in quadramp filter */
70 void trajectory_hardstop(struct trajectory *traj);
71
72
73 /************ GOTO XY, USE EVENTS */
74
75 /** goto a x,y point, using a trajectory event */
76 void trajectory_goto_xy_abs(struct trajectory *traj, double x, double y);
77
78 /** go forward to a x,y point, using a trajectory event */
79 void trajectory_goto_forward_xy_abs(struct trajectory *traj, double x, double y);
80
81 /** go backward to a x,y point, using a trajectory event */
82 void trajectory_goto_backward_xy_abs(struct trajectory *traj, double x, double y);
83
84 /** go forward to a d,a point, using a trajectory event */
85 void trajectory_goto_d_a_rel(struct trajectory *traj, double d, double a);
86
87 /** go forward to a x,y relative point, using a trajectory event */
88 void trajectory_goto_xy_rel(struct trajectory *traj, double x_rel_mm, double y_rel_mm);
89
90 /************ FUNCS FOR GETTING TRAJ STATE */
91
92 uint8_t trajectory_angle_finished(struct trajectory *traj);
93 uint8_t trajectory_distance_finished(struct trajectory *traj);
94
95 /** return true if the position consign is equal to the filtered
96  * position consign (after quadramp filter), for angle and
97  * distance. */
98 uint8_t trajectory_finished(struct trajectory *traj);
99
100 /** return true if traj is nearly finished */
101 uint8_t trajectory_in_window(struct trajectory *traj, double d_win, double a_win_rad);
102
103 /*********** *TRAJECTORY EVENT FUNC */
104
105 /** event called for xy trajectories */
106 void trajectory_manager_xy_event(struct trajectory *traj);
107
108 /* trajectory event for circles */
109 void trajectory_manager_circle_event(struct trajectory *traj);
110
111 /* trajectory event */
112 void trajectory_manager_event(void * param);
113
114 /*********** *CIRCLE */
115
116 /* XXX TODO */
117
118 /*********** CLITOID */
119
120 /**
121  * do a superb curve joining line1 to line2 which is composed of:
122  *   - a clothoid starting from line1
123  *   - a circle
124  *   - another clothoid up to line2
125  * this curve is called a clitoid (hehe)
126  *
127  * the function assumes that the initial linear speed is Vd and
128  * angular speed is 0.
129  *
130  * - x,y,a: starting position
131  * - advance: parameter for line following
132  * - alpha: total angle
133  * - beta: circular part of angle (lower than alpha)
134  * - R: the radius of the circle (must be != 0)
135  * - Vd: linear speed to use (in imp per cs period)
136  * - Amax: maximum angular acceleration
137  * - d_inter: distance in mm until the intersection of the
138  *            2 lines
139  *
140  * return 0 if trajectory can be loaded, then it is processed in
141  * background.
142  */
143 int8_t trajectory_clitoid(struct trajectory *traj,
144                           double x, double y, double a, double advance,
145                           double alpha_deg, double beta_deg, double R_mm,
146                           double d_inter_mm);