00001 #define FSM_MAIN
00002 #include "fsmmove.h"
00003 #include "movehelper.h"
00004 #include "robot.h"
00005 #include "trgen.h"
00006 #include <path_planner.h>
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <sys/shm.h>
00010 #include <sys/stat.h>
00011 #include <math.h>
00012 #include <map.h>
00013
00014
00015 FSM_STATE_DECL(robot_goto_test);
00016
00017 FSM_STATE(main_init) {
00018 ShmapInit(1);
00019
00020 ROBOT_LOCK(act_pos);
00021 robot.act_pos.x = 0.5;
00022 robot.act_pos.y = 0.5;
00023 robot.act_pos.phi = 0;
00024 ROBOT_UNLOCK(act_pos);
00025 FSM_TRANSITION(robot_goto_test);
00026 }
00027
00028
00029
00030 FSM_STATE(robot_goto_test)
00031 {
00032 double goalx, goaly;
00033 switch (FSM_EVENT) {
00034 case EV_STATE_ENTERED:
00035 ShmapSetRectangleType(0.0, 0.0, 0.2, 2.1, MAP_WALL_CSPACE);
00036 ShmapSetRectangleType(0.0, 0.0, 3.0, 0.2, MAP_WALL_CSPACE);
00037 ShmapSetRectangleType(0.0, 2.0, 3.0, 2.1, MAP_WALL_CSPACE);
00038 ShmapSetRectangleType(2.9, 0.0, 3.0, 2.1, MAP_WALL_CSPACE);
00039 ShmapSetRectangleType(1.3, 0.8, 1.7, 1.2, MAP_WALL_CSPACE);
00040 ShmapSetRectangleType(1.8, 1.5, 2.3, 1.8, MAP_WALL_CSPACE);
00041 ShmapSetRectangleType(1.4, 0.9, 1.6, 1.1, MAP_WALL);
00042 ShmapSetRectangleType(1.9, 1.6, 2.2, 1.7, MAP_WALL);
00043 do {
00044 goalx = (rand()%(MAP_PLAYGROUND_WIDTH_MM-50)+25)/1000.0;
00045 goaly = ((rand()%(MAP_PLAYGROUND_HEIGHT_MM-50)+25)/1000.0);
00046 } while (!ShmapIsFreePoint(goalx, goaly));
00047
00048 robot_goto( goalx, goaly);
00049 break;
00050 case EV_MOTION_DONE:
00051 FSM_TIMER(1000);
00052 break;
00053 case EV_GOAL_IS_TMP_OBSTACLE:
00054 case EV_GOAL_IS_OBSTACLE:
00055 case EV_GOAL_NOT_REACHABLE:
00056 DBG("Goal is not reachable: %s\n",fsm_event_str(FSM_EVENT));
00057 FSM_TIMER(10000);
00058 break;
00059 case EV_TIMER:
00060 ShmapClearOldPath();
00061 FSM_TRANSITION(robot_goto_test);
00062 break;
00063 case EV_START:
00064
00065 break;
00066 case EV_EXIT:
00067
00068 break;
00069 default:
00070 break;
00071 }
00072 }
00073
00074 int main()
00075 {
00076
00077 robot_init();
00078 srand(time(0));
00079 FSM(MAIN)->debug_states = 1;
00080 FSM(MOTION)->debug_states = 1;
00081
00082 FSM(MAIN)->state = &fsm_state_main_init;
00083 FSM(MOTION)->state = &fsm_state_move_init;
00084
00085 FSM(DET)->state = &fsm_state_det_start;
00086 FSM(PICKUP)->state = &fsm_state_start_pickup;
00087
00088
00089 robot_start();
00090 robot_wait();
00091
00092
00093 robot_destroy();
00094
00095 return 0;
00096 }