test morning

Dependencies:   ISR_Mini-explorer mbed

Fork of roboticLab_withclass_3_July by Georgios Tsamis

Committer:
Ludwigfr
Date:
Mon Jul 10 18:03:19 2017 +0000
Revision:
10:d0109d7cbe7c
Parent:
9:1cc27f33d3e1
Child:
14:696187e74411
lab 4 not working but it s compiling

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