SRM / Mbed 2 deprecated LabWork4

Dependencies:   mbed

Committer:
shut
Date:
Sun Jun 09 14:54:11 2019 +0000
Revision:
0:25f4809c2729
observer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shut 0:25f4809c2729 1 #ifndef UNTITLED2_ACTIVECELL_H
shut 0:25f4809c2729 2 #define UNTITLED2_ACTIVECELL_H
shut 0:25f4809c2729 3 #include <iostream>
shut 0:25f4809c2729 4 #include <iomanip>
shut 0:25f4809c2729 5 #include <math.h>
shut 0:25f4809c2729 6
shut 0:25f4809c2729 7 class ActiveCell {
shut 0:25f4809c2729 8 public:
shut 0:25f4809c2729 9 //cell dimension = 5x5cm
shut 0:25f4809c2729 10 float cellVal;
shut 0:25f4809c2729 11 float forceX;
shut 0:25f4809c2729 12 float forceY;
shut 0:25f4809c2729 13 float distance;
shut 0:25f4809c2729 14 short xt, yt;
shut 0:25f4809c2729 15 static const short repulsiveForce = 20;
shut 0:25f4809c2729 16 //robots position
shut 0:25f4809c2729 17 short x0;
shut 0:25f4809c2729 18 short y0;
shut 0:25f4809c2729 19 ///////////VFH//////////////
shut 0:25f4809c2729 20 static const int a=70,b=2;
shut 0:25f4809c2729 21 float angle;
shut 0:25f4809c2729 22 float amplitude;
shut 0:25f4809c2729 23 short sectorK;
shut 0:25f4809c2729 24 //resolution - if changing change also secVal in main & calcSectors
shut 0:25f4809c2729 25 static const short res=10;
shut 0:25f4809c2729 26
shut 0:25f4809c2729 27 ActiveCell(){
shut 0:25f4809c2729 28 angle=0;
shut 0:25f4809c2729 29 amplitude=0;
shut 0:25f4809c2729 30 sectorK=0;
shut 0:25f4809c2729 31 cellVal=0;
shut 0:25f4809c2729 32 forceX=0;
shut 0:25f4809c2729 33 forceY=0;
shut 0:25f4809c2729 34 x0=0;
shut 0:25f4809c2729 35 y0=0;
shut 0:25f4809c2729 36 }
shut 0:25f4809c2729 37
shut 0:25f4809c2729 38
shut 0:25f4809c2729 39 void calForce() {
shut 0:25f4809c2729 40 forceX = (repulsiveForce * cellVal / pow(distance, 2)) * (xt - x0) / distance;
shut 0:25f4809c2729 41 forceY = (repulsiveForce * cellVal / pow(distance, 2)) * (yt - y0) / distance;
shut 0:25f4809c2729 42 amplitude = cellVal*cellVal*(a-b*distance);
shut 0:25f4809c2729 43 }
shut 0:25f4809c2729 44 //Calculating distance from the robot
shut 0:25f4809c2729 45 void calDist(int idX, int idY) {
shut 0:25f4809c2729 46 if (idX < 5) {
shut 0:25f4809c2729 47 xt = x0 - (5 - idX) * 5;
shut 0:25f4809c2729 48 } else if (idX == 5) {
shut 0:25f4809c2729 49 xt = x0;
shut 0:25f4809c2729 50 } else {
shut 0:25f4809c2729 51 xt = x0 + (idX - 5) * 5;
shut 0:25f4809c2729 52 }
shut 0:25f4809c2729 53 if (idY > 5) {
shut 0:25f4809c2729 54 yt = y0 - (5 - idY) * 5;
shut 0:25f4809c2729 55 } else if (idY == 5) {
shut 0:25f4809c2729 56 yt = y0;
shut 0:25f4809c2729 57 } else {
shut 0:25f4809c2729 58 yt = y0 + (idY - 5) * 5;
shut 0:25f4809c2729 59 }
shut 0:25f4809c2729 60 distance = sqrt(pow((float)abs(x0 - xt), 2) + pow((float)abs(y0 - yt), 2));
shut 0:25f4809c2729 61
shut 0:25f4809c2729 62 //////angle/////////////
shut 0:25f4809c2729 63 angle = atan2((float)yt-y0,(float)xt-x0)*180/3.14159265358979323846f;
shut 0:25f4809c2729 64 sectorK=angle/res;
shut 0:25f4809c2729 65 if(sectorK<0)
shut 0:25f4809c2729 66 sectorK=36+sectorK;
shut 0:25f4809c2729 67 }
shut 0:25f4809c2729 68 };
shut 0:25f4809c2729 69
shut 0:25f4809c2729 70
shut 0:25f4809c2729 71 #endif //UNTITLED2_ACTIVECELL_H