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: MODSERIAL QEI mbed HIDScope
Fork of prog_pract3 by
Diff: main.cpp
- Revision:
- 2:ee821b9bf42b
- Parent:
- 1:6be8bcde9f05
- Child:
- 3:c1ef4d7490c1
diff -r 6be8bcde9f05 -r ee821b9bf42b main.cpp --- a/main.cpp Mon Oct 10 12:07:25 2016 +0000 +++ b/main.cpp Mon Oct 10 13:11:05 2016 +0000 @@ -2,6 +2,8 @@ #include <math.h> #include "MODSERIAL.h" +DigitalOut led1 (D12); +DigitalOut led2 (D10); AnalogIn potMeterIn(PTB2); DigitalIn button1(D7); DigitalOut motor1DirectionPin(D4); @@ -22,14 +24,17 @@ // Returns reference velocity in rad/s. // Positive value means clockwise rotation. const float maxVelocity = 8.4; // in rad/s of course! - if (button1) - { + if (button1 == 0){ + led1=1; + led2=0; // Clockwise rotation - referenceVelocity = potMeterIn.read() * maxVelocity; - } else - { + referenceVelocity = potMeterIn * maxVelocity; + } + else { + led1=0; + led2=1; // Counterclockwise rotation - referenceVelocity = -1*potMeterIn.read() * maxVelocity; + referenceVelocity = -1*potMeterIn * maxVelocity; } return referenceVelocity; } @@ -38,7 +43,7 @@ { // very simple linear feed-forward control const float MotorGain=8.4; // unit: (rad/s) / PWM - volatile float motorValue = referenceVelocity / MotorGain; + float motorValue = referenceVelocity / MotorGain; return motorValue; } @@ -66,16 +71,27 @@ void TimeTrackerF(){ wait(1); + float Potmeter = potMeterIn.read(); + float motorValue; pc.printf("Reference velocity: %f rad/s \r\n", referenceVelocity); + pc.printf("MotorValue: %f rad/s \r\n", motorValue); + pc.printf("Potmeter: %f rad/s \r\n", Potmeter); } int main() { //Initialize - MeasureTicker.attach(&MeasureTicker_act, 0.1f); - TimeTracker.attach(&TimeTracker_act, 1.0f); + led1=0; + led2=0; + float Potmeter = potMeterIn.read(); + float motorValue; + MeasureTicker.attach(&MeasureTicker_act, 0.01f); + TimeTracker.attach(&TimeTracker_act, 0.1f); pc.baud(115200); - pc.printf("Reference velocity: %f rad/s \r\n", referenceVelocity); + pc.printf("Reference velocity: %f rad/s \r\n", referenceVelocity); + pc.printf("MotorValue: %f rad/s \r\n", motorValue); + pc.printf("Potmeter: %f rad/s \r\n", Potmeter); + while(1) { if (MeasureTicker_go){