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
36 enum robot_start_state {
46 /* Mapping from FSM ID to field in robot.fsm */
47 #define ROBOT_FSM_MAIN main
48 #define ROBOT_FSM_MOTION motion
49 #define ROBOT_FSM_DISPLAY display
50 #define ROBOT_FSM_ACT act
52 #define FSM_GET_BY_ID(fsm_id) (&robot.fsm.ROBOT_FSM_##fsm_id)
55 * LOCKING MANIPULATION
58 #ifdef CONFIG_LOCK_CHECKING
59 #define LOCK_CHECK_COUNT 10
61 pthread_mutex_t *locked[LOCK_CHECK_COUNT];
65 extern struct lock_log robot_lock_log;
67 #define __LOCK_CHECK(mutex) robot_lock_log.locked[robot_lock_log.idx++] = mutex;
68 #define __UNLOCK_CHECK(mutex) \
69 if (robot_lock_log.locked[--robot_lock_log.idx] != mutex || \
70 robot_lock_log.idx < 0) \
71 ul_logerr("!!! Locking error %s:%d\n", __FILE__, __LINE__);
73 #define __LOCK_CHECK(mutex)
74 #define __UNLOCK_CHECK(mutex)
77 * Locks the robot structure.
78 * @param var Field in the structure you are going to work with.
80 #define ROBOT_LOCK(var) \
82 pthread_mutex_lock(&robot.__robot_lock_##var); \
83 __LOCK_CHECK(&robot.__robot_lock_##var); \
87 * Unlocks the robot structure.
88 * @param var Field in the structure, which was locked by ROBOT_LOCK.
90 #define ROBOT_UNLOCK(var) \
92 __UNLOCK_CHECK(&robot.__robot_lock_##var); \
93 pthread_mutex_unlock(&robot.__robot_lock_##var); \
96 /* Mapping of robot structure fields to locks */
97 //#define __robot_lock_ lock /* ROBOT_LOCK() */
98 #define __robot_lock_ref_pos lock_ref_pos
99 #define __robot_lock_est_pos_uzv lock_est_pos_uzv
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_cmu lock
108 #define __robot_lock_bumper lock
109 #define __robot_lock_drives 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 {
131 ROBOT_COMPONENT_NUMBER
134 /* robot's main data structure */
136 pthread_mutex_t lock;
137 pthread_mutex_t lock_ref_pos;
138 pthread_mutex_t lock_est_pos_uzv;
139 pthread_mutex_t lock_est_pos_odo;
140 pthread_mutex_t lock_est_pos_indep_odo;
141 pthread_mutex_t lock_meas_angles;
142 pthread_mutex_t lock_joy_data;
143 pthread_mutex_t lock_disp;
144 pthread_mutex_t lock_camera;
146 /* competition parameters */
147 enum team_color team_color;
149 /** State variable used for controlling the robot by pluggin
150 * in and out start connector. */
151 enum robot_start_state start_state;
153 /** Temporary storage for new trajectory. After the trajectory creation is
154 * finished, this trajectory is submitted to fsmmove. */
155 void *new_trajectory;
157 unsigned char isTrajectory;
160 struct fsm_main_loop main_loop;
164 struct robo_fsm main;
165 struct robo_fsm motion;
169 /* actual position */
170 struct robot_pos_type ref_pos;
171 /* estimated position */
172 struct robot_pos_type est_pos_uzv;
173 struct robot_pos_type est_pos_odo;
174 struct robot_pos_type est_pos_indep_odo;
176 /** True if localization data arrives correctly and therfore
177 * localization runs */
178 bool localization_works;
179 /** True if est_pos_odo is updated according to reception of motion_irc */
181 /** True if est_pos_indep_odo is updated according to reception of motion_indep_odo */
182 bool indep_odometry_works;
184 bool use_back_switch;
185 bool use_left_switch;
186 bool use_right_switch;
188 /** True iff at least one wheel rotates backward */
192 * sometimes H8S does not send queried odometry
193 * following flag has been added for EKF estimator,
194 * since is has been hardly disturbed by missing measurement
195 * (taken as sudden zero velocities)
197 bool motion_irc_received;
200 struct robottype_orte_data orte;
203 struct motion_irc_type motion_irc; /* motor odometry */
204 struct odo_data_type odo_data; /* independent odometry */
205 struct corr_distances_type corr_distances; /* ultrasound */
207 struct hokuyo_scan_type hokuyo;
210 struct map *map; /* Map for pathplanning (no locking) */
212 enum robot_status status[ROBOT_COMPONENT_NUMBER];
214 char corns_conf_center;
215 char corns_conf_side;
216 struct corns_group *corns;
218 bool obstacle_avoidance_enabled;
220 /** is set to true in separate thread when there is short time left */
221 bool short_time_to_end;
222 bool check_turn_safety;
225 extern struct robot robot;
231 int robot_init() __attribute__ ((warn_unused_result));
232 int robot_start() __attribute__ ((warn_unused_result));
234 void robot_destroy();
236 void robot_get_est_pos_trans(double *x, double *y, double *phi);
237 void robot_get_est_pos(double *x, double *y, double *phi);
239 /* Hack to easily disable display if it is not configured */
240 void serial_comm(int status);
244 FSM_STATE_FULL_DECL(main, init);
245 FSM_STATE_FULL_DECL(motion, init);
246 FSM_STATE_FULL_DECL(disp, init);
247 FSM_STATE_FULL_DECL(act, wait_for_command);
253 /*Thread priorities*/
254 #define THREAD_PRIO_TRAJ_FOLLOWER 90 /* As high as possible */
255 #define THREAD_PRIO_TRAJ_RECLAC 18
256 #define OBST_FORGETING_PRIO 17 /* Priority of the thread for forgeting detected obstacles. */