with class
Dependencies: ISR_Mini-explorer mbed
Fork of VirtualForces by
MiniExplorerCoimbra.hpp@34:c208497dd079, 2017-06-09 (annotated)
- Committer:
- Ludwigfr
- Date:
- Fri Jun 09 14:30:21 2017 +0000
- Revision:
- 34:c208497dd079
- Parent:
- 33:814bcd7d3cfe
- Child:
- 35:68f9edbb3cff
okay it compiles
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ludwigfr | 33:814bcd7d3cfe | 1 | #ifndef MINIEXPLORERCOIMBRA_HPP |
Ludwigfr | 33:814bcd7d3cfe | 2 | #define MINIEXPLORERCOIMBRA_HPP |
Ludwigfr | 33:814bcd7d3cfe | 3 | |
Ludwigfr | 33:814bcd7d3cfe | 4 | #include "Map.hpp" |
Ludwigfr | 33:814bcd7d3cfe | 5 | #include "Sonar.hpp" |
Ludwigfr | 34:c208497dd079 | 6 | #include<math.h> |
Ludwigfr | 34:c208497dd079 | 7 | |
Ludwigfr | 33:814bcd7d3cfe | 8 | |
Ludwigfr | 33:814bcd7d3cfe | 9 | /* |
Ludwigfr | 33:814bcd7d3cfe | 10 | Robot coordinate system: World coordinate system: |
Ludwigfr | 33:814bcd7d3cfe | 11 | ^ ^ |
Ludwigfr | 33:814bcd7d3cfe | 12 | |x |y |
Ludwigfr | 33:814bcd7d3cfe | 13 | <--R O--> |
Ludwigfr | 33:814bcd7d3cfe | 14 | y x |
Ludwigfr | 33:814bcd7d3cfe | 15 | */ |
Ludwigfr | 33:814bcd7d3cfe | 16 | |
Ludwigfr | 33:814bcd7d3cfe | 17 | class MiniExplorerCoimbra { |
Ludwigfr | 34:c208497dd079 | 18 | |
Ludwigfr | 33:814bcd7d3cfe | 19 | public: |
Ludwigfr | 34:c208497dd079 | 20 | |
Ludwigfr | 33:814bcd7d3cfe | 21 | Map map; |
Ludwigfr | 33:814bcd7d3cfe | 22 | Sonar sonarLeft; |
Ludwigfr | 33:814bcd7d3cfe | 23 | Sonar sonarFront; |
Ludwigfr | 33:814bcd7d3cfe | 24 | Sonar sonarRight; |
Ludwigfr | 33:814bcd7d3cfe | 25 | float speed; |
Ludwigfr | 33:814bcd7d3cfe | 26 | float radiusWheels; |
Ludwigfr | 33:814bcd7d3cfe | 27 | float distanceWheels; |
Ludwigfr | 33:814bcd7d3cfe | 28 | float khro; |
Ludwigfr | 33:814bcd7d3cfe | 29 | float ka; |
Ludwigfr | 33:814bcd7d3cfe | 30 | float kb; |
Ludwigfr | 33:814bcd7d3cfe | 31 | float kv; |
Ludwigfr | 33:814bcd7d3cfe | 32 | float kh; |
Ludwigfr | 33:814bcd7d3cfe | 33 | |
Ludwigfr | 33:814bcd7d3cfe | 34 | float rangeForce; |
Ludwigfr | 33:814bcd7d3cfe | 35 | float attractionConstantForce; |
Ludwigfr | 33:814bcd7d3cfe | 36 | float repulsionConstantForce; |
Ludwigfr | 33:814bcd7d3cfe | 37 | |
Ludwigfr | 33:814bcd7d3cfe | 38 | MiniExplorerCoimbra(float defaultX, float defaultY, float defaultTheta); |
Ludwigfr | 33:814bcd7d3cfe | 39 | |
Ludwigfr | 33:814bcd7d3cfe | 40 | void setXYTheta(float x, float y, float theta); |
Ludwigfr | 33:814bcd7d3cfe | 41 | |
Ludwigfr | 33:814bcd7d3cfe | 42 | //generate a position randomly and makes the robot go there while updating the map |
Ludwigfr | 33:814bcd7d3cfe | 43 | void randomize_and_map(); |
Ludwigfr | 33:814bcd7d3cfe | 44 | |
Ludwigfr | 33:814bcd7d3cfe | 45 | //go the the given position while updating the map |
Ludwigfr | 33:814bcd7d3cfe | 46 | void go_to_point_with_angle(float targetX, float targetY, float targetAngle); |
Ludwigfr | 33:814bcd7d3cfe | 47 | |
Ludwigfr | 33:814bcd7d3cfe | 48 | void update_sonar_values(float leftMm,float frontMm,float rightMm); |
Ludwigfr | 33:814bcd7d3cfe | 49 | |
Ludwigfr | 33:814bcd7d3cfe | 50 | float get_converted_robot_X_into_world(); |
Ludwigfr | 33:814bcd7d3cfe | 51 | |
Ludwigfr | 33:814bcd7d3cfe | 52 | float get_converted_robot_Y_into_world(); |
Ludwigfr | 33:814bcd7d3cfe | 53 | |
Ludwigfr | 33:814bcd7d3cfe | 54 | void do_half_flip(); |
Ludwigfr | 33:814bcd7d3cfe | 55 | |
Ludwigfr | 33:814bcd7d3cfe | 56 | //Distance computation function |
Ludwigfr | 33:814bcd7d3cfe | 57 | float dist(float robotX, float robotY, float targetX, float targetY); |
Ludwigfr | 33:814bcd7d3cfe | 58 | |
Ludwigfr | 33:814bcd7d3cfe | 59 | float update_angular_speed_wheels_go_to_point_with_angle(float targetX, float targetY, float targetAngle, float dt); |
Ludwigfr | 33:814bcd7d3cfe | 60 | |
Ludwigfr | 33:814bcd7d3cfe | 61 | void try_to_reach_target(float targetXWorld,float targetYWorld); |
Ludwigfr | 33:814bcd7d3cfe | 62 | |
Ludwigfr | 33:814bcd7d3cfe | 63 | void vff(bool* reached, float targetXWorld, float targetYWorld); |
Ludwigfr | 33:814bcd7d3cfe | 64 | |
Ludwigfr | 33:814bcd7d3cfe | 65 | //compute the force on X and Y |
Ludwigfr | 33:814bcd7d3cfe | 66 | void compute_forceX_and_forceY(float* forceX, float* forceY, float targetXWorld, float targetYWorld); |
Ludwigfr | 33:814bcd7d3cfe | 67 | |
Ludwigfr | 33:814bcd7d3cfe | 68 | void update_force(int widthIndice, int heightIndice, float* forceX, float* forceY, float xRobotWorld, float yRobotWorld ); |
Ludwigfr | 33:814bcd7d3cfe | 69 | |
Ludwigfr | 33:814bcd7d3cfe | 70 | //robotX and robotY are from Odometria, calculate line_a, line_b and line_c |
Ludwigfr | 33:814bcd7d3cfe | 71 | void calculate_line(float forceX, float forceY, float *line_a, float *line_b, float *line_c); |
Ludwigfr | 33:814bcd7d3cfe | 72 | |
Ludwigfr | 33:814bcd7d3cfe | 73 | //currently line_c is not used |
Ludwigfr | 33:814bcd7d3cfe | 74 | void go_to_line(float line_a, float line_b, float line_c,float targetXWorld, float targetYWorld); |
Ludwigfr | 33:814bcd7d3cfe | 75 | |
Ludwigfr | 33:814bcd7d3cfe | 76 | //return 1 if positiv, -1 if negativ |
Ludwigfr | 33:814bcd7d3cfe | 77 | float sign1(float value); |
Ludwigfr | 33:814bcd7d3cfe | 78 | |
Ludwigfr | 33:814bcd7d3cfe | 79 | //return 1 if positiv, 0 if negativ |
Ludwigfr | 33:814bcd7d3cfe | 80 | int sign2(float value); |
Ludwigfr | 33:814bcd7d3cfe | 81 | |
Ludwigfr | 33:814bcd7d3cfe | 82 | /*angleToTarget is obtained through atan2 so it s: |
Ludwigfr | 33:814bcd7d3cfe | 83 | < 0 if the angle is bettween PI and 2pi on a trigo circle |
Ludwigfr | 33:814bcd7d3cfe | 84 | > 0 if it is between 0 and PI |
Ludwigfr | 33:814bcd7d3cfe | 85 | */ |
Ludwigfr | 33:814bcd7d3cfe | 86 | void turn_to_target(float angleToTarget); |
Ludwigfr | 34:c208497dd079 | 87 | |
Ludwigfr | 34:c208497dd079 | 88 | void print_final_map(); |
Ludwigfr | 34:c208497dd079 | 89 | |
Ludwigfr | 34:c208497dd079 | 90 | void print_final_map_with_robot_position(float robot_x,float robot_y); |
Ludwigfr | 34:c208497dd079 | 91 | |
Ludwigfr | 34:c208497dd079 | 92 | void print_final_map_with_robot_position_and_target(float robot_x,float robot_y,float targetXWorld, float targetYWorld); |
Ludwigfr | 33:814bcd7d3cfe | 93 | }; |
Ludwigfr | 33:814bcd7d3cfe | 94 | |
Ludwigfr | 34:c208497dd079 | 95 | |
Ludwigfr | 33:814bcd7d3cfe | 96 | #endif |
Ludwigfr | 33:814bcd7d3cfe | 97 |