MX-12W Servo Library

Dependents:   DISCO_L475VG_IOT01-Sensors-BSP

Committer:
tsoul
Date:
Fri Dec 11 11:05:33 2020 +0000
Revision:
3:513956de75d7
Parent:
2:b4d4c281f174
Child:
4:9ffc4009a463
Add GetPosition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsoul 0:5e5d94ac9c80 1 #ifndef MBED_MX12_H
tsoul 0:5e5d94ac9c80 2 #define MBED_MX12_H
tsoul 0:5e5d94ac9c80 3
tsoul 0:5e5d94ac9c80 4 #include "mbed.h"
tsoul 0:5e5d94ac9c80 5
tsoul 1:d0c3878f77ee 6 #define MX12_ANSWER_MAX_SIZE 32
tsoul 1:d0c3878f77ee 7
tsoul 0:5e5d94ac9c80 8 class MX12 {
tsoul 0:5e5d94ac9c80 9 public:
tsoul 2:b4d4c281f174 10 enum Status {
tsoul 2:b4d4c281f174 11 InstructionError,
tsoul 2:b4d4c281f174 12 OverloadError,
tsoul 2:b4d4c281f174 13 ChecksumError,
tsoul 2:b4d4c281f174 14 RangeError,
tsoul 2:b4d4c281f174 15 OverheatingError,
tsoul 2:b4d4c281f174 16 AngleLimitError,
tsoul 2:b4d4c281f174 17 InputVoltageError,
tsoul 2:b4d4c281f174 18 Unknown,
tsoul 2:b4d4c281f174 19 Ok
tsoul 2:b4d4c281f174 20 };
tsoul 2:b4d4c281f174 21
tsoul 0:5e5d94ac9c80 22 MX12(PinName tx, PinName rx, int baud=115200);
tsoul 0:5e5d94ac9c80 23
tsoul 0:5e5d94ac9c80 24 void SetSpeed(unsigned char mot_id, float speed);
tsoul 2:b4d4c281f174 25 MX12::Status GetStatus();
tsoul 3:513956de75d7 26 float ReadPosition(unsigned char mot_id);
tsoul 1:d0c3878f77ee 27 void PrintAnswer();
tsoul 0:5e5d94ac9c80 28
tsoul 1:d0c3878f77ee 29 void rw(unsigned char mot_id, char adress, char len, char *data);
tsoul 1:d0c3878f77ee 30
tsoul 1:d0c3878f77ee 31 void _ReadCallback();
tsoul 0:5e5d94ac9c80 32
tsoul 0:5e5d94ac9c80 33 private:
tsoul 0:5e5d94ac9c80 34 UnbufferedSerial _mx12;
tsoul 2:b4d4c281f174 35 MX12::Status _status;
tsoul 1:d0c3878f77ee 36
tsoul 1:d0c3878f77ee 37 char _res[MX12_ANSWER_MAX_SIZE];
tsoul 1:d0c3878f77ee 38 char _res_count;
tsoul 0:5e5d94ac9c80 39 int _baud;
tsoul 0:5e5d94ac9c80 40 };
tsoul 0:5e5d94ac9c80 41
tsoul 0:5e5d94ac9c80 42 #endif /* MBED_MX12_H */