2 * robot_eb2008.h 08/04/20
4 * Robot's data structures for the Eurobot 2008.
6 * Copyright: (c) 2008 CTU Dragons
7 * CTU FEE - Department of Control Engineering
11 #ifndef ROBOT_EB2008_H
12 #define ROBOT_EB2008_H
16 #include <mcl_laser.h>
17 #include <trgenconstr.h>
18 #include <robottype.h>
19 #include <robottype_eb2008.h>
20 #include <roboorte_generic.h>
21 #include <roboorte_eb2008.h>
22 #include <robodim_eb2008.h>
23 #include <roboevent_eb2008.h>
25 #include <servos_eb2008.h>
26 #include <robot_config.h>
28 /* Select robot color. If we are BLUE, no coordinate transformation will
34 * Competition parameters
63 #define LAS_CNT 12 /* dont forget to change CRA!! */
64 /* index of information in times array */
65 #define LAS_MEAS_CNTI 0 /* counter index of measured times */
66 #define LAS_MEAS_PERI 1 /* period index */
67 #define LAS_MEAS_DATAI 2 /* data index */
70 * LOCKING MANIPULATION
73 #ifdef CONFIG_LOCK_CHECKING
74 #define LOCK_CHECK_COUNT 10
76 pthread_mutex_t *locked[LOCK_CHECK_COUNT];
80 extern struct lock_log robot_lock_log;
82 #define __LOCK_CHECK(mutex) robot_lock_log.locked[robot_lock_log.idx++] = mutex;
83 #define __UNLOCK_CHECK(mutex) \
84 if (robot_lock_log.locked[--robot_lock_log.idx] != mutex || \
85 robot_lock_log.idx < 0) \
86 printf("!!! Locking error %s:%d\n", __FILE__, __LINE__);
88 #define __LOCK_CHECK(mutex)
89 #define __UNLOCK_CHECK(mutex)
92 * Locks the robot structure.
93 * @param var Field in the structure you are going to work with.
95 #define ROBOT_LOCK(var) \
97 pthread_mutex_lock(&robot.__robot_lock_##var); \
98 __LOCK_CHECK(&robot.__robot_lock_##var); \
102 * Unlocks the robot structure.
103 * @param var Field in the structure, which was locked by ROBOT_LOCK.
105 #define ROBOT_UNLOCK(var) \
107 __UNLOCK_CHECK(&robot.__robot_lock_##var); \
108 pthread_mutex_unlock(&robot.__robot_lock_##var); \
111 /* Mapping of robot structure fields to locks */
112 //#define __robot_lock_ lock /* ROBOT_LOCK() */
113 #define __robot_lock_ref_pos lock_ref_pos
114 #define __robot_lock_est_pos lock_est_pos
115 #define __robot_lock_des_pos lock
116 #define __robot_lock_joy_data lock_joy_data
117 #define __robot_lock_meas_angles lock_meas_angles
118 #define __robot_lock_drives lock
119 #define __robot_lock_sharps lock
120 #define __robot_lock_cmu lock
121 #define __robot_lock_bumper lock
122 #define __robot_lock_drives lock
123 #define __robot_lock_disp lock_disp
125 /* robot's main data structure */
126 struct robot_eb2008 {
129 pthread_mutex_t lock;
130 pthread_mutex_t lock_ref_pos;
131 pthread_mutex_t lock_est_pos;
132 pthread_mutex_t lock_meas_angles;
133 pthread_mutex_t lock_joy_data;
134 pthread_mutex_t lock_disp;
136 /* competition parameters */
137 unsigned char team_color;
138 unsigned char beacon_color;
140 #define CAROUSEL_SIZE 5
141 #define BALL_TO_COLLECT 5
142 enum ball_color carousel[CAROUSEL_SIZE];
143 unsigned char carousel_cnt; /* The number of balls in carousel */
144 unsigned char carousel_pos; /* required position of the carousel */
146 /** Temporary storage for new trajectory. After the trajectory creation is
147 * finished, this trajectory is submitted to fsmmove. */
148 void *new_trajectory;
150 unsigned char isTrajectory;
154 struct robo_fsm fsm[FSM_CNT];
156 /* actual position */
157 struct ref_pos_type ref_pos;
158 /* estimated position */
159 struct est_pos_type est_pos;
161 struct motion_irc_type odometry;
162 struct joy_data_type joy_data;
163 struct drives_type drives;
166 struct eb2008_orte_data orte;
167 struct generic_orte_data gorte;
170 struct sharps_type sharps;
171 struct bumper_type bumper;
175 struct mcl_model *mcl; /* Pointer to the generic MCL model */
176 struct mcl_laser laser; /* MCL implementation for laser */
178 struct map *map; /* Map for pathplanning (no locking) */
180 struct sercom_data *sercom; /* Sercom for display */
182 /* information about HW units status - for display */
183 uint8_t hw_status[6];
185 bool obstacle_avoidance_enabled;
186 }; /* robot_eb2008 */
188 extern struct robot_eb2008 robot;
200 /* Hack to easily disable display if it is not configured */
201 void serial_comm(int status);
205 FSM_STATE_FULL_DECL(main, init);
206 FSM_STATE_FULL_DECL(motion, init);
207 FSM_STATE_FULL_DECL(loc, init);
208 FSM_STATE_FULL_DECL(joy, init);
209 FSM_STATE_FULL_DECL(disp, init);
215 /*Thread priorities*/
216 #define THREAD_PRIO_TRAJ_FOLLOWER 255 /* As high as possible */
217 #define THREAD_PRIO_MOTION 30
218 #define THREAD_PRIO_MAIN 25
219 #define THREAD_PRIO_LOC 20
220 #define THREAD_PRIO_TRAJ_RECLAC 18
221 #define OBST_FORGETING_PRIO 17 /* Priority of the thread for forgeting detected obstacles. */
222 #define THREAD_PRIO_DISP 15
223 #define THREAD_PRIO_JOY 10
226 #endif /* ROBOT_EB2008_H */