org.mbari.siam.foce.devices.motorControl
Class MotorControl

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by org.mbari.siam.core.DeviceService
                  extended by org.mbari.siam.core.BaseInstrumentService
                      extended by org.mbari.siam.core.PolledInstrumentService
                          extended by org.mbari.siam.foce.devices.motorControl.MotorControl
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, ScheduleOwner, Device, DeviceServiceIF, Instrument, InstrumentDataListener

public class MotorControl
extends PolledInstrumentService
implements Instrument, InstrumentDataListener

MotorControl implements a PID loop for the FOCE thruster motors, using a set of AllMotion EZServo EZSV23 Motor Servo Boards, with communication via an RS-485 serial port.

See Also:
Serialized Form

Field Summary
protected  Velocity _adcpVelocity
           
protected  byte[] _commBuf
           
protected  boolean _debug
           
protected  int[] _errors
           
protected  PrintfFormat _format
           
protected  int[] _good
           
protected  Velocity _instantaneousVelocity
           
protected  int[] _lastPosition
           
protected  int[] _lastVelocityCmd
           
protected static org.apache.log4j.Logger _log4j
          Log4j logger
protected  byte[] _nullBytes
           
protected  byte[] _sampleTerm
           
protected  boolean[] _stalled
           
protected  int[] _totErrors
           
protected  Velocity _waterVelocity
           
protected  Velocity _waterVelocityAccum
           
protected  int _waterVelocitySamples
           
protected static java.lang.String CANCEL_CMD
           
protected static int ERR_CLEAR
           
protected static java.lang.String EXEC_INIT_CMD
           
protected static java.lang.String FIRMWARE_CMD
           
protected static java.lang.String GET_POSITION_CMD
           
protected static java.lang.String INIT_STRING
           
protected static int MAX_MOTOR_RPM
           
protected static int MAX_SERVOS
           
protected static java.lang.String NEG_DIRECTION_CMD
           
protected static java.lang.String POS_DIRECTION_CMD
           
protected static java.lang.String RESET_CMD
           
protected static java.lang.String STATUS_CMD
           
protected static java.lang.String VELOCITY_CMD
           
 
Fields inherited from class org.mbari.siam.core.BaseInstrumentService
_defaultSamplerTask, _defaultSampleScheduleName, _errorCache, _instrumentAttributes, _lastPacket, _lastSensorDataPacket, _maxSampleBytes, _messagePacket, _nPowerRequests, _nWakeRequests, _packetLog, _recordType, _running, _samplerWakeupTime, _scheduleKey, _schedules, _sensorDataPacket, _turbinator, MAX_BASE_RECORDTYPE, RECORDTYPE_DEFAULT, RECORDTYPE_METADATA, RECORDTYPE_UNDEFINED
 
Fields inherited from class org.mbari.siam.core.DeviceService
_fromDevice, _instrumentPort, _nodeProperties, _parentNode, _regEntry, _sandBox, _serviceCachePath, _serviceName, _servicePropertiesPath, _serviceXMLPath, _toDevice, CACHED_PROPERTIES_FILENAME, PROPERTIES_FILENAME, XML_FILENAME
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface org.mbari.siam.distributed.Device
ERROR, INITIAL, INSTRUMENT_STATE, MDATA_ALL, OK, SAFE, SAMPLING, SERVICE_ATTRIBUTES, SERVICE_CACHE, SERVICE_PROPERTIES, SERVICE_XML, SHUTDOWN, SLEEPING, SUSPEND, UNKNOWN
 
Constructor Summary
MotorControl()
           
 
Method Summary
protected  void clearErrors()
           
protected  ScheduleSpecifier createDefaultSampleSchedule()
          Return specifier for default sampling schedule.
 void dataCallback(DevicePacket sensorData, PacketParser.Field[] fields)
          dataCallback from the ADV device
protected  int findResponse(int nbytes)
          Look for "/0" in _commBuf.
protected  byte[] getInstrumentStateMetadata()
          Return metadata.
protected  int getMotorPosition(int servo)
          Get Motor position for one servo
 SerialPortParameters getSerialPortParameters()
          Return parameters to use on serial port.
protected  PowerPolicy initCommunicationPowerPolicy()
          Return initial value of communication power policy.
protected  int initCurrentLimit()
          Specify current limit.
protected  void initializeInstrument()
          Initialize the servos
protected  PowerPolicy initInstrumentPowerPolicy()
          Return initial value of instrument power policy.
protected  int initInstrumentStartDelay()
          Specify device startup delay (millisec)
