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 16:27430afe663e, committed 2017-09-21
- Comitter:
- tvlogman
- Date:
- Thu Sep 21 11:20:03 2017 +0000
- Parent:
- 15:b76b8cff4d8f
- Child:
- 17:616ce7bc1f96
- Commit message:
- Added a reverse-direction button on button1 of the Biorobotics shield
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Sep 21 11:00:55 2017 +0000
+++ b/main.cpp Thu Sep 21 11:20:03 2017 +0000
@@ -9,6 +9,7 @@
QEI Encoder(D12,D13,NC,64, QEI::X4_ENCODING);
MODSERIAL pc(USBTX, USBRX);
+HIDScope scope(2);
// Defining outputs
DigitalOut motor1_direction(D4);
@@ -17,23 +18,37 @@
// Defining inputs
InterruptIn sw2(SW2);
InterruptIn sw3(SW3);
+InterruptIn button1(D2);
AnalogIn pot(A0);
-// Enabling motors
-bool motorsOn = true;
+// PWM settings
+float pwmPeriod = 1.0/5000.0;
+int frequency_pwm = 10000; //10kHz PWM
+volatile float x;
+volatile float x_prev =0;
+volatile float y; // filtered 'output' of ReadAnalogInAndFilter
+volatile float ledBrightness = 0.00;
-float pwmPeriod = 1.0/5000.0;
Ticker encoderTicker;
volatile int counts = 0;
volatile float revs = 0.00;
+
+
void readEncoder(){
counts = Encoder.getPulses();
revs = counts/64.0f;
- pc.printf("%i pulses \r\n", counts);
- pc.printf("%f revolutions \r\n", revs);
+
+ // Displaying revs in HIDscope
+ x = revs; // Capture data
+ scope.set(0, x); // store data in first element of scope memory
+ y = (x_prev + x)/2.0; // averaging filter
+ scope.set(1, y); // store data in second element of scope memory
+ x_prev = x; // Prepare for next round
+
+ scope.send(); // send what's in scope memory to PC
}
void killSwitch(){
@@ -51,16 +66,15 @@
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);
+ button1.rise(&M1switchDirection);
pc.baud(115200);
- encoderTicker.attach(readEncoder, 1.0);
+ encoderTicker.attach(readEncoder, 0.1);
pc.printf("Encoder ticker attached and baudrate set");
