Test du path finding

Dependencies:   RoboClaw mbed

Fork of TestMyPathFind by Romain Ame

Committer:
IceTeam
Date:
Wed Jan 20 17:13:01 2016 +0100
Revision:
25:8e7f24c3d05f
Parent:
20:b2f3757fd7ee
Child:
26:6c5c453602ff
Petit commit de merging

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sype 0:ad9600df4a70 1 #include "Odometry.h"
IceTeam 17:e32b4b54fc04 2 /** Dependencies :
IceTeam 17:e32b4b54fc04 3 Map/Point.h
IceTeam 17:e32b4b54fc04 4 Map/define.h
IceTeam 17:e32b4b54fc04 5 Map/Obstacles/Obstacle.h
IceTeam 20:b2f3757fd7ee 6
IceTeam 20:b2f3757fd7ee 7 Test en cours :
IceTeam 20:b2f3757fd7ee 8 * Un obstacle seulement
IceTeam 20:b2f3757fd7ee 9 * Radius du robot réduit à 1 (defines.cpp)
IceTeam 20:b2f3757fd7ee 10 * Nombreux
IceTeam 17:e32b4b54fc04 11 */
IceTeam 12:5355aed288b0 12 #include "Map/Map.h"
sype 0:ad9600df4a70 13
sype 0:ad9600df4a70 14 #define dt 10000
sype 10:ae3178aa94e9 15 #define ATTENTE 0
sype 10:ae3178aa94e9 16 #define GO 1
sype 10:ae3178aa94e9 17 #define STOP 2
sype 0:ad9600df4a70 18
sype 10:ae3178aa94e9 19 InterruptIn mybutton(USER_BUTTON);
sype 10:ae3178aa94e9 20 DigitalIn button(USER_BUTTON);
sype 2:abdf8c6823a1 21 DigitalOut led(LED1);
sype 0:ad9600df4a70 22 Ticker ticker;
sype 10:ae3178aa94e9 23 //Serial pc(USBTX, USBRX);
sype 10:ae3178aa94e9 24 Serial pc(PA_9, PA_10);
sype 10:ae3178aa94e9 25 RoboClaw roboclaw(460800, PA_11, PA_12);
sype 10:ae3178aa94e9 26 Odometry odo(63.2, 63.3, 252, 4096, roboclaw);
sype 10:ae3178aa94e9 27
sype 10:ae3178aa94e9 28 int i = 0;
sype 0:ad9600df4a70 29
sype 0:ad9600df4a70 30 void update_main(void);
sype 2:abdf8c6823a1 31 void init(void);
sype 10:ae3178aa94e9 32 void pressed(void);
sype 10:ae3178aa94e9 33 void unpressed(void);
sype 0:ad9600df4a70 34
IceTeam 9:e39b218ab20d 35 /** Debut du programme */
sype 0:ad9600df4a70 36 int main(void)
sype 10:ae3178aa94e9 37 {
sype 10:ae3178aa94e9 38 double angle_v = 2*PI/5;
sype 10:ae3178aa94e9 39 double distance_v = 200.0;
IceTeam 12:5355aed288b0 40 std::vector<SimplePoint> path;
IceTeam 12:5355aed288b0 41 Map map;
IceTeam 12:5355aed288b0 42
sype 2:abdf8c6823a1 43 init();
IceTeam 18:0f1fefe78266 44 //Construction des obstacles
IceTeam 17:e32b4b54fc04 45 map.build();
IceTeam 25:8e7f24c3d05f 46 map.Astar(0, 1000, 2000, 1000);
IceTeam 13:a394e27b8cb2 47 path = map.path;
IceTeam 13:a394e27b8cb2 48
IceTeam 18:0f1fefe78266 49 for(int i=0; i<path.size();i++) {
IceTeam 12:5355aed288b0 50 odo.GotoXYT(path[i].x, path[i].y, 0);
IceTeam 18:0f1fefe78266 51 }
IceTeam 12:5355aed288b0 52
IceTeam 12:5355aed288b0 53 //odo.GotoXYT(500, 50, 0);
sype 10:ae3178aa94e9 54 //odo.GotoXYT(200, 0, 0);
sype 10:ae3178aa94e9 55 //odo.GotoXYT(0, 0, 0);
sype 10:ae3178aa94e9 56
sype 10:ae3178aa94e9 57 //odo.GotoThet(-PI/2);
sype 10:ae3178aa94e9 58 wait(2000);
sype 10:ae3178aa94e9 59 //odo.GotoXYT(2250,500,0);
sype 2:abdf8c6823a1 60 while(1);
sype 2:abdf8c6823a1 61 }
sype 2:abdf8c6823a1 62
sype 2:abdf8c6823a1 63 void init(void)
sype 0:ad9600df4a70 64 {
sype 10:ae3178aa94e9 65 pc.baud(9600);
sype 2:abdf8c6823a1 66 pc.printf("Hello from main !\n\r");
sype 10:ae3178aa94e9 67 wait_ms(500);
sype 10:ae3178aa94e9 68
sype 10:ae3178aa94e9 69 odo.setPos(0, 0, 0);
sype 2:abdf8c6823a1 70 roboclaw.ForwardM1(ADR, 0);
sype 2:abdf8c6823a1 71 roboclaw.ForwardM2(ADR, 0);
sype 10:ae3178aa94e9 72
sype 10:ae3178aa94e9 73 while(button);
sype 10:ae3178aa94e9 74 wait(1);
sype 10:ae3178aa94e9 75 mybutton.fall(&pressed);
sype 10:ae3178aa94e9 76 mybutton.rise(&unpressed);
sype 0:ad9600df4a70 77 ticker.attach_us(&update_main,dt); // 100 Hz
sype 0:ad9600df4a70 78 }
sype 0:ad9600df4a70 79
sype 0:ad9600df4a70 80 void update_main(void)
sype 0:ad9600df4a70 81 {
sype 0:ad9600df4a70 82 odo.update_odo();
sype 10:ae3178aa94e9 83 //pc.printf("X : %3.2f\tY : %3.2f\tTheta : %3.2f\n\r", odo.getX(), odo.getY(), odo.getTheta()*180/PI);
sype 2:abdf8c6823a1 84 //if(pc.readable()) if(pc.getc()=='l') led = !led;
sype 0:ad9600df4a70 85 }
sype 10:ae3178aa94e9 86
sype 10:ae3178aa94e9 87 void pressed(void)
sype 10:ae3178aa94e9 88 {
sype 10:ae3178aa94e9 89 if(i==0) {
sype 10:ae3178aa94e9 90 roboclaw.ForwardM1(ADR, 0);
sype 10:ae3178aa94e9 91 roboclaw.ForwardM2(ADR, 0);
sype 10:ae3178aa94e9 92 //pc.printf("X : %3.2f\tY : %3.2f\tTheta : %3.2f\n\r", odo.getX(), odo.getY(), odo.getTheta()*180/PI);
sype 10:ae3178aa94e9 93 i++;
sype 10:ae3178aa94e9 94 }
sype 10:ae3178aa94e9 95 }
sype 10:ae3178aa94e9 96
sype 10:ae3178aa94e9 97 void unpressed(void)
sype 10:ae3178aa94e9 98 {
sype 10:ae3178aa94e9 99 if(i==1) {
sype 10:ae3178aa94e9 100 i--;
sype 10:ae3178aa94e9 101 }
sype 10:ae3178aa94e9 102 }