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:
- 8:5ed6685f6edd
- Parent:
- 6:477382219bcf
- Child:
- 9:cefa177c1353
--- a/WheelControl/Wheel.h Thu Mar 28 01:07:54 2019 +0000
+++ b/WheelControl/Wheel.h Sun Mar 31 20:31:30 2019 +0000
@@ -2,8 +2,6 @@
{
private:
-
-
float distance; //distance traversed by wheel
float angularVelocity;
@@ -22,12 +20,12 @@
public:
- float maxAngularVel;
- float minAngularVel;
+ float maxAngularVel;
+ float minAngularVel;
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,2.0f,0.0f,0.0005f)
+ Wheel (Encoder* E, PinName M, PinName D, PinName Mode) : Mtr(M), direction(D), polarity(Mode), controller(gain,3.0f,0.00005f,0.0005f)
{
maxAngularVel = 0.0f;
enc = E;
@@ -75,7 +73,6 @@
void init2(void) //used as a temporarily wait command for the wheel to spin to max
{
enc->startTimer();
- updater.detach();
calculateAngularVelocity();
maxAngularVel = 60.0f;
minAngularVel = -1.0f*maxAngularVel;
@@ -96,15 +93,16 @@
void wheelUpdates(void) //sampling rate the ticker is attached I.E the wheel speed is updated everytime this function is called
{
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
+
}
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
{
controller.setSetPoint(W);
- if (W < 0.0f) {direction = 0;} else {direction = 1;} //obvs if you put a negative value -> will get a negative direction i.e 0;
};
float getDistance(void)
@@ -112,6 +110,11 @@
return distance; //distance traversed by wheel
}
+ void stop()
+ {
+ controller.setSetPoint(0);
+ }
+
float returnMaxAngularVel(void)
{
return maxAngularVel;