Mark Norman / Mbed 2 deprecated Nottingham

Dependencies:   mbed

Committer:
merlinsystemscorp
Date:
Tue Dec 14 11:32:52 2010 +0000
Revision:
0:191698f11ceb
Nottingham Lab Warehouse Controller

Who changed what in which revision?

UserRevisionLine numberNew contents of line
merlinsystemscorp 0:191698f11ceb 1 /* mbed AX-12+ Servo Library
merlinsystemscorp 0:191698f11ceb 2 *
merlinsystemscorp 0:191698f11ceb 3 * Copyright (c) 2010, cstyles (http://mbed.org)
merlinsystemscorp 0:191698f11ceb 4 *
merlinsystemscorp 0:191698f11ceb 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
merlinsystemscorp 0:191698f11ceb 6 * of this software and associated documentation files (the "Software"), to deal
merlinsystemscorp 0:191698f11ceb 7 * in the Software without restriction, including without limitation the rights
merlinsystemscorp 0:191698f11ceb 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
merlinsystemscorp 0:191698f11ceb 9 * copies of the Software, and to permit persons to whom the Software is
merlinsystemscorp 0:191698f11ceb 10 * furnished to do so, subject to the following conditions:
merlinsystemscorp 0:191698f11ceb 11 *
merlinsystemscorp 0:191698f11ceb 12 * The above copyright notice and this permission notice shall be included in
merlinsystemscorp 0:191698f11ceb 13 * all copies or substantial portions of the Software.
merlinsystemscorp 0:191698f11ceb 14 *
merlinsystemscorp 0:191698f11ceb 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
merlinsystemscorp 0:191698f11ceb 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
merlinsystemscorp 0:191698f11ceb 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
merlinsystemscorp 0:191698f11ceb 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
merlinsystemscorp 0:191698f11ceb 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
merlinsystemscorp 0:191698f11ceb 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
merlinsystemscorp 0:191698f11ceb 21 * THE SOFTARE.
merlinsystemscorp 0:191698f11ceb 22 */
merlinsystemscorp 0:191698f11ceb 23 #ifndef MBED_AX12_H
merlinsystemscorp 0:191698f11ceb 24 #define MBED_AX12_H
merlinsystemscorp 0:191698f11ceb 25
merlinsystemscorp 0:191698f11ceb 26 #include "mbed.h"
merlinsystemscorp 0:191698f11ceb 27 #include "BlockingSerial.h"
merlinsystemscorp 0:191698f11ceb 28
merlinsystemscorp 0:191698f11ceb 29 #define AX12_WRITE_DEBUG 0
merlinsystemscorp 0:191698f11ceb 30 #define AX12_READ_DEBUG 0
merlinsystemscorp 0:191698f11ceb 31 #define AX12_TRIGGER_DEBUG 0
merlinsystemscorp 0:191698f11ceb 32 #define AX12_DEBUG 0
merlinsystemscorp 0:191698f11ceb 33
merlinsystemscorp 0:191698f11ceb 34 #define AX12_REG_ID 0x3
merlinsystemscorp 0:191698f11ceb 35 #define AX12_REG_CW_LIMIT 0x06
merlinsystemscorp 0:191698f11ceb 36 #define AX12_REG_CCW_LIMIT 0x08
merlinsystemscorp 0:191698f11ceb 37 #define AX12_REG_GOAL_POSITION 0x1E
merlinsystemscorp 0:191698f11ceb 38 #define AX12_REG_MOVING_SPEED 0x20
merlinsystemscorp 0:191698f11ceb 39 #define AX12_REG_VOLTS 0x2A
merlinsystemscorp 0:191698f11ceb 40 #define AX12_REG_TEMP 0x2B
merlinsystemscorp 0:191698f11ceb 41 #define AX12_REG_MOVING 0x2E
merlinsystemscorp 0:191698f11ceb 42 #define AX12_REG_POSITION 0x24
merlinsystemscorp 0:191698f11ceb 43
merlinsystemscorp 0:191698f11ceb 44 #define AX12_MODE_POSITION 0
merlinsystemscorp 0:191698f11ceb 45 #define AX12_MODE_ROTATION 1
merlinsystemscorp 0:191698f11ceb 46
merlinsystemscorp 0:191698f11ceb 47 #define AX12_CW 1
merlinsystemscorp 0:191698f11ceb 48 #define AX12_CCW 0
merlinsystemscorp 0:191698f11ceb 49
merlinsystemscorp 0:191698f11ceb 50 class AX12 {
merlinsystemscorp 0:191698f11ceb 51
merlinsystemscorp 0:191698f11ceb 52 public:
merlinsystemscorp 0:191698f11ceb 53
merlinsystemscorp 0:191698f11ceb 54 // define which pins are used, and the ID of this instance
merlinsystemscorp 0:191698f11ceb 55 // Mutiple AX12's can share the same pins.
merlinsystemscorp 0:191698f11ceb 56 AX12(PinName tx, PinName rx, int ID);
merlinsystemscorp 0:191698f11ceb 57
merlinsystemscorp 0:191698f11ceb 58 // methods for writing and reading registers
merlinsystemscorp 0:191698f11ceb 59 int read(int ID, int start, int length, char* data);
merlinsystemscorp 0:191698f11ceb 60 int write(int ID, int start, int length, char* data, int flag=0);
merlinsystemscorp 0:191698f11ceb 61
merlinsystemscorp 0:191698f11ceb 62 // set goal angle in integer degrees
merlinsystemscorp 0:191698f11ceb 63 // flags[0] = blocking (only returns when goal reached
merlinsystemscorp 0:191698f11ceb 64 // flags[1] = register. Requires broadcast trigger to activate
merlinsystemscorp 0:191698f11ceb 65 int SetGoal(int degrees, int flags = 0);
merlinsystemscorp 0:191698f11ceb 66
merlinsystemscorp 0:191698f11ceb 67 // Mode = 0, positional
merlinsystemscorp 0:191698f11ceb 68 // Mode = 1, continuous rotation
merlinsystemscorp 0:191698f11ceb 69 int SetMode(int mode);
merlinsystemscorp 0:191698f11ceb 70
merlinsystemscorp 0:191698f11ceb 71 // Speed is -1.0 (CCW) to 1.0 (CW)
merlinsystemscorp 0:191698f11ceb 72 int SetCRSpeed(float speed);
merlinsystemscorp 0:191698f11ceb 73
merlinsystemscorp 0:191698f11ceb 74 // set these in degrees, CCW limit is 300
merlinsystemscorp 0:191698f11ceb 75 // If both are set to zero, we are continuous rotation
merlinsystemscorp 0:191698f11ceb 76 int SetCWLimit(int degrees);
merlinsystemscorp 0:191698f11ceb 77 int SetCCWLimit(int degrees);
merlinsystemscorp 0:191698f11ceb 78
merlinsystemscorp 0:191698f11ceb 79 // Change the ID
merlinsystemscorp 0:191698f11ceb 80 int SetID(int CurrentID, int NewID);
merlinsystemscorp 0:191698f11ceb 81
merlinsystemscorp 0:191698f11ceb 82 // returns true if the motor is in motion
merlinsystemscorp 0:191698f11ceb 83 int isMoving(void);
merlinsystemscorp 0:191698f11ceb 84
merlinsystemscorp 0:191698f11ceb 85 // broadcast to trigger registered goals
merlinsystemscorp 0:191698f11ceb 86 void trigger(void);
merlinsystemscorp 0:191698f11ceb 87
merlinsystemscorp 0:191698f11ceb 88 // Get current angle, only valid 0-300
merlinsystemscorp 0:191698f11ceb 89 float GetPosition();
merlinsystemscorp 0:191698f11ceb 90
merlinsystemscorp 0:191698f11ceb 91 // In volts and ^C
merlinsystemscorp 0:191698f11ceb 92 float GetTemp(void);
merlinsystemscorp 0:191698f11ceb 93 float GetVolts(void);
merlinsystemscorp 0:191698f11ceb 94
merlinsystemscorp 0:191698f11ceb 95 private :
merlinsystemscorp 0:191698f11ceb 96 //SerialHalfDuplex _ax12;
merlinsystemscorp 0:191698f11ceb 97 BlockingSerial _ax12;
merlinsystemscorp 0:191698f11ceb 98 int _ID;
merlinsystemscorp 0:191698f11ceb 99
merlinsystemscorp 0:191698f11ceb 100 };
merlinsystemscorp 0:191698f11ceb 101
merlinsystemscorp 0:191698f11ceb 102 #endif