MX-12W Servo Library

Dependents:   DISCO_L475VG_IOT01-Sensors-BSP

Committer:
tsoul
Date:
Fri Jan 15 09:15:47 2021 +0000
Revision:
4:9ffc4009a463
Parent:
3:513956de75d7
Child:
5:4bdd101ce4ec
Add callback function

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 4:9ffc4009a463 7 #define MX12_MOTOR_COUNT 16
tsoul 1:d0c3878f77ee 8
tsoul 0:5e5d94ac9c80 9 class MX12 {
tsoul 0:5e5d94ac9c80 10 public:
tsoul 2:b4d4c281f174 11 enum Status {
tsoul 2:b4d4c281f174 12 InstructionError,
tsoul 2:b4d4c281f174 13 OverloadError,
tsoul 2:b4d4c281f174 14 ChecksumError,
tsoul 2:b4d4c281f174 15 RangeError,
tsoul 2:b4d4c281f174 16 OverheatingError,
tsoul 2:b4d4c281f174 17 AngleLimitError,
tsoul 2:b4d4c281f174 18 InputVoltageError,
tsoul 2:b4d4c281f174 19 Unknown,
tsoul 2:b4d4c281f174 20 Ok
tsoul 2:b4d4c281f174 21 };
tsoul 4:9ffc4009a463 22
tsoul 4:9ffc4009a463 23 enum State {
tsoul 4:9ffc4009a463 24 ReadingPosition,
tsoul 4:9ffc4009a463 25 Writing,
tsoul 4:9ffc4009a463 26 Available,
tsoul 4:9ffc4009a463 27 };
tsoul 2:b4d4c281f174 28
tsoul 0:5e5d94ac9c80 29 MX12(PinName tx, PinName rx, int baud=115200);
tsoul 0:5e5d94ac9c80 30
tsoul 0:5e5d94ac9c80 31 void SetSpeed(unsigned char mot_id, float speed);
tsoul 4:9ffc4009a463 32 char IsAvailable(void);
tsoul 4:9ffc4009a463 33 MX12::Status GetStatus(void);
tsoul 4:9ffc4009a463 34 void ReadPosition(unsigned char mot_id);
tsoul 4:9ffc4009a463 35 float GetPosition(unsigned char mot_id);
tsoul 1:d0c3878f77ee 36 void PrintAnswer();
tsoul 0:5e5d94ac9c80 37
tsoul 1:d0c3878f77ee 38 void rw(unsigned char mot_id, char adress, char len, char *data);
tsoul 1:d0c3878f77ee 39
tsoul 1:d0c3878f77ee 40 void _ReadCallback();
tsoul 4:9ffc4009a463 41
tsoul 4:9ffc4009a463 42 char _chksm;
tsoul 0:5e5d94ac9c80 43
tsoul 0:5e5d94ac9c80 44 private:
tsoul 0:5e5d94ac9c80 45 UnbufferedSerial _mx12;
tsoul 2:b4d4c281f174 46 MX12::Status _status;
tsoul 1:d0c3878f77ee 47
tsoul 1:d0c3878f77ee 48 char _res[MX12_ANSWER_MAX_SIZE];
tsoul 1:d0c3878f77ee 49 char _res_count;
tsoul 4:9ffc4009a463 50 char _len;
tsoul 4:9ffc4009a463 51
tsoul 4:9ffc4009a463 52 MX12::State _state;
tsoul 4:9ffc4009a463 53 float _angle[MX12_MOTOR_COUNT];
tsoul 0:5e5d94ac9c80 54 int _baud;
tsoul 0:5e5d94ac9c80 55 };
tsoul 0:5e5d94ac9c80 56
tsoul 0:5e5d94ac9c80 57 #endif /* MBED_MX12_H */