00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #define FSM_DETECT
00012 #include "robot.h"
00013 #include "fsm.h"
00014 #include "fsmmain.h"
00015 #include "movehelper.h"
00016 #include "serva.h"
00017 #include <math.h>
00018
00019 #define WASTE_STACK_EMPTYm 0xe0
00020 #define WASTE_INNER_STACK_BOTTLE1 0x1e
00021 #define WASTE_INNER_STACK_BOTTLE2 0x0f
00022
00023 #define CLOSE_LIMIT 850
00024 #define FAR_LIMIT 650
00025
00026 #define VMAX 0.5;
00027
00028 #define R 0.15
00029
00030 void evaluate_distance(uint16_t value, uint8_t *result) {
00031 if((value > CLOSE_LIMIT)) *result = CLOSE;
00032 else if((value >= FAR_LIMIT)&&(value < CLOSE_LIMIT)) *result = FAR;
00033 else if(value < FAR_LIMIT) *result = NOTHING;
00034 }
00035
00036 FSM_STATE_DECL(det_start);
00037 FSM_STATE_DECL(det_scan);
00038
00039 FSM_STATE(det_start) {
00040 FSM_TIMEOUT(100);
00041
00042 FSM_SIGNAL(MAIN, EV_START);
00043 FSM_TRANSITION(det_scan);
00044
00045 }
00046
00047 FSM_STATE(det_scan) {
00048
00049 FSM_TIMEOUT(100);
00050
00051
00052 robot.waste_cnt = 0;
00053
00054
00055
00056
00057
00058
00059
00060 switch (FSM_EVENT) {
00061 case EV_STATE_ENTERED:
00062 break;
00063 case EV_TIMEOUT:
00064
00065 if(robot.waste_cnt) {
00066 evaluate_distance(robot.sharpsWaste.short1, &robot.bott_sens.sens1);
00067 evaluate_distance(robot.sharpsWaste.short2, &robot.bott_sens.sens2);
00068 evaluate_distance(robot.sharpsWaste.short3, &robot.bott_sens.sens3);
00069 evaluate_distance(robot.sharpsWaste.short4, &robot.bott_sens.sens4);
00070
00071 FSM_SIGNAL(MAIN, EV_DETECTED_BOTTLE);
00072 break;
00073 }
00074
00075
00076
00077 if(robot.joy.button1 == 1) innerTransporterStop();
00078 if(robot.joy.button2 == 1) frontTransporterStop();
00079 if(robot.joy.button3 == 1) frontDoorDown();
00080 if(robot.joy.button4 == 1) frontTransporterBackward();
00081 if(robot.joy.button5 == 1) frontDoorUp();
00082 if(robot.joy.button6 == 1) frontTransporterForward();
00083 if(robot.joy.button7 == 1) innerDoorDown();
00084 if(robot.joy.button8 == 1) innerDoorUp();
00085 if(robot.joy.button9 == 1) backDoorDown();
00086 if(robot.joy.button10 == 1) backDoorUp();
00087 if(robot.joy.button11 == 1) innerTransporterLeft();
00088 if(robot.joy.button12 == 1) innerTransporterRight();
00089
00090 #ifdef JOYSTICK_NAV // if joystick is used for navigating
00091 v = (double)robot.joy.axisY/32768;
00092 omega = (double)robot.joy.axisX/32768;
00093 lenght = sqrt( pow(v,2) + pow(omega,2));
00094 if (lenght >= 1)
00095 {
00096 angle = tan2(robot.joy.axisX/robot.joy.axisY);
00097 v = sin(angle);
00098 omega = cos(angle);
00099 }
00100
00101 speedL = (v - R*omega)*VMAX;
00102 speedR = -(v + R*omega)*VMAX;
00103 robot_send_speed(speedL, speedR);
00104 printf("v %f, omega %f\n",v, omega);
00105 printf("length %f, angle %f\n",lenght, angle);
00106 printf("axisX %d, axisY %d\n",robot.joy.axisX, robot.joy.axisY);
00107 printf("sent speed: %f, %f\n",speedL, speedR);
00108 #endif
00109 break;
00110 default:
00111 DBG_PRINT_EVENT("Unhandled event:");
00112 }
00113
00114
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134