protected  int initMaxSampleBytes()
          Specify maximum bytes in raw sample.
protected  byte[] initPromptString()
          Specify prompt string.
protected  byte[] initSampleTerminator()
          Specify sample terminator.
protected  void pidLoop()
          Run once through PID loop
protected  void printBuffer(byte[] buf, int nbytes)
           
protected  int readSample(byte[] sample)
          Run the loop, log the results
protected  void requestSample()
          Request a data sample
 void serviceRegisteredCallback(RegistryEntry entry)
          Callback for InstrumentDataListener interface, called when the ADV service is registered with the InstrumentRegistry
 void setClock()
          No internal clock.
protected  void setMotorDirection(int servo, boolean dir)
          Set Motor direction for one servo
protected  void setMotorVelocity(int servo, int velocity)
          Set motor velocity for one servo
protected  void setVelocity(Velocity velocity, PacketParser.Field[] fields)
           
 java.lang.String shutdownInstrument()
          Perform any instrument-specific shutdown actions and optionally return a human-readable message (e.g.
protected  int status(int servo)
          Get motor status
 int test()
          Self-test not implemented.
protected  int transact(int servo, java.lang.String cmd, boolean logIt)
          Perform one I/O transaction to a servo.
protected  boolean transactAll(java.lang.String cmd)
          Send a command to all servos
 
Methods inherited from class org.mbari.siam.core.PolledInstrumentService
acquire, doScheduledTask, setAttributes
 
Methods inherited from class org.mbari.siam.core.BaseInstrumentService
acquireSample, addDefaultPacketFilters, addSchedule, addSchedule, annotate, assertSamplingState, cacheProperties, callDataListeners, canSummarize, checkInputProperties, cleanupServiceState, clearDefaultPacketFilters, clearPropertiesCache, createPacketLog, createTask, createTurbinators, disableSummary, enableSummary, endDeviceAccess, getAllSchedules, getChildren, getCommunicationPowerPolicy, getCurrentLimit, getDefaultPacketFilters, getDefaultSampleSchedule, getDefaultSampleScheduleName, getDevicePacketParser, getFileBytes, getInstrumentPowerPolicy, getInstrumentServiceBlock, getInstrumentStartDelay, getLastSample, getMaxSampleBytes, getMaxSampleTries, getMetadata, getMetadata, getMetadataPayload, getPackets, getPackets, getParent, getParser, getPortDiagnostics, getPortDiagnosticsSummary, getPromptString, getProperties, getProperty, getSampleBuf, getSampleSchedule, getSampleTerminator, getSampleTimeout, getSchedule, getScheduleKey, getSchedules, getServicePropertiesBytes, initialize, initializeDriverDefaults, initializePooledResources, interruptDeviceAccess, logPacket, managePowerSleep, managePowerWake, nPowerRequests, postSample, powerOff, powerOffCallback, powerOn, powerOnCallback, prepareToRun, prepareToSample, printData, processSample, removeAllSchedules, removeSchedule, resetPortDiagnostics, resume, resumeSchedule, running, setClock, setCommunicationPowerPolicy, setCurrentLimit, setDefaultSampleScheduleName, setInstrumentPowerPolicy, setInstrumentServiceBlock, setInstrumentStartDelay, setMaxSampleBytes, setMaxSampleTries, setPromptString, setProperty, setRecordType, setSampleTerminator, setSampleTimeout, shutdown, sleepingUntil, snooze, startDeviceAccess, summaryEnabled, suspend, suspendSchedule, sync, syncSchedule, validateSample
 
Methods inherited from class org.mbari.siam.core.DeviceService
addDataListener, advertiseService, createRegistryEntry, getAttributes, getCommPortName, getFrameworkVersion, getId, getInstrumentPort, getLocation, getName, getRemoteSerialPort, getRemoteSerialPort, getSamplingCount, getSamplingErrorCount, getSamplingRetryCount, getStatus, host, incRetryCount, initializePropertyDefaults, registryEntry, registryName, removeDataListener, setInstrumentPort, setNodeProperties, setParent, setSerialPort, setStatusError, setStatusInitial, setStatusOk, setStatusSafe, setStatusSampling, setStatusShutdown, setStatusSuspend
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mbari.siam.distributed.Instrument
acquireSample, addDefaultPacketFilters, annotate, cacheProperties, clearDefaultPacketFilters, clearPropertiesCache, disableSummary, enableSummary, getDefaultPacketFilters, getLastSample, getPackets, getPackets, getParser, getPortDiagnostics, getPortDiagnosticsSummary, getProperties, getProperty, getSampleSchedule, getSchedules, resetPortDiagnostics, setClock, setProperty, summaryEnabled
 
Methods inherited from interface org.mbari.siam.distributed.Device
getChildren, getCommPortName, getFrameworkVersion, getId, getLocation, getMetadata, getName, getParent, getSamplingCount, getSamplingErrorCount, getSamplingRetryCount, getStatus, host, powerOff, powerOn, prepareToRun, resume, shutdown, suspend
 
Methods inherited from interface org.mbari.siam.distributed.DeviceServiceIF
getName
 
Methods inherited from interface org.mbari.siam.core.ScheduleOwner
addSchedule, getAllSchedules, getScheduleKey, removeAllSchedules, removeSchedule, resumeSchedule, sleepingUntil, suspendSchedule, syncSchedule
 

Field Detail

_log4j

protected static org.apache.log4j.Logger _log4j
Log4j logger


MAX_SERVOS

protected static final int MAX_SERVOS
See Also:
Constant Field Values

MAX_MOTOR_RPM

protected static final int MAX_MOTOR_RPM
See Also:
Constant Field Values

INIT_STRING

protected static final java.lang.String INIT_STRING
See Also:
Constant Field Values

EXEC_INIT_CMD

protected static final java.lang.String EXEC_INIT_CMD
See Also:
Constant Field Values

RESET_CMD

protected static final java.lang.String RESET_CMD
See Also:
Constant Field Values

CANCEL_CMD

protected static final java.lang.String CANCEL_CMD
See Also:
Constant Field Values

STATUS_CMD

protected static final java.lang.String STATUS_CMD
See Also:
Constant Field Values

VELOCITY_CMD

protected static final java.lang.String VELOCITY_CMD
See Also:
Constant Field Values

GET_POSITION_CMD

protected static final java.lang.String GET_POSITION_CMD
See Also:
Constant Field Values

POS_DIRECTION_CMD

protected static final java.lang.String POS_DIRECTION_CMD
See Also:
Constant Field Values

NEG_DIRECTION_CMD

protected static final java.lang.String NEG_DIRECTION_CMD
See Also:
Constant Field Values

FIRMWARE_CMD

protected static final java.lang.String FIRMWARE_CMD
See Also:
Constant Field Values

ERR_CLEAR

protected static final int ERR_CLEAR
See Also:
Constant Field Values

_lastVelocityCmd

protected int[] _lastVelocityCmd

_lastPosition

protected int[] _lastPosition

_errors

protected int[] _errors

_totErrors

protected int[] _totErrors

_good

protected int[] _good

_stalled

protected boolean[] _stalled

_instantaneousVelocity

protected Velocity _instantaneousVelocity

_waterVelocity

protected Velocity _waterVelocity

_waterVelocityAccum

protected Velocity _waterVelocityAccum

_adcpVelocity

protected Velocity _adcpVelocity

_waterVelocitySamples

protected int _waterVelocitySamples

_format

protected PrintfFormat _format

_nullBytes

protected byte[] _nullBytes

_debug

protected boolean _debug

_sampleTerm

protected byte[] _sampleTerm

_commBuf

protected byte[] _commBuf
Constructor Detail

MotorControl

public MotorControl()
             throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException
Method Detail

initInstrumentStartDelay

protected int initInstrumentStartDelay()
Specify device startup delay (millisec)

Specified by:
initInstrumentStartDelay in class BaseInstrumentService

initPromptString

protected byte[] initPromptString()
Specify prompt string.

Specified by:
initPromptString in class BaseInstrumentService

initSampleTerminator

protected byte[] initSampleTerminator()
Specify sample terminator.

Specified by:
initSampleTerminator in class BaseInstrumentService

initMaxSampleBytes

protected int initMaxSampleBytes()
Specify maximum bytes in raw sample.

Specified by:
initMaxSampleBytes in class BaseInstrumentService

initCurrentLimit

protected int initCurrentLimit()
Specify current limit.

Specified by:
initCurrentLimit in class BaseInstrumentService

initInstrumentPowerPolicy

protected PowerPolicy initInstrumentPowerPolicy()
Return initial value of instrument power policy.

Specified by:
initInstrumentPowerPolicy in class BaseInstrumentService

initCommunicationPowerPolicy

protected PowerPolicy initCommunicationPowerPolicy()
Return initial value of communication power policy.

Specified by:
initCommunicationPowerPolicy in class BaseInstrumentService

requestSample

protected void requestSample()
                      throws java.lang.Exception
Request a data sample

Specified by:
requestSample in class PolledInstrumentService
Throws:
java.lang.Exception

initializeInstrument

protected void initializeInstrument()
                             throws InitializeException,
                                    java.lang.Exception
Initialize the servos

Overrides:
initializeInstrument in class BaseInstrumentService
Throws:
InitializeException
java.lang.Exception

serviceRegisteredCallback

public void serviceRegisteredCallback(RegistryEntry entry)
Callback for InstrumentDataListener interface, called when the ADV service is registered with the InstrumentRegistry

Specified by:
serviceRegisteredCallback in interface InstrumentDataListener

setVelocity

protected void setVelocity(Velocity velocity,
                           PacketParser.Field[] fields)
                    throws NoDataException
Throws:
NoDataException

dataCallback

public void dataCallback(DevicePacket sensorData,
                         PacketParser.Field[] fields)
dataCallback from the ADV device

Specified by:
dataCallback in interface InstrumentDataListener
Parameters:
sensorData - - SensorDataPacket that instrument logged
fields - - Result of passing sensorData to PacketParser.parseFields() if registered DeviceService is an instanceof BaseInstrumentService. Else null.

findResponse

protected int findResponse(int nbytes)
Look for "/0" in _commBuf. This indicates the start of the response to the command. Return index of next byte after the response, or -1 if not found. Note that response must contain at least one byte after "/0". This is the status byte.


transact

protected int transact(int servo,
                       java.lang.String cmd,
                       boolean logIt)
                throws java.io.IOException,
                       java.lang.IllegalArgumentException
Perform one I/O transaction to a servo. Return number of bytes in response.

Throws:
java.io.IOException
java.lang.IllegalArgumentException

transactAll

protected boolean transactAll(java.lang.String cmd)
Send a command to all servos


status

protected int status(int servo)
              throws java.io.IOException,
                     java.lang.IllegalArgumentException
Get motor status

Throws:
java.io.IOException
java.lang.IllegalArgumentException

setMotorDirection

protected void setMotorDirection(int servo,
                                 boolean dir)
                          throws java.io.IOException,
                                 java.lang.IllegalArgumentException
Set Motor direction for one servo

Parameters:
servo - - servo number (1-4)
dir - - direction, true for positive direction
Throws:
java.io.IOException
java.lang.IllegalArgumentException

setMotorVelocity

protected void setMotorVelocity(int servo,
                                int velocity)
                         throws java.io.IOException,
                                java.lang.IllegalArgumentException
Set motor velocity for one servo

Throws:
java.io.IOException
java.lang.IllegalArgumentException

getMotorPosition

protected int getMotorPosition(int servo)
                        throws java.io.IOException,
                               java.lang.IllegalArgumentException,
                               java.lang.NumberFormatException
Get Motor position for one servo

Parameters:
servo - - servo number (1-4)
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.NumberFormatException

pidLoop

protected void pidLoop()
Run once through PID loop


readSample

protected int readSample(byte[] sample)
Run the loop, log the results

Overrides:
readSample in class BaseInstrumentService
Parameters:
sample - output buffer

clearErrors

protected void clearErrors()

getInstrumentStateMetadata

protected byte[] getInstrumentStateMetadata()
Return metadata.

Overrides:
getInstrumentStateMetadata in class BaseInstrumentService

shutdownInstrument

public java.lang.String shutdownInstrument()
Description copied from class: BaseInstrumentService
Perform any instrument-specific shutdown actions and optionally return a human-readable message (e.g. noting caveats, status, etc); the returned message is purely for human operator.

Overrides:
shutdownInstrument in class BaseInstrumentService

printBuffer

protected void printBuffer(byte[] buf,
                           int nbytes)

setClock

public void setClock()
              throws NotSupportedException
No internal clock.

Specified by:
setClock in interface Instrument
Overrides:
setClock in class BaseInstrumentService
Throws:
NotSupportedException

test

public int test()
Self-test not implemented.

Specified by:
test in interface Device

createDefaultSampleSchedule

protected ScheduleSpecifier createDefaultSampleSchedule()
                                                 throws ScheduleParseException
Return specifier for default sampling schedule.

Specified by:
createDefaultSampleSchedule in class PolledInstrumentService
Throws:
ScheduleParseException

getSerialPortParameters

public SerialPortParameters getSerialPortParameters()
                                             throws gnu.io.UnsupportedCommOperationException
Return parameters to use on serial port.

Overrides:
getSerialPortParameters in class DeviceService
Throws:
gnu.io.UnsupportedCommOperationException


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.