test morning

Dependencies:   ISR_Mini-explorer mbed

Fork of roboticLab_withclass_3_July by Georgios Tsamis

Committer:
Ludwigfr
Date:
Fri Jul 07 11:49:30 2017 +0000
Revision:
6:0e8db3a23486
Parent:
5:19f24c363418
Child:
8:072a76960e27
lol;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ludwigfr 0:9f7ee7ed13e4 1 #ifndef MINIEXPLORERCOIMBRA_HPP
Ludwigfr 0:9f7ee7ed13e4 2 #define MINIEXPLORERCOIMBRA_HPP
Ludwigfr 0:9f7ee7ed13e4 3
Ludwigfr 0:9f7ee7ed13e4 4 #include "Map.hpp"
Ludwigfr 0:9f7ee7ed13e4 5 #include "Sonar.hpp"
Ludwigfr 0:9f7ee7ed13e4 6 #include<math.h>
Ludwigfr 0:9f7ee7ed13e4 7
Ludwigfr 0:9f7ee7ed13e4 8 /*
Ludwigfr 0:9f7ee7ed13e4 9 Robot coordinate system: World coordinate system:
Ludwigfr 0:9f7ee7ed13e4 10 ^ ^
Ludwigfr 0:9f7ee7ed13e4 11 |x |y
Ludwigfr 0:9f7ee7ed13e4 12 <--R O-->
Ludwigfr 0:9f7ee7ed13e4 13 y x
Ludwigfr 0:9f7ee7ed13e4 14
Ludwigfr 0:9f7ee7ed13e4 15 angles from pi/2 to 3pi/2->0 to pi angles from 0 to pi->0 to pi
Ludwigfr 0:9f7ee7ed13e4 16 angles from pi/2 to -pi/2->0 to -pi angles from pi to 2pi-> -pi to 0
Ludwigfr 0:9f7ee7ed13e4 17
Ludwigfr 0:9f7ee7ed13e4 18 The idea is that for every command to the robot we use to world coodinate system
Ludwigfr 2:11cd5173aa36 19
Ludwigfr 2:11cd5173aa36 20 The target are relative to the robot position, so if the robot is in 100,80
Ludwigfr 2:11cd5173aa36 21 and the target is -20,30
Ludwigfr 2:11cd5173aa36 22 the robot will go to 80,110
Ludwigfr 2:11cd5173aa36 23 TODO I m pretty sure that a target angle is not relative to the current robot angle
Ludwigfr 0:9f7ee7ed13e4 24 */
Ludwigfr 0:9f7ee7ed13e4 25
Ludwigfr 0:9f7ee7ed13e4 26 class MiniExplorerCoimbra {
Ludwigfr 0:9f7ee7ed13e4 27
Ludwigfr 0:9f7ee7ed13e4 28 public:
Ludwigfr 0:9f7ee7ed13e4 29 float xWorld;
Ludwigfr 0:9f7ee7ed13e4 30 float yWorld;
Ludwigfr 0:9f7ee7ed13e4 31 float thetaWorld;
Ludwigfr 0:9f7ee7ed13e4 32 Map map;
Ludwigfr 0:9f7ee7ed13e4 33 Sonar sonarLeft;
Ludwigfr 0:9f7ee7ed13e4 34 Sonar sonarFront;
Ludwigfr 0:9f7ee7ed13e4 35 Sonar sonarRight;
Ludwigfr 0:9f7ee7ed13e4 36 float speed;
Ludwigfr 0:9f7ee7ed13e4 37 float radiusWheels;
Ludwigfr 0:9f7ee7ed13e4 38 float distanceWheels;
Ludwigfr 0:9f7ee7ed13e4 39 float khro;
Ludwigfr 0:9f7ee7ed13e4 40 float ka;
Ludwigfr 0:9f7ee7ed13e4 41 float kb;
Ludwigfr 0:9f7ee7ed13e4 42 float kv;
Ludwigfr 0:9f7ee7ed13e4 43 float kh;
geotsam 1:20f48907c726 44 float kd;
geotsam 1:20f48907c726 45 float k_linear;
geotsam 1:20f48907c726 46 float k_angular;
Ludwigfr 0:9f7ee7ed13e4 47
Ludwigfr 0:9f7ee7ed13e4 48 float rangeForce;
Ludwigfr 0:9f7ee7ed13e4 49 float attractionConstantForce;
Ludwigfr 0:9f7ee7ed13e4 50 float repulsionConstantForce;
Ludwigfr 5:19f24c363418 51
Ludwigfr 5:19f24c363418 52 float covariancePositionEstimationK[3][3];
Ludwigfr 0:9f7ee7ed13e4 53
Ludwigfr 2:11cd5173aa36 54 MiniExplorerCoimbra(float defaultXWorld, float defaultYWorld, float defaultThetaWorld, float widthRealMap, float heightRealMap);
Ludwigfr 2:11cd5173aa36 55
Ludwigfr 2:11cd5173aa36 56 void test_procedure_lab2(int nbIteration);
Ludwigfr 0:9f7ee7ed13e4 57
Ludwigfr 0:9f7ee7ed13e4 58 //generate a position randomly and makes the robot go there while updating the map
Ludwigfr 0:9f7ee7ed13e4 59 void randomize_and_map();
Ludwigfr 0:9f7ee7ed13e4 60
Ludwigfr 0:9f7ee7ed13e4 61 //move of targetXWorld and targetYWorld ending in a targetAngleWorld
Ludwigfr 0:9f7ee7ed13e4 62 void go_to_point_with_angle(float targetXWorld, float targetYWorld, float targetAngleWorld);
Ludwigfr 0:9f7ee7ed13e4 63
geotsam 1:20f48907c726 64 //move of targetXWorld and targetYWorld ending in a targetAngleWorld without checking the sonars
geotsam 1:20f48907c726 65 void go_to_point_with_angle_first_lab(float targetXWorld, float targetYWorld, float targetAngleWorld);
geotsam 1:20f48907c726 66
Ludwigfr 0:9f7ee7ed13e4 67 //use virtual force field
Ludwigfr 0:9f7ee7ed13e4 68 void try_to_reach_target(float targetXWorld,float targetYWorld);
Ludwigfr 0:9f7ee7ed13e4 69
geotsam 1:20f48907c726 70 void go_to_point(float targetXWorld, float targetYWorld);
geotsam 1:20f48907c726 71
geotsam 1:20f48907c726 72 void go_to_line_first_lab(float line_a, float line_b, float line_c);
geotsam 1:20f48907c726 73
Ludwigfr 2:11cd5173aa36 74 void print_map_with_robot_position_and_target(float targetXWorld, float targetYWorld);
Ludwigfr 2:11cd5173aa36 75
Ludwigfr 2:11cd5173aa36 76 void print_map_with_robot_position();
Ludwigfr 2:11cd5173aa36 77
Ludwigfr 2:11cd5173aa36 78 void test_sonars_and_map(int nbIteration);
Ludwigfr 2:11cd5173aa36 79
Ludwigfr 5:19f24c363418 80 void test_procedure_lab_4(float sizeX, float sizeY, int nbRectangle);
Ludwigfr 5:19f24c363418 81
Ludwigfr 5:19f24c363418 82 void go_straight_kalman(float targetXWorld, float targetYWorld, float targetAngleWorld);
Ludwigfr 5:19f24c363418 83
Ludwigfr 5:19f24c363418 84 void go_turn_kalman(float targetXWorld, float targetYWorld, float targetAngleWorld);
Ludwigfr 5:19f24c363418 85
Ludwigfr 5:19f24c363418 86 void go_to_point_with_angle_kalman(float targetXWorld, float targetYWorld, float targetAngleWorld);
Ludwigfr 5:19f24c363418 87
Ludwigfr 6:0e8db3a23486 88 void OdometriaKalmanFilter();
Ludwigfr 6:0e8db3a23486 89
Ludwigfr 6:0e8db3a23486 90 void test_prediction_sonar();
Ludwigfr 5:19f24c363418 91
Ludwigfr 0:9f7ee7ed13e4 92 private:
Ludwigfr 0:9f7ee7ed13e4 93
Ludwigfr 0:9f7ee7ed13e4 94 void myOdometria();
Ludwigfr 0:9f7ee7ed13e4 95
Ludwigfr 0:9f7ee7ed13e4 96 void setXYThetaAndXYThetaWorld(float defaultXWorld, float defaultYWorld, float defaultThetaWorld);
Ludwigfr 0:9f7ee7ed13e4 97
Ludwigfr 0:9f7ee7ed13e4 98 float update_angular_speed_wheels_go_to_point_with_angle(float targetXWorld, float targetYWorld, float targetAngleWorld, float dt);
Ludwigfr 0:9f7ee7ed13e4 99
Ludwigfr 0:9f7ee7ed13e4 100 void update_sonar_values(float leftMm,float frontMm,float rightMm);
Ludwigfr 0:9f7ee7ed13e4 101
Ludwigfr 0:9f7ee7ed13e4 102 void do_half_flip();
Ludwigfr 0:9f7ee7ed13e4 103
Ludwigfr 0:9f7ee7ed13e4 104 //Distance computation function
Ludwigfr 0:9f7ee7ed13e4 105 float dist(float x1, float y1, float x2, float y2);
Ludwigfr 0:9f7ee7ed13e4 106
geotsam 1:20f48907c726 107 float distFromLine(float robot_x, float robot_y, float line_a, float line_b, float line_c);
geotsam 1:20f48907c726 108
Ludwigfr 0:9f7ee7ed13e4 109 /*angleToTarget is obtained through atan2 so it s:
Ludwigfr 0:9f7ee7ed13e4 110 < 0 if the angle is bettween PI and 2pi on a trigo circle
Ludwigfr 0:9f7ee7ed13e4 111 > 0 if it is between 0 and PI
Ludwigfr 0:9f7ee7ed13e4 112 */
Ludwigfr 0:9f7ee7ed13e4 113 void turn_to_target(float angleToTarget);
Ludwigfr 0:9f7ee7ed13e4 114
Ludwigfr 0:9f7ee7ed13e4 115 void vff(bool* reached, float targetXWorld, float targetYWorld);
Ludwigfr 0:9f7ee7ed13e4 116
Ludwigfr 0:9f7ee7ed13e4 117 //compute the force on X and Y
Ludwigfr 0:9f7ee7ed13e4 118 void compute_forceX_and_forceY(float* forceXWorld, float* forceYWorld, float targetXWorld, float targetYWorld);
Ludwigfr 0:9f7ee7ed13e4 119
Ludwigfr 0:9f7ee7ed13e4 120 void calculate_line(float forceX, float forceY, float *line_a, float *line_b, float *line_c);
Ludwigfr 0:9f7ee7ed13e4 121
Ludwigfr 0:9f7ee7ed13e4 122 //currently line_c is not used
Ludwigfr 0:9f7ee7ed13e4 123 void go_to_line(float line_a, float line_b, float line_c,float targetXWorld, float targetYWorld);
Ludwigfr 0:9f7ee7ed13e4 124
Ludwigfr 0:9f7ee7ed13e4 125 void update_force(int widthIndice, int heightIndice, float* forceRepulsionComputedX, float* forceRepulsionComputedY );
Ludwigfr 0:9f7ee7ed13e4 126
Ludwigfr 0:9f7ee7ed13e4 127 //return 1 if positiv, -1 if negativ
Ludwigfr 0:9f7ee7ed13e4 128 float sign1(float value);
Ludwigfr 0:9f7ee7ed13e4 129
Ludwigfr 0:9f7ee7ed13e4 130 //return 1 if positiv, 0 if negativ
Ludwigfr 0:9f7ee7ed13e4 131 int sign2(float value);
Ludwigfr 0:9f7ee7ed13e4 132
Ludwigfr 0:9f7ee7ed13e4 133 void go_straight_line(float distanceCm);
Ludwigfr 0:9f7ee7ed13e4 134
Ludwigfr 0:9f7ee7ed13e4 135 void procedure_lab_4(float xEstimatedK,float yEstimatedK, float thetaWorldEstimatedK, float distanceMoved, float angleMoved, float PreviousCovarianceOdometricPositionEstimate[3][3]);
Ludwigfr 0:9f7ee7ed13e4 136
Ludwigfr 0:9f7ee7ed13e4 137 };
Ludwigfr 0:9f7ee7ed13e4 138
Ludwigfr 0:9f7ee7ed13e4 139
Ludwigfr 0:9f7ee7ed13e4 140 #endif
Ludwigfr 0:9f7ee7ed13e4 141