Provides an interface to an AX-12A servo. Requires the Dynamixel bus protocol library

Dependents:   RobotArmDemo

Fork of AX-12A by robot arm demo team

AX12.h

Committer:
henryrawas
Date:
2016-01-07
Revision:
10:e4c9b94b5879
Parent:
8:b6979be5a0a7
Child:
11:8de493bd8922

File content as of revision 10:e4c9b94b5879:

/* Copyright (c) 2012 Martin Smith, MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef MBED_AX12_H
#define MBED_AX12_H

#include "mbed.h"
#include "DynamixelBus.h"
#include "RobotNode.h"

enum ControlTable
{
    ctModelNumberLow      = 0,        // RD
    ctModelNumberHigh     = 1,        // RD
    ctFirmwareVersion     = 2,        // RD
    ctID                  = 3,        // RD/WR
    ctBaudRate            = 4,        // RD/WR
    ctReturnDelayTime     = 5,        // RD/WR
    ctCWAngleLimitL       = 6,        // RD/WR
    ctCWAngleLimitH       = 7,        // RD/WR
    ctCCWAngleLimitL      = 8,        // RD/WR
    ctCCWAngleLimitH      = 9,        // RD/WR
    ctReserved1           = 10,
    ctTemperatureLimit    = 11,       // RD/WR
    ctVoltageLow          = 12,       // RD/WR
    ctVoltageHigh         = 13,       // RD/WR
    ctMaxTorqueL          = 14,       // RD/WR
    ctMaxTorqueH          = 15,       // RD/WR
    ctStatusReturnLevel   = 16,       // RD/WR
    ctAlarmLED            = 17,       // RD/WR
    ctAlarmShutdown       = 18,       // RD/WR
    ctReserved2           = 19,
    ctDownCalibrationL    = 20,       // RR
    ctDownCalibrationH    = 21,       // RD
    ctUpCalibrationL      = 22,       // RD
    ctUpCalibrationH      = 23,       // RD
    ctTorqueEnable        = 24,       // RD/WR
    ctLED                 = 25,       // RD/WR
    ctCWComplianceMargin  = 26,       // RD/WR
    ctCCWComplianceMargin = 27,       // RD/WR
    ctCWComplianceSlope   = 28,       // RD/WR
    ctCCWComplianceSlope  = 29,       // RD/WR
    ctGoalPositionL       = 30,       // RD/WR
    ctGoalPositionH       = 31,       // RD/WR
    ctMovingSpeedL        = 32,       // RD/WR
    ctMovingSpeedH        = 33,       // RD/WR
    ctTorqueLimitL        = 34,       // RD/WR
    ctTorqueLimitH        = 35,       // RD/WR
    ctPresentPositionL    = 36,       // RD
    ctPresentPositionH    = 37,       // RD
    ctPresentSpeedL       = 38,       // RD
    ctPresentSpeedH       = 39,       // RD
    ctPresentLoadL        = 40,       // RD
    ctPresentLoadH        = 41,       // RD
    ctPresentVoltage      = 42,       // RD
    ctPresentTemperature  = 43,       // RD
    ctRegisteredInst      = 44,       // RD/WR
    ctReserved3           = 45,       
    ctMoving              = 46,       // RD
    ctLock                = 47,       // RD/WR
    ctPunchL              = 48,       // RD/WR
    ctPunchH              = 49        // RD/WR
};

class AX12
{

public:
    AX12(DynamixelBus* pbus, ServoId = 1);

    // sets the servo ID
    StatusCode SetServoId(char newId);

    // returns the status of the servo (connected/not connected + errors)
    StatusCode Ping();

    // Sets the goal position of the servo in degrees
    StatusCode SetGoal(float degrees);

    // determines if the servo is moving
    bool IsMoving(void);

    // gets the position of the servo in degrees
    float GetPosition();

    // gets the internal temperature of the servo
    int GetTemperature(void);

    // gets the servo power supply voltage
    float GetSupplyVoltage(void);
    
    // gets the servo load
    float GetLoad(void);
    
    // enables/disables holding torque 
    StatusCode TorqueEnable( bool );

    // get last error
    virtual int GetLastError();
   
    // check if has error
    virtual bool HasError();

    
private :
    ServoId _ID;
    DynamixelBus* _pbus;
    
    unsigned char _LastError;
    
};
#endif