brbrain
Class SequencePlaybackController

java.lang.Object
  extended by brbrain.SequencePlaybackController

public class SequencePlaybackController
extends java.lang.Object

PoseSequence playback controller.

The sequence playback controller is installed into a PoseSequenceGUI and controls initiation, progress, and termination of pose sequence playback.

This class gives a default implementation which starts playback whenever there are more poses in the sequence and stops it when the opposite is true. Playback is advanced from pose to pose in the sequence order whenever the time deadline for the current pose expires or whenever the actual mechanism pose is closeEnough(brbrain.Pose, brbrain.Pose) to the target pose.

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

Field Summary
private static java.lang.String cvsid
           
static int DEF_EPSILON
          default epsilon for closeEnough(brbrain.Pose, brbrain.Pose)
protected  int epsilon
          the epsilon for closeEnough(brbrain.Pose, brbrain.Pose)
protected  long expectedDeadlineNS
          the expected deadline of the current pose morph
 
Constructor Summary
SequencePlaybackController()
          initializes with DEF_EPSILON
SequencePlaybackController(int epsilon)
          initializes with a specific epsilon
 
Method Summary
protected  boolean advancePose(PoseSequenceGUI psg, Pose currentActualPose, Pose currentSequencePose, int currentSequenceIndex, java.lang.String reason, boolean deadlineValid, long currentTimeNS)
          Called by startPlayback(brbrain.PoseSequenceGUI, brbrain.Pose, brbrain.Pose, int) and controlPlayback(brbrain.PoseSequenceGUI, brbrain.Pose, brbrain.Pose, int) to advance to the next pose.
protected  boolean closeEnough(Pose currentActualPose, Pose currentSequencePose)
          Compare AX12Register.AX12_PRESENT_POSITION of the current actual pose to the current sequence pose and return true iff their L-infinity norm (maximum element abs difference) is less than epsilon.
 boolean controlPlayback(PoseSequenceGUI psg, Pose currentActualPose, Pose currentSequencePose, int currentSequenceIndex)
          Called by the PoseSequenceGUI to request control of playback.
protected  boolean epsilonEquals(int p, int q)
          Check if the absolute difference between p and q is less than epsilon.
 boolean startPlayback(PoseSequenceGUI psg, Pose currentActualPose, Pose currentSequencePose, int currentSequenceIndex)
          Called by the PoseSequenceGUI to request initiation of playback.
 
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

DEF_EPSILON

public static final int DEF_EPSILON
default epsilon for closeEnough(brbrain.Pose, brbrain.Pose)

See Also:
Constant Field Values

expectedDeadlineNS

protected long expectedDeadlineNS
the expected deadline of the current pose morph


epsilon

protected int epsilon
the epsilon for closeEnough(brbrain.Pose, brbrain.Pose)

Constructor Detail

SequencePlaybackController

public SequencePlaybackController(int epsilon)
initializes with a specific epsilon


SequencePlaybackController

public SequencePlaybackController()
initializes with DEF_EPSILON

Method Detail

startPlayback

public boolean startPlayback(PoseSequenceGUI psg,
                             Pose currentActualPose,
                             Pose currentSequencePose,
                             int currentSequenceIndex)

Called by the PoseSequenceGUI to request initiation of playback.

If playback should be initiated, typically this would call advancePose(brbrain.PoseSequenceGUI, brbrain.Pose, brbrain.Pose, int, java.lang.String, boolean, long).

See class header doc for behavior of default impl.

Returns:
true iff playback was initiated

controlPlayback

public boolean controlPlayback(PoseSequenceGUI psg,
                               Pose currentActualPose,
                               Pose currentSequencePose,
                               int currentSequenceIndex)

Called by the PoseSequenceGUI to request control of playback.

Typically this would call advancePose(brbrain.PoseSequenceGUI, brbrain.Pose, brbrain.Pose, int, java.lang.String, boolean, long) as necessary.

See class header doc for behavior of default impl.

Returns:
true iff playback is still ongoing

advancePose

protected boolean advancePose(PoseSequenceGUI psg,
                              Pose currentActualPose,
                              Pose currentSequencePose,
                              int currentSequenceIndex,
                              java.lang.String reason,
                              boolean deadlineValid,
                              long currentTimeNS)

Called by startPlayback(brbrain.PoseSequenceGUI, brbrain.Pose, brbrain.Pose, int) and controlPlayback(brbrain.PoseSequenceGUI, brbrain.Pose, brbrain.Pose, int) to advance to the next pose.


closeEnough

protected boolean closeEnough(Pose currentActualPose,
                              Pose currentSequencePose)

Compare AX12Register.AX12_PRESENT_POSITION of the current actual pose to the current sequence pose and return true iff their L-infinity norm (maximum element abs difference) is less than epsilon.


epsilonEquals

protected boolean epsilonEquals(int p,
                                int q)

Check if the absolute difference between p and q is less than epsilon.