brbrain
Class Pose

java.lang.Object
  extended by brbrain.Pose

public class Pose
extends java.lang.Object

Bioloid pose.

A pose contains values for a collection of AXRegisters for a set of dynamixels. The register collection is the same across all dynamixels, and must consist of registers for only one dynamixel type (e.g. AX12Register or AXS1Register). Neither the register collection nor the set of dynamixels are mutable, but the values of the registers are. The recommended synchronization object for value mutation is the Pose object itself.

The collections of registers and axIDs need not be ordered or contiguous; however axIDs does need to be unique.

BRBrain read and write formats will be computed, respectively, as the shortest contiguous span including all registers (read format), and as the longest contiguous span of writable RAM registers included in registers starting from the lowest-address such register in registers (write format). It is also possible to specify arguments to the constructor which override the default write format; in that case the specified write span must be a writeable subset of registers.

Methods readFrom(int[], int)/writeTo(int[], int) are providing for gathering/scattering the pose values from/to an BRBrain read/write block.

Methods readFrom(PoseTokenizer), readFrom(InputStream), and writeTo(PrintWriter) are also provided for parsing and writing the pose to character streams in lisp sexp format with semicolon comments.

Copyright (C) 2007 Marsette A. Vona, III

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Author:
Marsette (Marty) A. Vona, III

Nested Class Summary
static class Pose.PoseTokenizer
          specialized tokenizer for poses, see Pose class header doc
 
Field Summary
 int[] axIDs
          the set of axIDs; do not mutate
 java.util.Map<java.lang.Integer,java.lang.Integer> axIDToIndex
          Unmodifiable inverse mapping of dynamixel id to dynamixel index, see values.
private static java.lang.String cvsid
           
static int PRESERVE_SPEED_POSITION_EPSILON
          Position difference below which to preserve previous speed in setMovingSpeedFrom(brbrain.Pose, int).
 int readNum
          the number of regs in the BRBrain read format
 AXRegister readStart
          the first reg in the BRBrain read format
 AXRegister[] registers
          the set of registers; do not mutate
 java.util.Map<AXRegister,int[]> values
          The register values, indexed first by register and second by dynamixel index.
static int WRITE_FIELD_WIDTH
          width in characters of register values written to an output stream
 int writeNum
          the number of regs in the BRBrain write format, or 0 if none
 AXRegister writeStart
          the first reg in the BRBrain write format, or null if none
 
Constructor Summary
Pose(int[] axIDs, AXRegister[] registers)
          see class header doc; uses default write span
Pose(int[] axIDs, AXRegister[] registers, AXRegister writeStart, int writeNum)
          See class header doc.
Pose(int firstAXID, int lastAXID, AXRegister[] registers)
          see class header doc; uses default write span
Pose(int firstAXID, int lastAXID, AXRegister[] registers, AXRegister writeStart, int writeNum)
          see class header doc
Pose(Pose otherPose)
          covers Pose(Pose, boolean), always copies values
Pose(Pose otherPose, boolean copyValues)
          make a pose with same format and maybe values as another
 
Method Summary
 int getMSMorphTimeFrom(Pose otherPose)
          Compute the expected morph time in milliseconds starting from otherPose.
 int getRegisterValue(int axID, AXRegister register)
          read a register value safely
static int[] makeIDs(int firstAXID, int lastAXID)
          Makes a contiguous array of ids in the range [firstAXID, lastAXID].
 void readFrom(java.io.InputStream is)
          covers readFrom(PoseTokenizer), conses the tokenizer
 void readFrom(int[] data)
          covers readFrom(int[], int), starts at 0
 void readFrom(int[] data, int startIndex)
          Gather values from an BRBrain read block; see class header doc.
 void readFrom(Pose.PoseTokenizer t)
          Parse values in lisp sexp format.
