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.
Revision 1:2c9a92a538e4, committed 2021-11-24
- Comitter:
- ea78anana
- Date:
- Wed Nov 24 10:28:01 2021 +0000
- Parent:
- 0:59348dbbd541
- Commit message:
- encoder
Changed in this revision
| Encoder.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Encoder.cpp Sat Nov 20 15:12:50 2021 +0000
+++ b/Encoder.cpp Wed Nov 24 10:28:01 2021 +0000
@@ -9,11 +9,7 @@
#define LOW 0
//Initialize Variable
-unsigned long time1 = 0; // Time
-float time_cw;
-float time_ccw;
int counter_cw = 0;
-int counter_ccw = 0;
const float d = 0.058; //Diameter of the wheel
const float pi = 3.141592654;//PI
int num = 0;//number of turns
@@ -43,7 +39,7 @@
else
- { counter_ccw++;
+ { counter_cw--;
@@ -57,9 +53,8 @@
a11.rise(&Encode0);
}
-void Set_state(int a, int b){
+void Set_state(int a){
counter_cw = a;
- counter_ccw = b;
n = 0;
}
@@ -71,32 +66,22 @@
n = n + 2;
if (counter_cw >= 2500)
{
-// Printf("ok");//Testing
temp = counter_cw / 2500;
- num = num + temp;
current = counter_cw - 2500 * temp;
t = n;
- Set_state(current, counter_ccw);
- distance = num * d * pi;
+ Set_state(current);
velocity = (temp * d * pi) / t;
- current = 0;
- pc.printf("turns: %d \r\n", num);
pc.printf("The wheel has run ");pc.printf("%f", distance); pc.printf("m.");
pc.printf("The cw_speed is ");pc.printf("%f", velocity); pc.printf("m/s.");
}
//anti-clockwise turning
- else if (counter_ccw >= 2500)
+ else if (counter_cw >= -2500)
{
-// Printf("ok");//Testing
- temp = counter_ccw / 2500;
- num = num + temp;
- current = counter_ccw - 2500 * temp;
+ temp = counter_cw / 2500;
+ current = counter_cw + 2500 * temp;
t = n;
- Set_state(counter_cw,current);
- distance = num * d * pi;
+ Set_state(current);
velocity = d * pi / t;
- current = 0;
- pc.printf("turns: %d \r\n", num);
pc.printf("The wheel has run ");pc.printf("%f", distance); pc.printf("m.");
pc.printf("The cw_speed is ");pc.printf("%f", velocity); pc.printf("m/s.");
}