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:
jepickett
Date:
2015-12-10
Revision:
0:1a48094c99d1
Child:
1:d7642b2e155d

File content as of revision 0:1a48094c99d1:

/* 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"


enum ControlTable
{
    ModelNumberLow      = 0,        // RD
    ModelNumberHigh     = 1,        // RD
    FirmwareVersion     = 2,        // RD
    ID                  = 3,        // RD/WR
    BaudRate            = 4,        // RD/WR
    ReturnDelayTime     = 5,        // RD/WR
    CWAngleLimitL       = 6,        // RD/WR
    CWAngleLimitH       = 7,        // RD/WR
    CCWAngleLimitL      = 8,        // RD/WR
    CCWAngleLimitH      = 9,        // RD/WR
    Reserved1           = 10,
    TemperatureLimit    = 11,       // RD/WR
    VoltageLow          = 12,       // RD/WR
    VoltageHigh         = 13,       // RD/WR
    MaxTorqueL          = 14,       // RD/WR
    MaxTorqueH          = 15,       // RD/WR
    StatusReturnLevel   = 16,       // RD/WR
    AlarmLED            = 17,       // RD/WR
    AlarmShutdown       = 18,       // RD/WR
    Reserved2           = 19,
    DownCalibrationL    = 20,       // RR
    DownCalibrationH    = 21,       // RD
    UpCalibrationL      = 22,       // RD
    UpCalibrationH      = 23,       // RD
    TorqueEnable        = 24,       // RD/WR
    LED                 = 25,       // RD/WR
    CWComplianceMargin  = 26,       // RD/WR
    CCWComplianceMargin = 27,       // RD/WR
    CWComplianceSlope   = 28,       // RD/WR
    CCWComplianceSlope  = 29,       // RD/WR
    GoalPositionL       = 30,       // RD/WR
    GoalPositionH       = 31,       // RD/WR
    MovingSpeedL        = 32,       // RD/WR
    MovingSpeedH        = 33,       // RD/WR
    TorqueLimitL        = 34,       // RD/WR
    TorqueLimitH        = 35,       // RD/WR
    PresentPositionL    = 36,       // RD
    PresentPositionH    = 37,       // RD
    PresentSpeedL       = 38,       // RD
    PresentSpeedH       = 39,       // RD
    PresentLoadL        = 40,       // RD
    PresentLoadH        = 41,       // RD
    PresentVoltage      = 42,       // RD
    PresentTemperature  = 43,       // RD
    RegisteredInst      = 44,       // RD/WR
    Reserved3           = 45,       
    Moving              = 46,       // RD
    Lock                = 47,       // RD/WR
    PunchL              = 48,       // RD/WR
    PunchH              = 49        // RD/WR
};

class AX12
{

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

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

    // Sets toe 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
    float GetTemperature(void);

    // gets the servo power supply voltage
    float GetSupplyVoltage(void);

private :
    ServoId _ID;
    DynamixelBus* _pbus;
};
#endif