Dependencies:   mbed

Revision:
4:5a892f5ab5a8
Child:
6:2cd6ae395c0f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ActiveCell.h	Sun Mar 24 01:11:20 2019 +0000
@@ -0,0 +1,54 @@
+#ifndef UNTITLED2_ACTIVECELL_H
+#define UNTITLED2_ACTIVECELL_H
+#include <iostream>
+#include <iomanip>
+#include <math.h>
+
+class ActiveCell {
+public:
+    //cell dimension = 5x5cm
+    int cellVal;
+    double forceX;
+    double forceY;
+    double distance;
+    int xt, yt;
+    static const double repulsiveForce = 1000;
+    //robots position
+    int x0;
+    int y0;
+
+    ActiveCell(){
+        cellVal=0;
+        forceX=0;
+        forceY=0;
+        x0=0;
+        y0=0;
+    }
+
+
+    void calForce() {
+        forceX = (repulsiveForce * cellVal / pow(distance, 2)) * (xt - x0) / distance;
+        forceY = (repulsiveForce * cellVal / pow(distance, 2)) * (yt - y0) / distance;
+    }
+
+    void calDist(int idX, int idY) {
+        if (idX < 5) {
+            xt = x0 - (5 - idX) * 5;
+        } else if (idX == 5) {
+            xt = x0;
+        } else {
+            xt = x0 + (idX - 5) * 5;
+        }
+        if (idY > 5) {
+            yt = y0 - (5 - idY) * 5;
+        } else if (idY == 5) {
+            yt = y0;
+        } else {
+            yt = y0 + (idY - 5) * 5;
+        }
+        distance = sqrt(pow((double)abs(x0 - xt), 2) + pow((double)abs(y0 - yt), 2));
+    }
+};
+
+
+#endif //UNTITLED2_ACTIVECELL_H