A library for the AX-12+ servo using external ICs instead of the SerialHalf-Duplex class

A library based on the AX-12+ library but using external hardware to convert from full to half duplex as suggested in the AX-12 datasheet. The buffers and NOT gate need to connected as shown below.

640

Don't forget the pull-up resistor!

Committer:
ms523
Date:
Sun Aug 07 13:06:04 2011 +0000
Revision:
1:1dd9cd18975d
Parent:
0:d4af99baf76f
Child:
2:3000c6778d1c
Bare bones library for AX-12+ Servo plus external hardware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ms523 1:1dd9cd18975d 1 /* mbed AX-12+ Servo Library - External hardware version */
ms523 0:d4af99baf76f 2
ms523 0:d4af99baf76f 3 #ifndef MBED_AX12_H
ms523 0:d4af99baf76f 4 #define MBED_AX12_H
ms523 0:d4af99baf76f 5
ms523 0:d4af99baf76f 6 #include "mbed.h"
ms523 0:d4af99baf76f 7
ms523 0:d4af99baf76f 8 #define AX12_WRITE_DEBUG 0
ms523 0:d4af99baf76f 9 #define AX12_READ_DEBUG 0
ms523 0:d4af99baf76f 10 #define AX12_TRIGGER_DEBUG 0
ms523 0:d4af99baf76f 11 #define AX12_DEBUG 0
ms523 0:d4af99baf76f 12
ms523 0:d4af99baf76f 13 #define AX12_REG_GOAL_POSITION 0x1E
ms523 0:d4af99baf76f 14 #define AX12_REG_MOVING_SPEED 0x20
ms523 0:d4af99baf76f 15 #define AX12_REG_POSITION 0x24
ms523 0:d4af99baf76f 16
ms523 0:d4af99baf76f 17 #define TRANSMIT 1
ms523 0:d4af99baf76f 18 #define RECEIVE 0
ms523 0:d4af99baf76f 19
ms523 0:d4af99baf76f 20 class AX12 {
ms523 0:d4af99baf76f 21
ms523 0:d4af99baf76f 22 public:
ms523 0:d4af99baf76f 23 // define which pins are used, and the ID of this instance
ms523 0:d4af99baf76f 24 AX12(PinName tx, PinName rx, PinName dir, int ID);
ms523 0:d4af99baf76f 25
ms523 0:d4af99baf76f 26 // methods for writing and reading registers
ms523 0:d4af99baf76f 27 int read(int ID, int start, int length, char* data);
ms523 1:1dd9cd18975d 28 int write(int ID, int start, int length, char* data);
ms523 0:d4af99baf76f 29
ms523 0:d4af99baf76f 30 // set goal angle in integer degrees
ms523 1:1dd9cd18975d 31 int SetGoal(int degrees);
ms523 1:1dd9cd18975d 32
ms523 1:1dd9cd18975d 33 float GetPosition(); // Get current angle, only valid 0-300
ms523 0:d4af99baf76f 34
ms523 0:d4af99baf76f 35 private :
ms523 0:d4af99baf76f 36 Serial _ax12;
ms523 0:d4af99baf76f 37 DigitalOut _dir;
ms523 0:d4af99baf76f 38 int _ID;
ms523 0:d4af99baf76f 39 };
ms523 1:1dd9cd18975d 40 #endif