jAER project on SourceForge

ch.unizh.ini.jaer.projects.tobi.goalie
Class ServoArm

java.lang.Object
  extended by net.sf.jaer.eventprocessing.EventFilter
      extended by net.sf.jaer.eventprocessing.EventFilter2D
          extended by ch.unizh.ini.jaer.projects.tobi.goalie.ServoArm
All Implemented Interfaces:
de.thesycon.usbio.PnPNotifyInterface, java.util.Observer, FrameAnnotater

public class ServoArm
extends EventFilter2D
implements java.util.Observer, FrameAnnotater, de.thesycon.usbio.PnPNotifyInterface

Controls the servo arm in Goalie to decouple the motor actions from the sensory processing and manages self-calibration of the arm. This arm can also be controlled directly with visual feedback control using the tracked arm position. In this mode, the servo command is formed from an error signal that is the difference between the actual position and the desired position. The actual arm position comes from the cluster tracker that tracks the arm, while the desired position is the pixel position that the arm should go to.

Author:
malang, tobi

Field Summary
 java.lang.Object learningLock
           
 
Fields inherited from class net.sf.jaer.eventprocessing.EventFilter2D
enclosedFilter, out
 
Fields inherited from class net.sf.jaer.eventprocessing.EventFilter
annotationEnabled, chip, enclosedFilterChain, filterEnabled, log, perf, propertyTooltipMap, support
 
Constructor Summary
ServoArm(AEChip chip)
          Creates a new instance of ServoArm
 
