brbrain
Class AXRegister

java.lang.Object
  extended by brbrain.AXRegister
Direct Known Subclasses:
AX12Register, AXS1Register

public abstract class AXRegister
extends java.lang.Object

Represents the Dynamixel AX registers in a high-level way.

Multi-byte registers are handled as single values, write control and value clamping is provided, encoding and decoding from the 11 bit sign magnitude representation used by some AX-12 registers is handled, and translation to and from natural fractional units is included.

Copyright (C) 2008 Marsette A. Vona, III

Author:
Marsette (Marty) A. Vona, III

Field Summary
static int E_ANGLE_LIMIT
          Dynamixel error bit (goal pos out of range)
static int E_CHECKSUM
          Dynamixel error bit (comm failure)
static int E_INPUT_VOLTAGE
          Dynamixel error bit
static int E_INSTRUCTION
          Dynamixel error bit (invalid instruction)
static int E_OVERHEATING
          Dynamixel error bit
static int E_OVERLOAD
          Dynamixel error bit (insufficient torque)
static int E_RANGE
          Dynamixel error bit (write parameter out of range)
 int max
          maximum valid write value of this register, if writeable
static int MAX_DYNAMIXEL_ID
          maximum Dynamixel ID
 int min
          minimum valid write value of this register, if writeable
 java.lang.String naturalUnitsLabel
          human-readable label for the natural units, if any
 float naturalUnitsPerCount
          multiplier taking natural units to int register counts
 int ordinal
          zero-based index of this register in the register bank
 java.lang.String prettyName
          pretty human-readable register name
static int RAM_START_ADDRESS
          start address of RAM
 boolean signMagnitude11Bit
          Whether this is a 2-byte little endian reg with a 10 bit magnitude and the sign in bit 11.
 int startAddr
          start (byte) address of this register in the AX-12 register space
private static java.lang.String svnid
           
 boolean useNaturalUnitsByDefault
          whether to prefer natural or raw units by default
 int width
          byte width of this register
 boolean writeable
          whether this register can be written
 
Constructor Summary
protected AXRegister(int ordinal, java.lang.String prettyName, int startAddr, int width, boolean signMagnitude11Bit, float naturalUnitsPerCount, java.lang.String naturalUnitsLabel, boolean useNaturalUnitsByDefault)
          read-only reg with all options
protected AXRegister(int ordinal, java.lang.String prettyName, int startAddr, int width, int min, int max, boolean signMagnitude11Bit, float naturalUnitsPerCount, java.lang.String naturalUnitsLabel, boolean useNaturalUnitsByDefault)
          writeable reg with all options
 
Method Summary
 int check(float value)
          covers check(int), converts fromNaturalUnits(float)
 int check(int value)
          Check if an integer write value is within the closed interval [min, max].
static void checkSpan(AXRegister start, int n)
          verify that (start, n) is a valid span of registers
 float clamp(float value)
          Covers clamp(int), converts fromNaturalUnits(float) and toNaturalUnits(int).
 int clamp(int value)
          Clamp an integer write value to the closed interval [min, max].
static boolean containsReadOnlyRegs(AXRegister start, int n)
          check whether a span of registers contains any which are read-only
 int decode(int value)
          Encode an integer read value from the register bits.
static AXRegister[] dup(AXRegister[] from, AXRegister[] to)
          Covers dup(AXRegister[], AXRegister[], int), copies all.
static AXRegister[] dup(AXRegister[] from, AXRegister[] to, int n)
          duplicate first n element of from into to, reallocating as necessary
 int encode(int value)
          Encode an integer write value into the bits to write to the register.
static AXRegister[] ensureCapacity(AXRegister[] a, int n)
          make sure a is at least length n
static java.lang.String errorsToString(int errors)
          Covers errorsToString(int, StringBuffer)
static java.lang.StringBuffer errorsToString(int errors, java.lang.StringBuffer buf)
          Compose a human-readable string of AX-12 errors from a Dynamixel error bitfield.
 int fromNaturalUnits(float value)
          Convert a register int value from natural units.
protected abstract  java.lang.String getDynamixelType()
          get an identifier for registers of this Dynamixel type
abstract  int getNumRegisters()
          get the total number of registers in this Dynamixel type
