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 QEI HIDScope biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 3:4f281c336a8b
- Parent:
- 2:75b2f713161c
- Child:
- 4:fb67a4284aaa
- Child:
- 5:2ae500da8fe1
--- a/main.cpp Mon Oct 07 12:25:49 2019 +0000
+++ b/main.cpp Mon Oct 07 13:02:09 2019 +0000
@@ -5,11 +5,14 @@
DigitalIn button1(D12);
AnalogIn pot2(A0);
Ticker john;
-DigitalOut motor1Direction(D6);
-FastPWM motor1Velocity(D7);
+DigitalOut motor1Direction(D7);
+FastPWM motor1Velocity(D6);
Serial pc(USBTX, USBRX);
volatile double frequency = 17000.0;
volatile double period_signal = 1.0/frequency;
+float vel = 0.0f;
+float referencevelocity;
+float motorvalue2;
//get the measured velocity
double getmeasuredvelocity()
@@ -22,52 +25,19 @@
//get the reference of the velocity: positive or negative
double getreferencevelocity()
{
- //const float maxvelocity = 8.4;
- /*volatile float referencevelocity;
- if (button1.read() == 0)
- {
- referencevelocity = pot2.read()*maxvelocity;
- }
- else
- {
- referencevelocity = -1*pot2.read()*maxvelocity;
- }*/
- float referencevelocity = -1.0 + 2.0*pot2.read();
- //pc.printf("The reference velocity is %f\r\n", referencevelocity);
+ referencevelocity = -1.0 + 2.0*pot2.read();
return referencevelocity;
}
-float vel = 0.0f;
//send value to motor
void sendtomotor(float motorvalue)
{
- /*
- pc.printf("The motor value is %f\r\n", motorvalue);
- if (motorvalue >= 0)
- {
- motor1Direction = 1;
- pc.printf("hello");
- }
- else
- {
- motor1Direction = 0;
- pc.printf("wow");
- }
- if (fabs(motorvalue)>1)
- {
- motor1Velocity = 1;
- }
- else
- {
- motor1Velocity = fabs(motorvalue);
- }*/
+ motorvalue2 = motorvalue;
vel = fabs(motorvalue);
- vel = vel > 1.0f ? 1.0f : vel;
+ vel = vel > 1.0f ? 1.0f : vel;
motor1Velocity = vel;
motor1Direction = (motorvalue > 0.0f);
- //pc.printf("The motor value is %f\r\n", motorvalue);
- //pc.printf("The motor direction is %s\r\n", motor1Direction ? "links" : "rechts");
}
// function to call reference velocity, measured velocity and controls motor with feedback
@@ -75,7 +45,6 @@
{
float referencevelocity = getreferencevelocity();
float measuredvelocity = getmeasuredvelocity();
-// float motorvalue = feedbackcontrol(referencevelocity - measuredvelocity);
sendtomotor(referencevelocity);
}
int main()
@@ -87,6 +56,8 @@
while(true)
{
wait(0.5);
- pc.printf("%f\r\n", vel);
+ pc.printf("velocity = %f\r\n", vel);
+ pc.printf("motor1Direction = %i\r\n", (int)motor1Direction);
+ pc.printf("motorvalue2 = %f\r\n", motorvalue2);
}
}
\ No newline at end of file