1 #ifndef MOVEHELPER_EB2008_H
2 #define MOVEHELPER_EB2008_H
6 #include <trgenconstr.h>
12 TOP_TURN_CW, /* Clockwise */
13 TOP_TURN_CCW, /* Counter-clockwise */
14 TOP_TURN_SHORTEST, /* Shortest turn */
15 TOP_ARRIVE_FROM /* Arrive to the final point from the given direction */
18 struct move_target_heading {
19 enum move_target_op operation;
21 float distance; /* Distance used by TOP_ARRIVE_FROM */
24 static inline struct move_target_heading __target_heading(enum move_target_op op, float angle, float distance)
26 struct move_target_heading th;
29 th.distance = distance;
33 #define TURN(heading) __target_heading(TOP_TURN_SHORTEST, (heading), 0)
34 #define TURN_CW(heading) __target_heading(TOP_TURN_CW, (heading), 0)
35 #define TURN_CCW(heading) __target_heading(TOP_TURN_CCW, (heading), 0)
36 #define NO_TURN() __target_heading(TOP_DONT_TURN, 0, 0)
37 #define ARRIVE_FROM(heading, dist) __target_heading(TOP_ARRIVE_FROM, (heading), (dist))
39 static inline struct final_heading target2final_heading(struct move_target_heading th)
41 struct final_heading fh;
43 switch (th.operation) {
44 case TOP_DONT_TURN: fh.turn_type = FH_DONT_TURN; break;
45 case TOP_TURN_CW: fh.turn_type = FH_CW; break;
46 case TOP_TURN_CCW: fh.turn_type = FH_CCW; break;
47 case TOP_TURN_SHORTEST: fh.turn_type = FH_SHORTEST; break;
48 case TOP_ARRIVE_FROM: fh.turn_type = FH_DONT_TURN; break;
50 fh.heading = th.angle;
54 /* Represents the target position of a move. */
57 struct move_target_heading heading;
58 struct TrajectoryConstraints tc; /* if (trajectory) taken from it */
61 /** If trajectory is NULL, it is generated by motion FSM
62 * according to the above fields. Otherwise, the trajectory
63 * specified here is used and the above fields are used only
64 * for replanning in case of colision. */
68 extern struct TrajectoryConstraints trajectoryConstraintsDefault;
74 /* extern double target_x, target_y; */
76 #if defined(WE_ARE_RED) && defined(WE_ARE_GREEN)
77 #error Both colors defined
80 #if !defined(WE_ARE_RED) && !defined(WE_ARE_GREEN)
81 #error No colors defined
85 static inline double __trans_ang(double phi)
88 a = M_PI/2.0 - phi + M_PI/2.0;
89 a = fmod(a, 2.0*M_PI);
90 if (phi >= 0 && a >= 0) a -= 2.0*M_PI;
91 if (phi < 0 && a < 0) a += 2.0*M_PI;
94 static inline struct move_target_heading __trans_heading(struct move_target_heading h)
96 if (h.operation != TOP_DONT_TURN) {
97 h.angle = __trans_ang(h.angle);
98 switch (h.operation) {
100 h.operation = TOP_TURN_CCW;
103 h.operation = TOP_TURN_CW;
112 #define TRANS_X(x) (PLAYGROUND_WIDTH_M - (x))
113 #define TRANS_Y(y) (y)
114 #define TRANS_ANG(a) __trans_ang(a)
115 #define TRANS_HEADING(h) __trans_heading(h)
119 #define TRANS_X(x) (x)
120 #define TRANS_Y(y) (y)
121 #define TRANS_ANG(a) (a)
122 #define TRANS_HEADING(h) (h)
125 bool get_arrive_from_point(double target_x_m, double target_y_m,
126 struct move_target_heading heading,
127 double *point_x_m, double *point_y_m);
130 void robot_set_est_pos_notrans(double x, double y, double phi);
131 #define robot_set_est_pos_trans(x, y, phi) robot_set_est_pos_notrans(TRANS_X(x), TRANS_Y(y), TRANS_ANG(phi))
133 void robot_send_speed(double left, double right);
135 /* Low-level trajectory handling */
136 void robot_trajectory_new(struct TrajectoryConstraints *tc);
137 void robot_trajectory_new_backward(struct TrajectoryConstraints *tc);
139 void robot_trajectory_add_point_notrans(double x_m, double y_m);
140 #define robot_trajectory_add_point_trans(x, y) robot_trajectory_add_point_notrans(TRANS_X(x), TRANS_Y(y))
142 void robot_trajectory_add_final_point_notrans(double x_m, double y_m, struct move_target_heading heading);
143 #define robot_trajectory_add_final_point_trans(x, y, heading) robot_trajectory_add_final_point_notrans(TRANS_X(x), TRANS_Y(y), TRANS_HEADING(heading))
145 /** Stop robot immediately */
148 /** Go to a point using path planning to avoid apriori known obstacles */
149 void robot_goto_notrans(double x, double y, struct move_target_heading heading, struct TrajectoryConstraints *tc);
150 #define robot_goto_trans(x, y, heading, tc) robot_goto_notrans(TRANS_X(x), TRANS_Y(y), TRANS_HEADING(heading), tc)
152 /** Move to a point using straight line trajectory. If ARIVE_FROM is
153 * set, then the trajectory will be composed two lines.... TODO */
154 void robot_moveto_notrans(double x, double y, struct move_target_heading heading, struct TrajectoryConstraints *tc);
155 #define robot_moveto_trans(x, y, heading, tc) robot_goto_notrans(TRANS_X(x), TRANS_Y(y), TRANS_HEADING(heading), tc)
157 /* Relative movement */
158 void robot_move_by(double distance, struct move_target_heading heading, struct TrajectoryConstraints *tc);
159 #define robot_move_by_trans(distance, heading, tc) robot_move_by(distance, TRANS_HEADING(heading), tc)
161 /* FIXME: not used anywhere */
162 static inline void robot_translate_coordinates(double *x, double *y, double *phi)
168 *phi = TRANS_ANG(*phi);
172 void init_ekf(float x, float y, float ang);
180 #endif /* MOVEHELPER_EB2008_H */