00001
00012 #ifndef __robot__
00013 #define __robot__
00014
00015 #include <stdint.h>
00016 #include <stdio.h>
00017 #include <mcl.h>
00018 #include <RobotType.h>
00019 #include "RobotTypeArr.h"
00020 #include "roboevent.h"
00021 #include <fsm.h>
00022 #include "fsmloc.h"
00023
00024 #define LAS_CNT 12
00025
00026 #define LAS_MEAS_CNTI 0
00027 #define LAS_MEAS_PERI 1
00028 #define LAS_MEAS_DATAI 2
00029
00030
00031 #define FSM_CNT 5
00032
00033
00034 enum robot_fsm_id {
00035 FSM_ID_MAIN = 0,
00036 FSM_ID_DET = 1,
00037 FSM_ID_LOC = 2,
00038 FSM_ID_MOTION = 3,
00039 FSM_ID_PICKUP = 4
00040 };
00041
00042 #define FSM(id) (&robot.fsm[FSM_ID_##id])
00043 #define FSM_GET_BY_ID(id) (&robot.fsm[FSM_ID_##id])
00044
00045 enum bottle_sens_state {
00046 NOTHING = 0,
00047 FAR,
00048 CLOSE
00049 };
00050
00051
00052 struct robo_pos {
00053 double x;
00054 double y;
00055 double phi;
00056 };
00057
00058 struct bottle_sens {
00059 uint8_t sens1;
00060 uint8_t sens2;
00061 uint8_t sens3;
00062 uint8_t sens4;
00063 };
00064
00065
00066
00067 #define __robot_lock_act_pos lock_act_pos
00068 #define __robot_lock_est_pos lock
00069 #define __robot_lock_goal lock
00070 #define __robot_lock_IRsensors lock
00071 #define __robot_lock_joy lock
00072 #define __robot_lock_laser_recv lock
00073 #define __robot_lock_new_trajectory lock
00074 #define __robot_lock_sharpsOpponent lock
00075 #define __robot_lock_sharpsWaste lock
00076
00077
00078 struct robo_priv {
00079 long long cnt;
00080 unsigned char mode;
00081 pthread_mutex_t lock;
00082 pthread_mutex_t lock_act_pos;
00083
00086 void *new_trajectory;
00087
00088 unsigned char isTrajectory;
00089 unsigned char start;
00090
00091
00092 struct robo_fsm fsm[FSM_CNT];
00093
00094
00095 struct mcl_model mcl;
00096
00097 struct position_type act_pos;
00098
00099
00100 struct position_type est_pos;
00101
00102 struct position_type goal;
00103
00104 struct position_type move_dpos;
00105
00106
00107 struct laserData_type laser_recv;
00108 struct motionSpeed_type orte_speed;
00109
00110 struct stateServa_type serva;
00111 struct sharpShorts_type sharpsWaste;
00112 struct sharpLongs_type sharpsOpponent;
00113 struct stateInnerIR_type IRsensors;
00114 struct stateDigIn_type startBit;
00115 struct stateFrontDoor_type frontDoorAngle;
00116
00117 struct bottle_sens bott_sens;
00118
00119 struct motionPos_type odometry;
00120
00121 struct joyData_type joy;
00122
00123 ORTEPublication *publisherMotor;
00124 ORTEPublication *publisherServa;
00125 ORTEPublication *publisherPosition;
00126
00127 int bottle_under_belt;
00128 int waste_cnt;
00129
00130 };
00131
00132
00133 enum {
00134 ROBO_COMPETING = 0,
00135 ROBO_TESTING
00136 };
00137
00138
00139 extern struct robo_priv robot;
00140
00141
00142
00147 #define ROBOT_LOCK(var) (pthread_mutex_lock(&robot.__robot_lock_##var))
00148
00153 #define ROBOT_UNLOCK(var) (pthread_mutex_unlock(&robot.__robot_lock_##var))
00154
00155
00156
00157 #ifdef __cplusplus
00158 extern "C" {
00159 #endif
00160
00161 void initOrte();
00162 void terminateOrte();
00163 int robot_init();
00164 int robot_start();
00165 int robot_exit();
00166 int robot_wait();
00167 int robot_destroy();
00168
00169 FSM_STATE_DECL(main_init);
00170 FSM_STATE_DECL(start_pickup);
00171 FSM_STATE_DECL(move_init);
00172 FSM_STATE_DECL(det_start);
00173 FSM_STATE_DECL(loc_init);
00174
00175 #ifdef __cplusplus
00176 }
00177 #endif
00178
00179
00183 #define DEBUG
00184 #ifdef DEBUG
00185 #define PROG_NAME "robot"
00186 #define DBG(f, a...) printf(f, ## a)
00187 #define DBGPROG(f, a...) printf(PROG_NAME ": " f, ## a)
00188 #else
00189 #define DBG(f, a...) do { } while(0);
00190 #define DBGPROG(f, a...) do { } while(0);
00191 #endif
00192
00193
00194
00195 #define ROBOT_WIDTH_MM 290
00196 #define ROBOT_ROTATION_RADIUS_MM (254/2)
00197 #define LASER_CENTER_OFFSET_MM 50
00198 #define ROBOT_WHEEL_RADIUS_MM 40
00199 #define ROBOT_AXIS_TO_BACK_MM 75
00200 #define ROBOT_AXIS_TO_FRONT_MM 183
00201 #define ROBOT_AXIS_TO_BELT_MM 280
00202
00203 #define PLAYGROUND_WIDTH_MM 3000
00204 #define PLAYGROUND_HEIGHT_MM 2100
00205
00206
00207 #define TRAJ_FOLLOWER_PRIO 255
00208 #define TRAJ_RECALC_PRIO 0
00209 #define SET_THREAD_PRIORITY(tid,prio) \
00210 sched_param param; \
00211 pthread_attr_t tattr; \
00212 pthread_attr_init (&tattr); \
00213 pthread_attr_getschedparam (&tattr, ¶m); \
00214 param.sched_priority = prio;\
00215 pthread_attr_setschedparam (&tattr, ¶m);
00216
00217 #endif