protected  void readFrom(Pose.PoseTokenizer t, AXRegister r, int[] data)
          parse one register list
 void readFrom(Pose otherPose)
          read values from other pose
 boolean sameFormat(Pose otherPose)
          Check if this Pose is the same as otherPose except, possibly, for the contents of the values.
 void setGoalPositionFromPresent()
          Set AX12Register.AX12_GOAL_POSITION from AX12Register.AX12_PRESENT_POSITION.
 void setMovingSpeedFrom(Pose otherPose, int msMorphTime)
          Set the AX12Register.AX12_MOVING_SPEED of this Pose given the desired morph time in milliseconds starting from otherPose.
 void setRegisterValue(AXRegister register, int value)
          write same register value for all dynamixels safely
 void setRegisterValue(AXRegister register, Pose otherPose)
          copy register value for all dynamixels safely
 void setRegisterValue(int axID, AXRegister register, int value)
          write a register value safely
 void writeHeaderTo(java.io.OutputStream s)
          covers writeHeaderTo(PrintWriter)
 void writeHeaderTo(java.io.PrintWriter w)
          write a header comment with the dynamixel IDs
 void writeTo(int[] data)
          covers writeTo(int[], int), starts at 0
 void writeTo(int[] data, int startIndex)
          Scatter values to an BRBrain write block; see class header doc.
 void writeTo(java.io.OutputStream s)
          covers writeTo(PrintWriter)
 void writeTo(Pose otherPose)
          write values to other pose
 void writeTo(java.io.PrintWriter w)
          write values in the format readFrom(brbrain.Pose) expects
protected  void writeTo(java.io.PrintWriter w, AXRegister r, int[] data)
          write one register list
protected  void writeTo(java.io.PrintWriter w, int v)
          write one int left padded with spaces to WRITE_FIELD_WIDTH
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvsid

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

PRESERVE_SPEED_POSITION_EPSILON

public static final int PRESERVE_SPEED_POSITION_EPSILON

Position difference below which to preserve previous speed in setMovingSpeedFrom(brbrain.Pose, int).

See Also:
Constant Field Values

WRITE_FIELD_WIDTH

public static final int WRITE_FIELD_WIDTH
width in characters of register values written to an output stream

See Also:
Constant Field Values

axIDs

public final int[] axIDs
the set of axIDs; do not mutate


registers

public final AXRegister[] registers
the set of registers; do not mutate


readStart

public final AXRegister readStart
the first reg in the BRBrain read format


writeStart

public final AXRegister writeStart
the first reg in the BRBrain write format, or null if none


readNum

public final int readNum
the number of regs in the BRBrain read format


writeNum

public final int writeNum
the number of regs in the BRBrain write format, or 0 if none


values

public java.util.Map<AXRegister,int[]> values

The register values, indexed first by register and second by dynamixel index.

The map itself is not mutable (TBD), but the contents of the value arrays are. The containing Pose is the recommended synchronization object.

Dynamixel indices are the zero-based index of the dynamixel ID in axIDs, and dynamixel index i is not necessarily the same as axIDs[i]. See axIDToIndex.


axIDToIndex

public java.util.Map<java.lang.Integer,java.lang.Integer> axIDToIndex

Unmodifiable inverse mapping of dynamixel id to dynamixel index, see values.

Constructor Detail

Pose

public Pose(Pose otherPose,
            boolean copyValues)
make a pose with same format and maybe values as another


Pose

public Pose(Pose otherPose)
covers Pose(Pose, boolean), always copies values


Pose

public Pose(int[] axIDs,
            AXRegister[] registers,
            AXRegister writeStart,
            int writeNum)

See class header doc.

Parameters:
writeStart - overrides the default iff non-null
writeNum - overrides the default iff non-negative

Pose

public Pose(int[] axIDs,
            AXRegister[] registers)
see class header doc; uses default write span


Pose

public Pose(int firstAXID,
            int lastAXID,
            AXRegister[] registers,
            AXRegister writeStart,
            int writeNum)
see class header doc


Pose

public Pose(int firstAXID,
            int lastAXID,
            AXRegister[] registers)
see class header doc; uses default write span

Method Detail

makeIDs

public static int[] makeIDs(int firstAXID,
                            int lastAXID)

Makes a contiguous array of ids in the range [firstAXID, lastAXID].


sameFormat

