command circle set coef
[aversive.git] / modules / devices / robot / position_manager / position_manager.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: position_manager.h,v 1.5.4.4 2009-05-18 12:27:26 zer0 Exp $
19  *
20  */
21
22
23 #ifndef _ROBOT_POSITION_MANAGER_H_
24 #define _ROBOT_POSITION_MANAGER_H_
25
26 #include <math.h>
27 #include <robot_system.h>
28
29 /** 
30  * structure that stores the number of impulsions that corresponds to
31  * a mm or a degre. We also need to specify the track of the
32  */
33 struct robot_physical_params 
34 {
35         double track_mm;
36         double distance_imp_per_mm;
37 };
38
39
40 /** 
41  * stores a cartesian position on the area in double
42  * WARNING : a is stored in radian
43  */
44 struct xya_position 
45 {
46         double x;
47         double y;
48         double a;
49 };
50
51 /**
52  * stores a cartesian position on the area in integers
53  * WARNING : a is stored in degree
54  */
55 struct xya_position_s16
56 {
57         int16_t x;
58         int16_t y;
59         int16_t a;
60 };
61
62 /**
63  * Structure that stores everthing we need to get and stores the
64  * position of the robot 
65  */
66 struct robot_position
67 {
68         uint8_t use_ext;
69         struct robot_physical_params phys;
70         struct xya_position pos_d;
71         struct xya_position_s16 pos_s16;
72         struct rs_polar prev_encoders;
73         struct robot_system *rs;
74 #ifdef CONFIG_MODULE_COMPENSATE_CENTRIFUGAL_FORCE       
75         double centrifugal_coef;
76 #endif
77 };
78
79
80 /** initialization of the robot_position pos, everthing is set to 0 */
81 void position_init(struct robot_position *pos);
82
83 #ifdef CONFIG_MODULE_COMPENSATE_CENTRIFUGAL_FORCE       
84 /** set arbitrary coef to compensate the centrifugal force */
85 void position_set_centrifugal_coef(struct robot_position *pos, double coef);
86 #endif
87
88 /** Set a new robot position */
89 void position_set(struct robot_position *pos, int16_t x, int16_t y, int16_t a);
90
91 void position_use_ext(struct robot_position *pos);
92 void position_use_mot(struct robot_position *pos);
93
94
95 /** 
96  * Set the physical parameters of the robot : 
97  *  - distance between wheels (track, in mm)
98  *  - number of impulsions for 1 mm (distance)
99  */
100 void position_set_physical_params(struct robot_position *pos, double track_mm,
101                                   double distance_imp_per_mm);
102
103 /** 
104  * Save in pos structure the pointer to the associated robot_system. 
105  * The robot_system structure is used to get values from virtual encoders
106  * that return angle and distance.
107  */
108 void position_set_related_robot_system(struct robot_position *pos, struct robot_system *rs);
109
110 /** 
111  * Process the absolute position (x,y,a) depending on the delta on
112  * virtual encoders since last read, and depending on physical
113  * parameters.
114  */
115 void position_manage(struct robot_position *pos);
116
117
118 /**
119  * returns current x
120  */
121 int16_t position_get_x_s16(struct robot_position *pos);
122
123 /**
124  * returns current y
125  */
126 int16_t position_get_y_s16(struct robot_position *pos);
127
128 /**
129  * returns current alpha
130  */
131 int16_t position_get_a_deg_s16(struct robot_position *pos);
132
133 /**
134  * returns current x
135  */
136 double position_get_x_double(struct robot_position *pos);
137
138 /**
139  * returns current y
140  */
141 double position_get_y_double(struct robot_position *pos);
142
143 /**
144  * returns current alpha
145  */
146 double position_get_a_rad_double(struct robot_position *pos);
147
148
149 #endif