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.
Fork of airbrake_motor by
main.cpp
- Committer:
- zxie
- Date:
- 2019-06-08
- Revision:
- 0:9bfe3a86225a
File content as of revision 0:9bfe3a86225a:
#include "QEI.h"
Serial pc(USBTX, USBRX);
RawSerial smc(PC_6, PA_12);
//Use X2 encoding by default.
QEI wheel (PC_8, PC_5, NC, 624);
Ticker ctrl_tick;
int tgt = 5000;
void ctrl_event() {
static int rot = 0;
static int output = 0;
rot = wheel.getPulses();
pc.printf("Pulses is: %i\n\r", rot);
int err = tgt - rot;
if (err > 0) {
err = err;
output = (err * 0.1);
if (output > 127) output = 127;
smc.putc(0x8A);
smc.putc((uint8_t)output);
} else {
err = -err;
output = (err * 0.1);
if (output > 127) output = 127;
smc.putc(0x89);
smc.putc(output);
}
}
int main() {
pc.baud(115200);
smc.baud(115200);
ctrl_tick.attach(&ctrl_event, 0.1);
while(1){
wait(5);
if (tgt != 0) tgt = 0;
else tgt = 5000;
}
}
