Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
ActiveCell.h@6:2cd6ae395c0f, 2019-04-05 (annotated)
- Committer:
- shut
- Date:
- Fri Apr 05 14:28:09 2019 +0000
- Revision:
- 6:2cd6ae395c0f
- Parent:
- 4:5a892f5ab5a8
- Child:
- 7:3a755ebe4eaf
retwerwer
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jsobiecki | 4:5a892f5ab5a8 | 1 | #ifndef UNTITLED2_ACTIVECELL_H |
| jsobiecki | 4:5a892f5ab5a8 | 2 | #define UNTITLED2_ACTIVECELL_H |
| jsobiecki | 4:5a892f5ab5a8 | 3 | #include <iostream> |
| jsobiecki | 4:5a892f5ab5a8 | 4 | #include <iomanip> |
| jsobiecki | 4:5a892f5ab5a8 | 5 | #include <math.h> |
| jsobiecki | 4:5a892f5ab5a8 | 6 | |
| jsobiecki | 4:5a892f5ab5a8 | 7 | class ActiveCell { |
| jsobiecki | 4:5a892f5ab5a8 | 8 | public: |
| jsobiecki | 4:5a892f5ab5a8 | 9 | //cell dimension = 5x5cm |
| jsobiecki | 4:5a892f5ab5a8 | 10 | int cellVal; |
| shut | 6:2cd6ae395c0f | 11 | float forceX; |
| shut | 6:2cd6ae395c0f | 12 | float forceY; |
| shut | 6:2cd6ae395c0f | 13 | float distance; |
| jsobiecki | 4:5a892f5ab5a8 | 14 | int xt, yt; |
| shut | 6:2cd6ae395c0f | 15 | static const float repulsiveForce = 20; |
| jsobiecki | 4:5a892f5ab5a8 | 16 | //robots position |
| jsobiecki | 4:5a892f5ab5a8 | 17 | int x0; |
| jsobiecki | 4:5a892f5ab5a8 | 18 | int y0; |
| jsobiecki | 4:5a892f5ab5a8 | 19 | |
| jsobiecki | 4:5a892f5ab5a8 | 20 | ActiveCell(){ |
| jsobiecki | 4:5a892f5ab5a8 | 21 | cellVal=0; |
| jsobiecki | 4:5a892f5ab5a8 | 22 | forceX=0; |
| jsobiecki | 4:5a892f5ab5a8 | 23 | forceY=0; |
| jsobiecki | 4:5a892f5ab5a8 | 24 | x0=0; |
| jsobiecki | 4:5a892f5ab5a8 | 25 | y0=0; |
| jsobiecki | 4:5a892f5ab5a8 | 26 | } |
| jsobiecki | 4:5a892f5ab5a8 | 27 | |
| jsobiecki | 4:5a892f5ab5a8 | 28 | |
| jsobiecki | 4:5a892f5ab5a8 | 29 | void calForce() { |
| jsobiecki | 4:5a892f5ab5a8 | 30 | forceX = (repulsiveForce * cellVal / pow(distance, 2)) * (xt - x0) / distance; |
| jsobiecki | 4:5a892f5ab5a8 | 31 | forceY = (repulsiveForce * cellVal / pow(distance, 2)) * (yt - y0) / distance; |
| jsobiecki | 4:5a892f5ab5a8 | 32 | } |
| shut | 6:2cd6ae395c0f | 33 | //Calculating distance from the robot |
| jsobiecki | 4:5a892f5ab5a8 | 34 | void calDist(int idX, int idY) { |
| jsobiecki | 4:5a892f5ab5a8 | 35 | if (idX < 5) { |
| jsobiecki | 4:5a892f5ab5a8 | 36 | xt = x0 - (5 - idX) * 5; |
| jsobiecki | 4:5a892f5ab5a8 | 37 | } else if (idX == 5) { |
| jsobiecki | 4:5a892f5ab5a8 | 38 | xt = x0; |
| jsobiecki | 4:5a892f5ab5a8 | 39 | } else { |
| jsobiecki | 4:5a892f5ab5a8 | 40 | xt = x0 + (idX - 5) * 5; |
| jsobiecki | 4:5a892f5ab5a8 | 41 | } |
| jsobiecki | 4:5a892f5ab5a8 | 42 | if (idY > 5) { |
| jsobiecki | 4:5a892f5ab5a8 | 43 | yt = y0 - (5 - idY) * 5; |
| jsobiecki | 4:5a892f5ab5a8 | 44 | } else if (idY == 5) { |
| jsobiecki | 4:5a892f5ab5a8 | 45 | yt = y0; |
| jsobiecki | 4:5a892f5ab5a8 | 46 | } else { |
| jsobiecki | 4:5a892f5ab5a8 | 47 | yt = y0 + (idY - 5) * 5; |
| jsobiecki | 4:5a892f5ab5a8 | 48 | } |
| shut | 6:2cd6ae395c0f | 49 | distance = sqrt(pow((float)abs(x0 - xt), 2) + pow((float)abs(y0 - yt), 2)); |
| jsobiecki | 4:5a892f5ab5a8 | 50 | } |
| jsobiecki | 4:5a892f5ab5a8 | 51 | }; |
| jsobiecki | 4:5a892f5ab5a8 | 52 | |
| jsobiecki | 4:5a892f5ab5a8 | 53 | |
| jsobiecki | 4:5a892f5ab5a8 | 54 | #endif //UNTITLED2_ACTIVECELL_H |