2 * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
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: trajectory_manager.h,v 1.4.4.10 2009-05-02 10:03:04 zer0 Exp $
22 #ifndef TRAJECTORY_MANAGER
23 #define TRAJECTORY_MANAGER
27 #include <robot_system.h>
28 #include <vect_base.h>
31 enum trajectory_state {
34 /* simple trajectories */
39 /* trajectories using events */
45 RUNNING_XY_F_ANGLE_OK,
48 RUNNING_XY_B_ANGLE_OK,
57 struct circle_target {
58 vect2_cart center; /**< center of the circle */
59 double radius; /**< radius of the circle */
60 int32_t dest_angle; /**< dst angle in inc */
62 #define TRIGO 1 /* rotation is counterclockwise */
63 #define FORWARD 2 /* go forward or backward */
64 uint8_t flags; /**< flags for this trajectory */
74 enum trajectory_state state; /*<< describe the type of target, and if we reached the target */
77 vect2_cart cart; /**<< target, if it is a x,y vector */
78 struct rs_polar pol; /**<< target, if it is a d,a vector */
79 struct circle_target circle; /**<< target, if it is a circle */
80 struct line_target line; /**<< target, if it is a line */
83 double d_win; /**<< distance window (for END_NEAR) */
84 double a_win_rad; /**<< angle window (for END_NEAR) */
85 double a_start_rad;/**<< in xy consigns, start to move in distance
86 * when a_target < a_start */
87 double circle_coef;/**<< corrective circle coef */
89 uint16_t d_speed; /**<< distance speed consign */
90 uint16_t a_speed; /**<< angle speed consign */
92 struct robot_position *position; /**<< associated robot_position */
93 struct robot_system *robot; /**<< associated robot_system */
94 struct cs *csm_angle; /**<< associated control system (angle) */
95 struct cs *csm_distance; /**<< associated control system (distance) */
97 int8_t scheduler_task; /**<< id of current task (-1 if no running task) */
100 /** structure initialization */
101 void trajectory_init(struct trajectory *traj);
103 /** structure initialization */
104 void trajectory_set_cs(struct trajectory *traj, struct cs *cs_d,
107 /** structure initialization */
108 void trajectory_set_robot_params(struct trajectory *traj,
109 struct robot_system *rs,
110 struct robot_position *pos) ;
112 /** set speed consign */
113 void trajectory_set_speed(struct trajectory *traj, int16_t d_speed, int16_t a_speed);
116 * set windows for trajectory.
117 * params: distance window, angle window: we the robot enters this
118 * position window, we deletes the event and the last consign is
120 * a_start_deg used in xy consigns (start to move in distance when
121 * a_target < a_start)
123 void trajectory_set_windows(struct trajectory *traj, double d_win,
124 double a_win_deg, double a_start_deg);
127 * Set coef for circle trajectory. The objective of this value is to
128 * fix the radius of the circle which is not correctly what we asked.
130 void trajectory_set_circle_coef(struct trajectory *traj, double coef);
132 /** return true if the position consign is equal to the filtered
133 * position consign (after quadramp filter), for angle and
135 uint8_t trajectory_finished(struct trajectory *traj);
137 /** return true if traj is nearly finished depending on specified
139 uint8_t trajectory_in_window(struct trajectory *traj, double d_win, double a_win_rad);
141 /* simple commands */
143 /** set relative angle and distance consign to 0 */
144 void trajectory_stop(struct trajectory *traj);
146 /** set relative angle and distance consign to 0, and break any
147 * deceleration ramp in quadramp filter */
148 void trajectory_hardstop(struct trajectory *traj);
150 /** go straight forward (d is in mm) */
151 void trajectory_d_rel(struct trajectory *traj, double d_mm);
153 /** update distance consign without changing angle consign */
154 void trajectory_only_d_rel(struct trajectory *traj, double d_mm);
156 /** turn by 'a' degrees */
157 void trajectory_a_rel(struct trajectory *traj, double a_deg);
159 /** go to angle 'a' in degrees */
160 void trajectory_a_abs(struct trajectory *traj, double a_deg);
162 /** turn the robot until the point x,y is in front of us */
163 void trajectory_turnto_xy(struct trajectory*traj, double x_abs_mm, double y_abs_mm);
165 /** turn the robot until the point x,y is behind us */
166 void trajectory_turnto_xy_behind(struct trajectory*traj, double x_abs_mm, double y_abs_mm);
168 /** update angle consign without changing distance consign */
169 void trajectory_only_a_rel(struct trajectory *traj, double a_deg);
171 /** update angle consign without changing distance consign */
172 void trajectory_only_a_abs(struct trajectory *traj, double a_deg);
174 /** turn by 'a' degrees and go by 'd' mm */
175 void trajectory_d_a_rel(struct trajectory *traj, double d_mm, double a_deg);
177 /* commands using events */
179 /** goto a x,y point, using a trajectory event */
180 void trajectory_goto_xy_abs(struct trajectory *traj, double x_abs_mm, double y_abs_mm);
182 /** go forward to a x,y point, using a trajectory event */
183 void trajectory_goto_forward_xy_abs(struct trajectory *traj, double x_abs_mm, double y_abs_mm);
185 /** go backward to a x,y point, using a trajectory event */
186 void trajectory_goto_backward_xy_abs(struct trajectory *traj, double x_abs_mm, double y_abs_mm);
188 /** go forward to a d,a point, using a trajectory event */
189 void trajectory_goto_d_a_rel(struct trajectory *traj, double d, double a);
191 /** go forward to a x,y relative point, using a trajectory event */
192 void trajectory_goto_xy_rel(struct trajectory *traj, double x_rel_mm, double y_rel_mm);
194 /** make the robot orbiting around (x,y) on a circle whose radius is
195 * radius_mm, and exit when relative destination angle is reached. The
196 * flags set if we go forward or backwards, and CW/CCW. */
197 void trajectory_circle_rel(struct trajectory *traj, double x, double y,
198 double radius_mm, double rel_a_deg, uint8_t flags);
201 * Compute the fastest distance and angle speeds matching the radius
202 * from current traj_speed
204 void circle_get_da_speed_from_radius(struct trajectory *traj,
210 void trajectory_line_abs(struct trajectory *traj, double x1, double y1,
211 double x2, double y2, double advance);
213 #endif //TRAJECTORY_MANAGER