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.
Diff: MX12.h
- Revision:
- 0:7556356a8bcd
- Child:
- 1:a9ba9cf928fe
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MX12.h Wed Nov 03 11:17:12 2021 +0000
@@ -0,0 +1,84 @@
+#ifndef MBED_MX12_H
+#define MBED_MX12_H
+
+/** Class to communicate with Dynamixel MX12 servomotors.
+ *
+ *
+ */
+
+#include "mbed.h"
+
+#define MX12_ANSWER_MAX_SIZE 32
+#define MX12_MOTOR_COUNT 16
+
+class MX12
+{
+ public:
+
+ enum Status {
+ InstructionError,
+ OverloadError,
+ ChecksumError,
+ RangeError,
+ OverheatingError,
+ AngleLimitError,
+ InputVoltageError,
+ Unknown,
+ Ok
+ };
+
+ enum State {
+ ReadingPosition,
+ Writing,
+ Available,
+ };
+
+ /** Create MX12 instance
+ *
+ * @param tx board pin used for transmission in UART daisy chain link
+ * to servomotors
+ * @param rx board pin used for reception in UART daisy chain link
+ * to servomotors
+ * @param baud modulation rate of UART signal, unit: Baud
+ * to servomotors
+ */
+ MX12(PinName tx, PinName rx, int baud=115200);
+
+ /** Send desired speed to a specifc servomotor
+ *
+ * @param mot_id a unique value in the daisy chain network to identify
+ * each servomotor
+ * @param speed a float between -1 and 1 that represents the percentage
+ * of maximum requested speed
+ */
+ void SetSpeed(unsigned char mot_id, float speed);
+
+ char IsAvailable(void);
+
+ MX12::Status GetStatus(void);
+
+ void ReadPosition(unsigned char mot_id);
+
+ float GetPosition(unsigned char mot_id);
+
+ void PrintAnswer();
+
+ void rw(unsigned char mot_id, char adress, char len, char *data);
+
+ void _ReadCallback();
+
+ char _chksm;
+
+ private:
+
+ UnbufferedSerial _mx12;
+ MX12::Status _status;
+ char _res[MX12_ANSWER_MAX_SIZE];
+ char _res_count;
+ char _len;
+ MX12::State _state;
+ float _angle[MX12_MOTOR_COUNT];
+ int _baud;
+};
+
+#endif /* MBED_MX12_H */
\ No newline at end of file