public boolean sameFormat(Pose otherPose)

Check if this Pose is the same as otherPose except, possibly, for the contents of the values.


getRegisterValue

public int getRegisterValue(int axID,
                            AXRegister register)
read a register value safely


setRegisterValue

public void setRegisterValue(int axID,
                             AXRegister register,
                             int value)
write a register value safely


setRegisterValue

public void setRegisterValue(AXRegister register,
                             int value)
write same register value for all dynamixels safely


setRegisterValue

public void setRegisterValue(AXRegister register,
                             Pose otherPose)
copy register value for all dynamixels safely


getMSMorphTimeFrom

public int getMSMorphTimeFrom(Pose otherPose)

Compute the expected morph time in milliseconds starting from otherPose.

This Pose and otherPose must have the same axIDs and must both include AX12Register.AX12_GOAL_POSITION. This Pose must also include AX12Register.AX12_MOVING_SPEED. The morph time is the maximum time it would take any dynamixel to move from the other pose to this pose at the given speed.


setGoalPositionFromPresent

public void setGoalPositionFromPresent()

Set AX12Register.AX12_GOAL_POSITION from AX12Register.AX12_PRESENT_POSITION.


setMovingSpeedFrom

public void setMovingSpeedFrom(Pose otherPose,
                               int msMorphTime)

Set the AX12Register.AX12_MOVING_SPEED of this Pose given the desired morph time in milliseconds starting from otherPose.

Recriprocal to getMSMorphTimeFrom(brbrain.Pose). The AX12Register.AX12_MOVING_SPEED is computed for all dynamixels which change goal position more than PRESERVE_SPEED_POSITION_EPSILON so that they all move for the entire duration of the morph.


readFrom

public void readFrom(Pose otherPose)
read values from other pose


writeTo

public void writeTo(Pose otherPose)
write values to other pose


readFrom

public void readFrom(int[] data,
                     int startIndex)

Gather values from an BRBrain read block; see class header doc.


readFrom

public void readFrom(int[] data)
covers readFrom(int[], int), starts at 0


writeTo

public void writeTo(int[] data,
                    int startIndex)

Scatter values to an BRBrain write block; see class header doc.


writeTo

public void writeTo(int[] data)
covers writeTo(int[], int), starts at 0


readFrom

public void readFrom(Pose.PoseTokenizer t)
              throws java.io.IOException

Parse values in lisp sexp format.

The values are parsed as a list of register lists in the order of registers, with each register list containing the register value for each dynamixel in the order of axIDs.

Lisp semicolon comments are ignored.

Throws:
java.io.IOException

readFrom

public void readFrom(java.io.InputStream is)
              throws java.io.IOException
covers readFrom(PoseTokenizer), conses the tokenizer

Throws:
java.io.IOException

readFrom

protected void readFrom(Pose.PoseTokenizer t,
                        AXRegister r,
                        int[] data)
                 throws java.io.IOException
parse one register list

Throws:
java.io.IOException

writeTo

public void writeTo(java.io.PrintWriter w)
             throws java.io.IOException
write values in the format readFrom(brbrain.Pose) expects

Throws:
java.io.IOException

writeTo

public void writeTo(java.io.OutputStream s)
             throws java.io.IOException
covers writeTo(PrintWriter)

Throws:
java.io.IOException

writeTo

protected void writeTo(java.io.PrintWriter w,
                       AXRegister r,
                       int[] data)
                throws java.io.IOException
write one register list

Throws:
java.io.IOException

writeTo

protected void writeTo(java.io.PrintWriter w,
                       int v)
                throws java.io.IOException
write one int left padded with spaces to WRITE_FIELD_WIDTH

Throws:
java.io.IOException

writeHeaderTo

public void writeHeaderTo(java.io.PrintWriter w)
                   throws java.io.IOException
write a header comment with the dynamixel IDs

Throws:
java.io.IOException

writeHeaderTo

public void writeHeaderTo(java.io.OutputStream s)
                   throws java.io.IOException
covers writeHeaderTo(PrintWriter)

Throws:
java.io.IOException