Fish Feeder

Fork of AX12 by Chris Styles

Committer:
chris
Date:
Thu Jun 03 14:22:25 2010 +0000
Revision:
0:be51952765ec
Child:
1:93ad80f5fde7

        

Who changed what in which revision?

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