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: FastPWM HIDScope MODSERIAL QEI Matrix biquadFilter controller errorFetch mbed motorConfig refGen MatrixMath inverseKinematics
Fork of Minor_test_serial by
Revision 15:b76b8cff4d8f, committed 2017-09-21
- Comitter:
- tvlogman
- Date:
- Thu Sep 21 11:00:55 2017 +0000
- Parent:
- 14:664870b5d153
- Child:
- 16:27430afe663e
- Commit message:
- Changed control scheme to finite state machine
Changed in this revision
| FastPWM.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastPWM.lib Thu Sep 21 11:00:55 2017 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Sissors/code/FastPWM/#c0b2265cff9c
--- a/main.cpp Thu Sep 21 10:02:29 2017 +0000
+++ b/main.cpp Thu Sep 21 11:00:55 2017 +0000
@@ -2,6 +2,10 @@
#include "MODSERIAL.h"
#include "HIDScope.h"
#include "QEI.h"
+#include "FastPWM.h"
+
+enum robotStates {KILLED, ACTIVE};
+robotStates currentState = KILLED;
QEI Encoder(D12,D13,NC,64, QEI::X4_ENCODING);
MODSERIAL pc(USBTX, USBRX);
@@ -12,6 +16,11 @@
// Defining inputs
InterruptIn sw2(SW2);
+InterruptIn sw3(SW3);
+AnalogIn pot(A0);
+
+// Enabling motors
+bool motorsOn = true;
float pwmPeriod = 1.0/5000.0;
@@ -28,28 +37,43 @@
}
void killSwitch(){
- motor1_pwm.write(0.0);
+ pc.printf("Motors turned off");
+ currentState = KILLED;
}
+void turnMotorsOn(){
+ pc.printf("Motors turned on");
+ currentState = ACTIVE;
+ }
+
+
void M1switchDirection(){
motor1_direction = !motor1_direction;
}
int frequency_pwm = 10000; //10kHz PWM
-
int main()
{
motor1_direction = false;
motor1_pwm.period(pwmPeriod);//T=1/f
sw2.fall(&killSwitch);
-
+ sw3.fall(&turnMotorsOn);
pc.baud(115200);
- encoderTicker.attach(readEncoder, 1.0);
+ encoderTicker.attach(readEncoder, 1.0);
+
pc.printf("Encoder ticker attached and baudrate set");
- motor1_pwm.write(100.0/100.0);//write Duty Cycle
-
- sw2.fall(&killSwitch);
+ while(true){
+ switch(currentState){
+ case KILLED:
+ motor1_pwm.write(0.0);
+ break;
+ case ACTIVE:
+ motor1_pwm.write(pot.read()); // Motor speed proportional to pot meter
+ break;
+ }
+ }
+
}
