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
Diff: WheelControl/Wheel.h
- Revision:
- 10:acf5cb8d58d5
- Parent:
- 9:cefa177c1353
- Child:
- 11:78c645fb76cd
--- a/WheelControl/Wheel.h Fri Apr 05 16:11:28 2019 +0000
+++ b/WheelControl/Wheel.h Sun Apr 28 18:27:46 2019 +0000
@@ -4,8 +4,9 @@
float distance; //distance traversed by wheel
float angularVelocity;
+ int br;
- float const static gain = 0.9f; //closed loop gain, (amount to amplify the difference) you have to tune this value
+ float const static gain = 1.1f; //closed loop gain, (amount to amplify the difference) you have to tune this value
//but make sure its less than 1.5 otherwise you'll have a really sensitive motor
PwmOut Mtr; //connect this pin to the motor driveboard pwm
@@ -25,7 +26,7 @@
float static const wheelDiameter = 0.18; //used in calculation of Linear velocity i.e never
- Wheel (Encoder* E, PinName M, PinName D, PinName Mode) : Mtr(M), direction(D), polarity(Mode), controller(gain,6.0f,0.00005f,0.0005f)
+ Wheel (Encoder* E, PinName M, PinName D, PinName Mode) : Mtr(M), direction(D), polarity(Mode), controller(gain,4.0f,0.00002f,0.0003f)
{
maxAngularVel = 0.0f;
enc = E;
@@ -67,7 +68,7 @@
Mtr.write(0); //max speed
angularVelocity = 10.0f;
if (dir == 0) {direction = 0;} else {direction = 1;}
- updater.attach(callback(this, &Wheel::init2),0.6f); //used as a wait preferably put this wait just long enough that the buggy will do a full 360 degree turn so that it hasn't moved
+ updater.attach(callback(this, &Wheel::init2),0.6f);
}
void init2(void) //used as a temporarily wait command for the wheel to spin to max
@@ -92,12 +93,17 @@
void wheelUpdates(void) //sampling rate the ticker is attached I.E the wheel speed is updated everytime this function is called
{
+ if (br == 0) {
calculateAngularVelocity();
//distance += angularVelocity*(wheelDiameter/2)*0.0005f;
float temp2 = controller.compute(angularVelocity); //another temporary value to store the computed angular velocity
if (temp2 < 0) {direction = 0;} else {direction = 1;} //change direction according to the computed value
Mtr.write((1.0f - abs(temp2))); //write the value as a pwm
-
+ }
+ else
+ {
+ return;
+ }
}
void adjustAngularVelocity(float W) // W = angular velocity you want, obviously putting a |w| value that is > max angular velocity will set dutcy cycle to max
@@ -132,4 +138,15 @@
return tempPTR;
}
+ void setBR (int p)
+ {
+ br = p;
+ }
+
+ void brake()
+ {
+ direction = 0;
+ Mtr.write(0);
+ }
+
};
\ No newline at end of file