4 * Robot's data structures for the Eurobot 2008.
6 * Copyright: (c) 2008 CTU Dragons
7 * CTU FEE - Department of Control Engineering
16 #include <trgenconstr.h>
17 #include <robottype.h>
18 #include <robottype.h>
19 #include <roboorte_robottype.h>
21 #include <roboevent.h>
23 #include <robot_config.h>
26 //UL_LOG_CUST(ulogd_robot_h); /* Log domain name = ulogd + name of the file */
29 * Competition parameters
32 TC_WHITE = 0, /* Coordinate transformation does not apply */
37 enum robot_start_state {
47 /* Mapping from FSM ID to field in robot.fsm */
48 #define ROBOT_FSM_MAIN main
49 #define ROBOT_FSM_MOTION motion
50 #define ROBOT_FSM_DISPLAY display
51 #define ROBOT_FSM_ACT act
53 #define FSM_GET_BY_ID(fsm_id) (&robot.fsm.ROBOT_FSM_##fsm_id)
56 * LOCKING MANIPULATION
59 #ifdef CONFIG_LOCK_CHECKING
60 #define LOCK_CHECK_COUNT 10
62 pthread_mutex_t *locked[LOCK_CHECK_COUNT];
66 extern struct lock_log robot_lock_log;
68 #define __LOCK_CHECK(mutex) robot_lock_log.locked[robot_lock_log.idx++] = mutex;
69 #define __UNLOCK_CHECK(mutex) \
70 if (robot_lock_log.locked[--robot_lock_log.idx] != mutex || \
71 robot_lock_log.idx < 0) \
72 ul_logerr("!!! Locking error %s:%d\n", __FILE__, __LINE__);
74 #define __LOCK_CHECK(mutex)
75 #define __UNLOCK_CHECK(mutex)
78 * Locks the robot structure.
79 * @param var Field in the structure you are going to work with.
81 #define ROBOT_LOCK(var) \
83 pthread_mutex_lock(&robot.__robot_lock_##var); \
84 __LOCK_CHECK(&robot.__robot_lock_##var); \
88 * Unlocks the robot structure.
89 * @param var Field in the structure, which was locked by ROBOT_LOCK.
91 #define ROBOT_UNLOCK(var) \
93 __UNLOCK_CHECK(&robot.__robot_lock_##var); \
94 pthread_mutex_unlock(&robot.__robot_lock_##var); \
97 /* Mapping of robot structure fields to locks */
98 //#define __robot_lock_ lock /* ROBOT_LOCK() */
99 #define __robot_lock_ref_pos lock_ref_pos
100 #define __robot_lock_est_pos_odo lock_est_pos_odo
101 #define __robot_lock_est_pos_indep_odo lock_est_pos_indep_odo
102 #define __robot_lock_joy_data lock_joy_data
103 #define __robot_lock_meas_angles lock_meas_angles
104 #define __robot_lock_drives lock
105 #define __robot_lock_sharps lock
106 #define __robot_lock_hokuyo lock
107 #define __robot_lock_sick lock
108 #define __robot_lock_cmu lock
109 #define __robot_lock_bumper lock
110 #define __robot_lock_disp lock_disp
111 #define __robot_lock_motion_irc lock
112 #define __robot_lock_odo_data lock
113 #define __robot_lock_corr_distances lock
114 #define __robot_lock_camera_result lock_camera
122 enum robot_component {
133 ROBOT_COMPONENT_NUMBER
136 /* robot's main data structure */
138 pthread_mutex_t lock;
139 pthread_mutex_t lock_ref_pos;
140 pthread_mutex_t lock_est_pos_odo;
141 pthread_mutex_t lock_est_pos_indep_odo;
142 pthread_mutex_t lock_meas_angles;
143 pthread_mutex_t lock_joy_data;
144 pthread_mutex_t lock_disp;
145 pthread_mutex_t lock_camera;
147 /* competition parameters */
148 enum team_color team_color;
150 /** State variable used for controlling the robot by pluggin
151 * in and out start connector. */
152 enum robot_start_state start_state;
154 /** Temporary storage for new trajectory. After the trajectory creation is
155 * finished, this trajectory is submitted to fsmmove. */
156 void *new_trajectory;
158 unsigned char isTrajectory;
161 struct fsm_main_loop main_loop;
165 struct robo_fsm main;
166 struct robo_fsm motion;
170 /* actual position */
171 struct robot_pos_type ref_pos;
172 /* estimated position */
173 struct robot_pos_type est_pos_odo;
174 struct robot_pos_type est_pos_indep_odo;
176 /** True if est_pos_odo is updated according to reception of motion_irc */
178 /** True if est_pos_indep_odo is updated according to reception of motion_indep_odo */
179 bool indep_odometry_works;
181 bool use_back_bumpers;
182 bool use_left_bumper;
183 bool use_right_bumper;
185 /** True iff at least one wheel rotates backward */
189 * sometimes H8S does not send queried odometry
190 * following flag has been added for EKF estimator,
191 * since is has been hardly disturbed by missing measurement
192 * (taken as sudden zero velocities)
194 bool motion_irc_received;
197 struct robottype_orte_data orte;
200 struct motion_irc_type motion_irc; /* motor odometry */
201 struct odo_data_type odo_data; /* independent odometry */
202 struct corr_distances_type corr_distances; /* ultrasound */
204 struct hokuyo_scan_type hokuyo;
207 struct sick_scan_type sick;
210 /* variables for target detection */
214 char target_color[3];
216 struct map *map; /* Map for pathplanning (no locking) */
218 enum robot_status status[ROBOT_COMPONENT_NUMBER];
220 char corns_conf_center;
221 char corns_conf_side;
222 struct corns_group *corns;
224 bool obstacle_avoidance_enabled;
226 /** is set to true in separate thread when there is short time left */
227 bool short_time_to_end;
228 bool check_turn_safety;
232 float odo_distance_a;
233 float odo_distance_b;
236 extern struct robot robot;
242 int robot_init() __attribute__ ((warn_unused_result));
243 int robot_start() __attribute__ ((warn_unused_result));
245 void robot_destroy();
246 void robot_get_est_pos_trans(double *x, double *y, double *phi);
247 void robot_get_est_pos(double *x, double *y, double *phi);
249 /* Hack to easily disable display if it is not configured */
250 void serial_comm(int status);
254 FSM_STATE_FULL_DECL(main, init);
255 FSM_STATE_FULL_DECL(motion, init);
256 FSM_STATE_FULL_DECL(disp, init);
257 FSM_STATE_FULL_DECL(act, wait_for_command);
263 /*Thread priorities*/
264 #define THREAD_PRIO_TRAJ_FOLLOWER 90 /* As high as possible */
265 #define THREAD_PRIO_TRAJ_RECLAC 18
266 #define OBST_FORGETING_PRIO 17 /* Priority of the thread for forgeting detected obstacles. */