abstract  AXRegister getRelativeRegister(int offset)
          get the register with the given relative ordinal
static float interp(float abscissa, float valueAtLowEnd, float abscissaAtLowEnd, float valueAtHighEnd, float abscissaAtHighEnd)
          Linearly interpolate between the points (abscissaAtLowEnd, valueAtLowEnd) and (abscissaAtHighEnd, valueAtHighEnd).
 boolean isBoolean()
          check if this is a boolean valued register
 boolean isRAM()
          true iff register is in RAM
 AXRegister nextRegister()
          get the next register after this one
 AXRegister prevRegister()
          get register before this one
static AXRegister[] span(AXRegister start)
          covers span(AXRegister, int), spans till end
static AXRegister[] span(AXRegister start, AXRegister[] span)
          covers span(AXRegister, int, AXRegister[]), spans till end
static AXRegister[] span(AXRegister start, int n)
          covers span(AXRegister, int, AXRegister[]), always conses
static AXRegister[] span(AXRegister start, int n, AXRegister[] span)
          Return span of n regs from start.
 java.lang.String toIdentifierString()
          returns the Java identifier for this register
 float toNaturalUnits(int value)
          Convert a register int value to natural units.
 java.lang.String toString()
          returns prettyName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

svnid

private static final java.lang.String svnid
See Also:
Constant Field Values

MAX_DYNAMIXEL_ID

public static final int MAX_DYNAMIXEL_ID
maximum Dynamixel ID

See Also:
Constant Field Values

RAM_START_ADDRESS

public static final int RAM_START_ADDRESS
start address of RAM

See Also:
Constant Field Values

E_INPUT_VOLTAGE

public static final int E_INPUT_VOLTAGE
Dynamixel error bit

See Also:
Constant Field Values

E_ANGLE_LIMIT

public static final int E_ANGLE_LIMIT
Dynamixel error bit (goal pos out of range)

See Also:
Constant Field Values

E_OVERHEATING

public static final int E_OVERHEATING
Dynamixel error bit

See Also:
Constant Field Values

E_RANGE

public static final int E_RANGE
Dynamixel error bit (write parameter out of range)

See Also:
Constant Field Values

E_CHECKSUM

public static final int E_CHECKSUM
Dynamixel error bit (comm failure)

See Also:
Constant Field Values

E_OVERLOAD

public static final int E_OVERLOAD
Dynamixel error bit (insufficient torque)

See Also:
Constant Field Values

E_INSTRUCTION

public static final int E_INSTRUCTION
Dynamixel error bit (invalid instruction)

See Also:
Constant Field Values

ordinal

public final int ordinal
zero-based index of this register in the register bank


prettyName

public final java.lang.String prettyName
pretty human-readable register name


startAddr

public final int startAddr
start (byte) address of this register in the AX-12 register space


width

public final int width
byte width of this register


writeable

public final boolean writeable
whether this register can be written


min

public final int min
minimum valid write value of this register, if writeable


max

public final int max
maximum valid write value of this register, if writeable


naturalUnitsLabel

public final java.lang.String naturalUnitsLabel
human-readable label for the natural units, if any


useNaturalUnitsByDefault

public final boolean useNaturalUnitsByDefault
whether to prefer natural or raw units by default


signMagnitude11Bit

public final boolean signMagnitude11Bit

Whether this is a 2-byte little endian reg with a 10 bit magnitude and the sign in bit 11.

When the sign bit is set the value is interpreted as negative or clocwise.


naturalUnitsPerCount

public final float naturalUnitsPerCount
multiplier taking natural units to int register counts

Constructor Detail

AXRegister

protected AXRegister(int ordinal,
                     java.lang.String prettyName,
                     int startAddr,
                     int width,
                     int min,
                     int max,
                     boolean signMagnitude11Bit,
                     float naturalUnitsPerCount,
                     java.lang.String naturalUnitsLabel,
                     boolean useNaturalUnitsByDefault)
writeable reg with all options


AXRegister

protected AXRegister(int ordinal,
                     java.lang.String prettyName,
                     int startAddr,
                     int width,
                     boolean signMagnitude11Bit,
                     float naturalUnitsPerCount,
                     java.lang.String naturalUnitsLabel,
                     boolean useNaturalUnitsByDefault)
read-only reg with all options

Method Detail

checkSpan

