Matlab connection via the serial port, to control the robot from there (interactively)
Diff: MatlabComm.h
- Revision:
- 0:08d5f31c6ddc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MatlabComm.h Tue Nov 01 02:31:36 2016 +0000 @@ -0,0 +1,28 @@ +#include "QEI.h" +#include "MODSERIAL.h" +#include "stdio.h" //sscanf +#include "mbed.h" +#include "math.h" // abs + +// Serial communications with Matlab, to control the robot and make a design. +// Communications sent: +// %i; Pulses sent, followed by a \r\n; +// This will be sent on every call of MatlabComm. +// In case of data, MatlabComm will read the Serial input buffer until it is empty, or until it has read a number + +class MatlabComm { + public: + MatlabComm(PinName MotorDirectionPin, PinName MotorSpeedPin, PinName EncoderChannelA, PinName EncoderChannelB); + void Step(); + private: + PwmOut M_SpeedPin; + DigitalOut M_DirectionPin; + QEI M_Encoder; + MODSERIAL pc; + void read(); + void write(); + void flush_buffer(); + static const int buffer_max_index=29; + char char_buffer[30]; + int buffer_index; + }; \ No newline at end of file