4 * Robot's data structures for the Eurobot 2008.
6 * Copyright: (c) 2008 CTU Dragons
7 * CTU FEE - Department of Control Engineering
16 #include <mcl_laser.h>
17 #include <trgenconstr.h>
18 #include <robottype.h>
19 #include <robottype.h>
20 #include <roboorte_robottype.h>
23 #include <roboevent.h>
25 #include <robot_config.h>
26 #include "actuators.h"
29 * Competition parameters
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 printf("!!! 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_joy_data lock_joy_data
102 #define __robot_lock_meas_angles lock_meas_angles
103 #define __robot_lock_drives lock
104 #define __robot_lock_sharps lock
105 #define __robot_lock_hokuyo lock
106 #define __robot_lock_cmu lock
107 #define __robot_lock_bumper lock
108 #define __robot_lock_drives lock
109 #define __robot_lock_disp lock_disp
110 #define __robot_lock_motion_irc lock
111 #define __robot_lock_corr_distances lock
112 #define __robot_lock_lift_cmd lock
113 #define __robot_lock_camera_result lock_camera
115 /* robot's main data structure */
117 pthread_mutex_t lock;
118 pthread_mutex_t lock_ref_pos;
119 pthread_mutex_t lock_est_pos_uzv;
120 pthread_mutex_t lock_est_pos_odo;
121 pthread_mutex_t lock_meas_angles;
122 pthread_mutex_t lock_joy_data;
123 pthread_mutex_t lock_disp;
124 pthread_mutex_t lock_camera;
126 /* competition parameters */
127 #define team_color orte.camera_control.game_color
128 // enum team_color team_color;
130 /** State variable used for controlling the robot by pluggin
131 * in and out start connector. */
132 enum robot_state state;
134 /** Temporary storage for new trajectory. After the trajectory creation is
135 * finished, this trajectory is submitted to fsmmove. */
136 void *new_trajectory;
138 unsigned char isTrajectory;
141 struct fsm_main_loop main_loop;
145 struct robo_fsm main;
146 struct robo_fsm motion;
147 struct robo_fsm display;
151 /* actual position */
152 struct robot_pos_type ref_pos;
153 /* estimated position */
154 struct robot_pos_type est_pos_uzv;
155 struct robot_pos_type est_pos_odo;
157 /** True if localization data arrives correctly and therfore
158 * localization runs */
159 bool localization_works;
160 /** True if est_pos_odo is updated according to reception of motion_irc */
163 bool use_back_switch;
165 /** True iff at least one wheel rotates backward */
171 * sometimes H8S does not send queried odometry
172 * following flag has been added for EKF estimator,
173 * since is has been hardly disturbed by missing measurement
174 * (taken as sudden zero velocities)
176 bool motion_irc_received;
179 struct robottype_orte_data orte;
182 struct motion_irc_type motion_irc; /* odometry */
183 struct corr_distances_type corr_distances; /* ultrasound */
184 double puck_distance; /* sharp sensor to puck distance in meters */
186 struct hokuyo_scan_type hokuyo;
188 struct map *map; /* Map for pathplanning (no locking) */
190 struct sercom_data *sercom; /* Sercom for display */
192 /* information about HW units status - for display */
193 uint8_t hw_status[8];
195 char pucks_inside; // number of pucks loaded in the robot
198 bool obstacle_avoidance_enabled;
201 extern struct robot robot;
207 int robot_init() __attribute__ ((warn_unused_result));
208 int robot_start() __attribute__ ((warn_unused_result));
210 void robot_destroy();
212 void robot_get_est_pos(double *x, double *y, double *phi);
214 /* Hack to easily disable display if it is not configured */
215 void serial_comm(int status);
219 FSM_STATE_FULL_DECL(main, init);
220 FSM_STATE_FULL_DECL(motion, init);
221 FSM_STATE_FULL_DECL(disp, init);
222 FSM_STATE_FULL_DECL(act, wait_for_command);
228 /*Thread priorities*/
229 #define THREAD_PRIO_TRAJ_FOLLOWER 255 /* As high as possible */
230 #define THREAD_PRIO_TRAJ_RECLAC 18
231 #define OBST_FORGETING_PRIO 17 /* Priority of the thread for forgeting detected obstacles. */
232 #define THREAD_PRIO_DISP 15
233 #define THREAD_PRIO_JOY 10
235 static inline void act_lift(unsigned short int pos)
238 ROBOT_LOCK(lift_cmd);
240 ROBOT_UNLOCK(lift_cmd);