Method Summary
 void annotate(float[][][] frame)
          annotate the RGB frame somehow by color pixels in the rendered pixel frame data.
 void annotate(javax.media.opengl.GLAutoDrawable drawable)
          Each annotator enters annotate with graphics context current, in coordinates with pixel 0,0 in LL corner (note opposite from Java2D) and pixel spacing 1 unit after the scaling transform (which is already active).
 void annotate(java.awt.Graphics2D g)
          each annotator is called by the relevant class (e.g.
 void doShowSamples()
           
 EventPacket<?> filterPacket(EventPacket<?> in)
          Subclasses implement this method to define custom processing.
protected  void finalize()
           
 float getAcceptableAccuracyPixels()
           
 int getActualPosition()
          A tracker tracks the arm; this method returns the arm position.
 RectangularClusterTracker getArmTracker()
           
 int getDesiredPosition()
          The desired position of the arm
 java.lang.Object getFilterState()
          should return the filter state in some useful form
 float getLastServoSetting()
          Returns the last servo command value, default 0.5f if nothing has been commanded yet.
 float getLearningLeftSamplingBoundary()
           
 float getLearningRightSamplingBoundary()
           
 float getOutputFromPosition(int position)
          Applies the learned model to return the learned motor value from the desired pixel position of the arm.
 ServoInterface getServoInterface()
           
 float getServoLimitLeft()
           
 float getServoLimitRight()
           
 float getServoPulseFreqHz()
           
 float getVisualFeedbackPIDControllerTauMs()
           
 float getVisualFeedbackProportionalGain()
           
 void initFilter()
          this should allocate and initialize memory: it may be called when the chip e.g.
 boolean isLearningFailed()
           
 boolean isRealtimeLogging()
           
 boolean isVisualFeedbackControlEnabled()
           
 void onAdd()
           
 void onRemove()
           
 void relax()
           
 void resetFilter()
          should reset the filter to initial state
 void setAcceptableAccuracyPixels(float acceptableAccuracyPixels)
           
 void setFilterEnabled(boolean yes)
          Resets the filter
 void setLearningFailed(boolean learningFailed)
           
 void setLearningLeftSamplingBoundary(float value)
           
 void setLearningRightSamplingBoundary(float value)
           
 void setPosition(int position)
          Sets the arm position in pixel space.
 void setRealtimeLogging(boolean v)
           
 void setServoInterface(ServoInterface servo)
           
 void setServoLimitLeft(float servoLimitLeft)
           
 void setServoLimitRight(float servoLimitRight)
           
 void setServoPulseFreqHz(float servoPulseFreqHz)
           
 void setVisualFeedbackControlEnabled(boolean visualFeedbackControlEnabled)
           
 void setVisualFeedbackPIDControllerTauMs(float visualFeedbackPIDControllerTauMs)
           
 void setVisualFeedbackProportionalGain(float visualFeedbackProportionalGain)
           
 void startLearning()
           
 void startLogging()
           
 void stopLearning()
           
 void stopLogging()
           
 void update(java.util.Observable o, java.lang.Object arg)
           
 
Methods inherited from class net.sf.jaer.eventprocessing.EventFilter2D
checkOutputPacketEventType, checkOutputPacketEventType, getEnclosedFilter, resetOut, setEnclosedFilter
 
Methods inherited from class net.sf.jaer.eventprocessing.EventFilter
getChip, getDescription, getEnclosedFilterChain, getEnclosingFilter, getPrefs, getPropertyChangeSupport, getPropertyTooltip, isAnnotationEnabled, isEnclosed, isFilterEnabled, prefsEnabledKey, setAnnotationEnabled, setChip, setEnclosed, setEnclosedFilter, setEnclosedFilterChain, setEnclosingFilter, setPreferredEnabledState, setPrefs, setPropertyTooltip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.jaer.graphics.FrameAnnotater
isAnnotationEnabled, setAnnotationEnabled
 

Field Detail

learningLock

public java.lang.Object learningLock
Constructor Detail

ServoArm

public ServoArm(AEChip chip)
Creates a new instance of ServoArm

Method Detail

isVisualFeedbackControlEnabled

public boolean isVisualFeedbackControlEnabled()

setVisualFeedbackControlEnabled

public void setVisualFeedbackControlEnabled(boolean visualFeedbackControlEnabled)

getVisualFeedbackProportionalGain

public float getVisualFeedbackProportionalGain()

setVisualFeedbackProportionalGain

public void setVisualFeedbackProportionalGain(float visualFeedbackProportionalGain)

getVisualFeedbackPIDControllerTauMs

public float getVisualFeedbackPIDControllerTauMs()

setVisualFeedbackPIDControllerTauMs

public void setVisualFeedbackPIDControllerTauMs(float visualFeedbackPIDControllerTauMs)

getServoInterface

public ServoInterface getServoInterface()

setServoInterface

public void setServoInterface(ServoInterface servo)

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

filterPacket

public EventPacket<?> filterPacket(EventPacket<?> in)
Description copied from class: EventFilter2D
Subclasses implement this method to define custom processing.

Specified by:
filterPacket in class EventFilter2D
Parameters:
in - the input packet
Returns:
the output packet

getFilterState

public java.lang.Object getFilterState()
Description copied from class: EventFilter
should return the filter state in some useful form

Specified by:
getFilterState in class EventFilter

resetFilter

public void resetFilter()
Description copied from class: EventFilter
should reset the filter to initial state

Specified by:
resetFilter in class EventFilter

initFilter

public void initFilter()
Description copied from class: EventFilter
this should allocate and initialize memory: it may be called when the chip e.g. size parameters are changed after creation of the filter

Specified by:
initFilter in class EventFilter

setFilterEnabled

public void setFilterEnabled(boolean yes)
Description copied from class: EventFilter2D
Resets the filter

Overrides:
setFilterEnabled in class EventFilter2D
Parameters:
yes - true to reset
See Also:
EventFilter.setPreferredEnabledState()

annotate

public void annotate(float[][][] frame)
Description copied from interface: FrameAnnotater
annotate the RGB frame somehow by color pixels in the rendered pixel frame data.

Specified by:
annotate in interface FrameAnnotater
Parameters:
frame - the RGB pixel information. First dimension is Y, second is X, third is RGB

annotate

public void annotate(java.awt.Graphics2D g)
Description copied from interface: FrameAnnotater
each annotator is called by the relevant class (e.g. EyeTracker) and enters annotate with graphics context current, in coordinates with pixel 0,0 in UL corner and pixel spacing 1 unit before scaling transform (which is already active).

Specified by:
annotate in interface FrameAnnotater
Parameters:
g - the Graphics2D context

annotate

public void annotate(javax.media.opengl.GLAutoDrawable drawable)
Description copied from interface: FrameAnnotater
Each annotator enters annotate with graphics context current, in coordinates with pixel 0,0 in LL corner (note opposite from Java2D) and pixel spacing 1 unit after the scaling transform (which is already active). The FrameAnnotater then can use JOGL calls to render to the screen by getting the GL context, e.g. the following code, used in the context of an AEChip object, draws a golden lines from LL to UR of the pixel array.
        GL gl = drawable.getGL();
        gl.glBegin(GL.GL_LINES);
        gl.glColor3f(.5f, .5f, 0);
        gl.glVertex2f(0, 0);
        gl.glVertex2f(getSizeX() - 1, getSizeY() - 1);
        gl.glEnd();
 

Specified by:
annotate in interface FrameAnnotater
Parameters:
drawable - the OpenGL drawable components, e.g., GLCanvas

getActualPosition

public int getActualPosition()
A tracker tracks the arm; this method returns the arm position.

Returns:
arm x position in image space, or the last measurement if no arm is tracked

getDesiredPosition

public int getDesiredPosition()
The desired position of the arm


setPosition

public void setPosition(int position)
Sets the arm position in pixel space. Also immediately aborts learning and sets the state to be ServoArmState.active.

Parameters:
position - the position of the arm in pixels in image space in the x coordinate (along the bottom of the scene in the arm tracking region).

relax

public void relax()

getOutputFromPosition

public float getOutputFromPosition(int position)
Applies the learned model to return the learned motor value from the desired pixel position of the arm.

Parameters:
position - the diseired postion in pixels [0,chip.getSizeX()-1]
Returns:
the learned motor value to move to this postion in servo units [0,1]

stopLearning

public void stopLearning()

startLearning

public void startLearning()

startLogging

public void startLogging()

stopLogging

public void stopLogging()

getLearningLeftSamplingBoundary

public float getLearningLeftSamplingBoundary()

setLearningLeftSamplingBoundary

public void setLearningLeftSamplingBoundary(float value)

getLearningRightSamplingBoundary

public float getLearningRightSamplingBoundary()

setLearningRightSamplingBoundary

public void setLearningRightSamplingBoundary(float value)

getServoLimitLeft

public float getServoLimitLeft()

setServoLimitLeft

public void setServoLimitLeft(float servoLimitLeft)

getServoLimitRight

public float getServoLimitRight()

setServoLimitRight

public void setServoLimitRight(float servoLimitRight)

isRealtimeLogging

public boolean isRealtimeLogging()

setRealtimeLogging

public void setRealtimeLogging(boolean v)

onAdd

public void onAdd()
Specified by:
onAdd in interface de.thesycon.usbio.PnPNotifyInterface

onRemove

public void onRemove()
Specified by:
onRemove in interface de.thesycon.usbio.PnPNotifyInterface

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer

doShowSamples

public void doShowSamples()

getServoPulseFreqHz

public float getServoPulseFreqHz()

setServoPulseFreqHz

public void setServoPulseFreqHz(float servoPulseFreqHz)

getAcceptableAccuracyPixels

public float getAcceptableAccuracyPixels()

setAcceptableAccuracyPixels

public void setAcceptableAccuracyPixels(float acceptableAccuracyPixels)

getLastServoSetting

public float getLastServoSetting()
Returns the last servo command value, default 0.5f if nothing has been commanded yet.


getArmTracker

public RectangularClusterTracker getArmTracker()

isLearningFailed

public boolean isLearningFailed()

setLearningFailed

public void setLearningFailed(boolean learningFailed)

jAER project on SourceForge