public static void checkSpan(AXRegister start,
                             int n)
verify that (start, n) is a valid span of registers


containsReadOnlyRegs

public static boolean containsReadOnlyRegs(AXRegister start,
                                           int n)
check whether a span of registers contains any which are read-only


dup

public static AXRegister[] dup(AXRegister[] from,
                               AXRegister[] to,
                               int n)
duplicate first n element of from into to, reallocating as necessary


dup

public static AXRegister[] dup(AXRegister[] from,
                               AXRegister[] to)

Covers dup(AXRegister[], AXRegister[], int), copies all.


ensureCapacity

public static AXRegister[] ensureCapacity(AXRegister[] a,
                                          int n)
make sure a is at least length n


span

public static AXRegister[] span(AXRegister start,
                                int n,
                                AXRegister[] span)

Return span of n regs from start.

Span is returned in span iff it's big enough, else a new array.

If n is less than 0 then the span includes all subsequent registers.


span

public static AXRegister[] span(AXRegister start,
                                int n)
covers span(AXRegister, int, AXRegister[]), always conses


span

public static AXRegister[] span(AXRegister start,
                                AXRegister[] span)
covers span(AXRegister, int, AXRegister[]), spans till end


span

public static AXRegister[] span(AXRegister start)
covers span(AXRegister, int), spans till end


interp

public static float interp(float abscissa,
                           float valueAtLowEnd,
                           float abscissaAtLowEnd,
                           float valueAtHighEnd,
                           float abscissaAtHighEnd)

Linearly interpolate between the points (abscissaAtLowEnd, valueAtLowEnd) and (abscissaAtHighEnd, valueAtHighEnd).


errorsToString

public static final java.lang.StringBuffer errorsToString(int errors,
                                                          java.lang.StringBuffer buf)

Compose a human-readable string of AX-12 errors from a Dynamixel error bitfield.

Parameters:
errors - the bitpacked error value
buf - the buffer to append, or null to make one
Returns:
the buffer to which the string was appended

errorsToString

public static final java.lang.String errorsToString(int errors)
Covers errorsToString(int, StringBuffer)


isRAM

public boolean isRAM()
true iff register is in RAM


check

public int check(int value)

Check if an integer write value is within the closed interval [min, max].

Parameters:
value - the value to check
Returns:
-1 if value is too low, +1 if it's too high, 0 if it's ok

check

public int check(float value)
covers check(int), converts fromNaturalUnits(float)


clamp

public int clamp(int value)

Clamp an integer write value to the closed interval [min, max].

Parameters:
value - the value to clamp
Returns:
the clamped value

clamp

public float clamp(float value)

Covers clamp(int), converts fromNaturalUnits(float) and toNaturalUnits(int).


encode

public int encode(int value)

Encode an integer write value into the bits to write to the register.

Handles conversion to signMagnitude11Bit as appropriate.

Parameters:
value - the value to encode
Returns:
the encoded value

decode

public int decode(int value)

Encode an integer read value from the register bits.

Handles conversion from signMagnitude11Bit as appropriate.

Parameters:
value - the value to decode
Returns:
the decoded value

toNaturalUnits

public float toNaturalUnits(int value)

Convert a register int value to natural units.

Default impl just multiplies by naturalUnitsPerCount.

Parameters:
value - the int value to convert
Returns:
the value in natural units

fromNaturalUnits

public int fromNaturalUnits(float value)

Convert a register int value from natural units.

Default impl just divides by naturalUnitsPerCount.

Parameters:
value - the natural value to convert
Returns:
the value in int counts

isBoolean

public boolean isBoolean()
check if this is a boolean valued register


getRelativeRegister

public abstract AXRegister getRelativeRegister(int offset)
get the register with the given relative ordinal


getNumRegisters

public abstract int getNumRegisters()
get the total number of registers in this Dynamixel type


nextRegister

public AXRegister nextRegister()
get the next register after this one


prevRegister

public AXRegister prevRegister()
get register before this one


toString

public java.lang.String toString()
returns prettyName

Overrides:
toString in class java.lang.Object

getDynamixelType

protected abstract java.lang.String getDynamixelType()
get an identifier for registers of this Dynamixel type


toIdentifierString

public java.lang.String toIdentifierString()
returns the Java identifier for this register