JSci.instruments.pi
Class Mercury

java.lang.Object
  extended by JSci.instruments.PositionControlAdapter
      extended by JSci.instruments.pi.Mercury
All Implemented Interfaces:
Control, PositionControl

public abstract class Mercury
extends PositionControlAdapter

A mechanical device attached to a Mercury PI board.
Attention! The Mercury board forgets the position of the axes when it is reset or is turned off. Do not turn off the Mercury while the motor is moving!
There is a lot of final and protected methods, because this should be not be simply sub-classed by motor-specific classes, but it should be included in them.


Field Summary
protected static java.lang.String ACTIVITY_ACT_NEG_LIMIT
           
protected static java.lang.String ACTIVITY_ACT_POS_LIMIT
           
protected static java.lang.String ACTIVITY_AXIS_SETTLED
           
protected static java.lang.String ACTIVITY_IN_MOTION
           
protected static java.lang.String ACTIVITY_MAX_VELOCITY
           
protected static java.lang.String ACTIVITY_MOTOR_STATUS
           
protected static java.lang.String ACTIVITY_PHASING_INITD
           
protected static java.lang.String ACTIVITY_POSITION_CAPTURE
           
protected static java.lang.String ACTIVITY_PROFILE_MODE_0
           
protected static java.lang.String ACTIVITY_PROFILE_MODE_1
           
protected static java.lang.String ACTIVITY_PROFILE_MODE_2
           
protected static java.lang.String ACTIVITY_RESERVED
           
protected static java.lang.String ACTIVITY_TRACKING
           
static java.lang.String C136
          The C-136.10 motor
static java.lang.String C150PD
          The C-150.PD motor
protected static java.lang.String EVENT_BREAKPOINT1
           
protected static java.lang.String EVENT_BREAKPOINT2
           
protected static java.lang.String EVENT_CAPTURE_RECEIVED
           
protected static java.lang.String EVENT_COMMUNICATION_ERR
           
protected static java.lang.String EVENT_INSTRUCTION_ERR
           
protected static java.lang.String EVENT_MOTION_COMPLETE
           
protected static java.lang.String EVENT_MOTION_ERROR
           
protected static java.lang.String EVENT_NEG_LIMIT
           
protected static java.lang.String EVENT_POS_LIMIT
           
protected static java.lang.String EVENT_WRAP_AROUND
           
static java.lang.String M126PD
          The M-126.PD motor
static java.lang.String RAW
          A generic motor driven by Mercury
(package private)  javax.swing.JFrame setLimitsDialog
           
protected static java.lang.String SIGNAL_AXIS_IN
           
protected static java.lang.String SIGNAL_AXIS_OUT
           
protected static java.lang.String SIGNAL_ENCODER_A
           
protected static java.lang.String SIGNAL_ENCODER_B
           
protected static java.lang.String SIGNAL_ENCODER_HOME
           
protected static java.lang.String SIGNAL_ENCODER_INDEX
           
protected static java.lang.String SIGNAL_HALL_A
           
protected static java.lang.String SIGNAL_HALL_B
           
protected static java.lang.String SIGNAL_HALL_C
           
protected static java.lang.String SIGNAL_MOTOR_OUTPUT
           
protected static java.lang.String SIGNAL_NEG_LIMIT
           
protected static java.lang.String SIGNAL_POS_LIMIT
           
protected static java.lang.String SIGNAL_STEP_OUTPUT
           
 
Fields inherited from class JSci.instruments.PositionControlAdapter
listenerList
 
Constructor Summary
protected Mercury(int p, java.io.DataInput rfi, java.io.DataOutput rfo, int n)
          Remember this class is abstract!
 
Method Summary
protected  void clearErrors()
          Clear errors
protected  javax.swing.JPanel createButtonControlPanel()
          Create a JPanel with buttons for controlling the motor.
ATTENZIONE! NON E' COMPLETO!!!
static Mercury createMotorDevice(java.lang.String t, int p, java.io.DataInput rfi, java.io.DataOutput rfo, int n, double gf)
          Call this to build a driver for a given motor, instead of calling the constructor.
static Mercury createMotorDevice(java.lang.String t, int p, int n)
          Call this to build a driver for a given motor, instead of calling the constructor.
static Mercury createMotorDevice(java.lang.String t, int p, int n, double gf)
          Call this to build a driver for a given motor, instead of calling the constructor.
protected  javax.swing.JPanel createPositionPanel(boolean monitor, boolean vertical, boolean inverted)
          Create a JPanel with the controls of the position
protected  javax.swing.JPanel createVelocityPanel(boolean monitor)
          Create a JPanel with the controls of the velocity
 double doGetPosition()
           
 double doGetPositionError()
           
protected  void findCenter()
          move to the position between the two limit switches.
protected  java.util.Hashtable getActivityStatus()
          get the status of activity.
 double getActualPosition()
          get the actual position while the axis is moving.
 double getActualVelocity()
          get the actual velocity while moving.
protected  boolean getBrake()
          check if the brake is on or off.
abstract  java.awt.Component getControlComponent()
          The motor can be controlled by a visual component, with buttons, sliders and so on.
protected  java.util.Hashtable getEventStatus()
          get the status of event.
 double getMajorStep()
          get the major step suggested for changing the position
 double getMaximum()
          get the maximum value of position
 double getMaxVelocity()
          get the maximum value of velocity
 double getMinimum()
          get the minimum value of position
 double getMinorStep()
          get the minor step suggested for changing the position
protected  boolean getMotorOn()
          check if the motor is on or off.
 double getPosition()
          get the position.
 double getPositionError()
          get the error on the actual position.
protected  java.util.Hashtable getSignalStatus()
          get the status of signal.
 java.lang.String getUnit()
          get the unit in which the position is expressed
 double getVelocity()
          get the velocity that should be reached when moving.
 double getVelocityStep()
          get the step suggested for changing the velocity
 java.lang.String getVelocityUnit()
          get the unit in which the velocity is expressed
static void main(java.lang.String[] args)
          Useful controls for the Mercury board.
protected  void setBrake(boolean b)
          switch the brake on or off.
 void setLimits()
          runs a graphical configuration of the limits.
protected  void setLimitSwitches(boolean b)
          set the limit switch polarity.
 void setMaximum(double m)
          set the maximum value of position.
 void setMinimum(double m)
          set the minimum value of position.
protected  void setMotorOn(boolean b)
          switch the motor on or off.
 void setPosition(double p)
          move the device to the given position.
 void setVelocity(double v)
          set the velocity the device will reach when moving.
 void sleep()
          sleep until the axis has reached its position
 java.lang.String toString()
          Report port number, device number and version
 
Methods inherited from class JSci.instruments.PositionControlAdapter
addChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EVENT_MOTION_COMPLETE

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

EVENT_WRAP_AROUND

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

EVENT_BREAKPOINT1

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

EVENT_CAPTURE_RECEIVED

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

EVENT_MOTION_ERROR

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

EVENT_POS_LIMIT

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

EVENT_NEG_LIMIT

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

EVENT_INSTRUCTION_ERR

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

EVENT_COMMUNICATION_ERR

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

EVENT_BREAKPOINT2

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

SIGNAL_ENCODER_A

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

SIGNAL_ENCODER_B

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

SIGNAL_ENCODER_INDEX

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

SIGNAL_ENCODER_HOME

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

SIGNAL_POS_LIMIT

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

SIGNAL_NEG_LIMIT

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

SIGNAL_AXIS_IN

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

SIGNAL_HALL_A

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

SIGNAL_HALL_B

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

SIGNAL_HALL_C

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

SIGNAL_AXIS_OUT

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

SIGNAL_STEP_OUTPUT

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

SIGNAL_MOTOR_OUTPUT

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

ACTIVITY_PHASING_INITD

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

ACTIVITY_MAX_VELOCITY

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

ACTIVITY_TRACKING

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

ACTIVITY_PROFILE_MODE_0

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

ACTIVITY_PROFILE_MODE_1

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

ACTIVITY_PROFILE_MODE_2

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

ACTIVITY_RESERVED

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

ACTIVITY_AXIS_SETTLED

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

ACTIVITY_MOTOR_STATUS

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

ACTIVITY_POSITION_CAPTURE

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

ACTIVITY_IN_MOTION

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

ACTIVITY_ACT_POS_LIMIT

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

ACTIVITY_ACT_NEG_LIMIT

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

C150PD

public static final java.lang.String C150PD
The C-150.PD motor

See Also:
Constant Field Values

C136

public static final java.lang.String C136
The C-136.10 motor

See Also:
Constant Field Values

M126PD

public static final java.lang.String M126PD
The M-126.PD motor

See Also:
Constant Field Values

RAW

public static final java.lang.String RAW
A generic motor driven by Mercury

See Also:
Constant Field Values

setLimitsDialog

javax.swing.JFrame setLimitsDialog
Constructor Detail

Mercury

protected Mercury(int p,
                  java.io.DataInput rfi,
                  java.io.DataOutput rfo,
                  int n)
Remember this class is abstract!

Parameters:
p - the ttyS port number at which the Mercury is attached
rfi - the input file connected to the port; something like new RandomAccessFile("/dev/ttyS0","rw")
rfo - the output file connected to the port; something like new RandomAccessFile("/dev/ttyS0","rw")
n - the number of the axis
Method Detail

setLimitSwitches

protected final void setLimitSwitches(boolean b)
set the limit switch polarity.

Parameters:
b - the switch signals are high when out-of-limit?

findCenter

protected void findCenter()
move to the position between the two limit switches.


setPosition

public void setPosition(double p)
move the device to the given position. Checking the limits must be done (if necessary) by the extending class (note this class is abstract!)

Specified by:
setPosition in interface PositionControl
Specified by:
setPosition in class PositionControlAdapter
Parameters:
p - the position that we want to reach, in counts. It is rounded to its nearest integer position

getPosition

public double getPosition()
get the position.

Specified by:
getPosition in interface PositionControl
Specified by:
getPosition in class PositionControlAdapter
Returns:
the position in counts. It is alwais an integer value

doGetPosition

public double doGetPosition()

getActualPosition

public double getActualPosition()
get the actual position while the axis is moving.

Specified by:
getActualPosition in interface PositionControl
Specified by:
getActualPosition in class PositionControlAdapter
Returns:
the position in counts. It is alwais an integer value

getMinimum

public double getMinimum()
get the minimum value of position

Specified by:
getMinimum in interface PositionControl
Specified by:
getMinimum in class PositionControlAdapter
Returns:
the minimum position

getMaximum

public double getMaximum()
get the maximum value of position

Specified by:
getMaximum in interface PositionControl
Specified by:
getMaximum in class PositionControlAdapter
Returns:
the maximum position

setMinimum

public void setMinimum(double m)
set the minimum value of position. Only root can do this.

Parameters:
m - the minimum position

setMaximum

public void setMaximum(double m)
set the maximum value of position. Only root can do this.

Parameters:
m - the maximum position

getUnit

public java.lang.String getUnit()
get the unit in which the position is expressed

Specified by:
getUnit in interface PositionControl
Specified by:
getUnit in class PositionControlAdapter
Returns:
the units

getMinorStep

public double getMinorStep()
get the minor step suggested for changing the position

Returns:
the suggested minor step

getMajorStep

public double getMajorStep()
get the major step suggested for changing the position

Returns:
the suggested major step

getPositionError

public double getPositionError()
get the error on the actual position.

Returns:
the error on the position in counts. It is rounded to its nearest integer position.

doGetPositionError

public double doGetPositionError()

setVelocity

public void setVelocity(double v)
set the velocity the device will reach when moving. Checking the limits must be done (if necessary) by the extending class (note this class is abstract!)

Parameters:
v - the velocity in counts per cycle. It is rounded to its nearest integer position.

getVelocity

public double getVelocity()
get the velocity that should be reached when moving.

Returns:
the velocity in counts per cycle. It is rounded to its nearest integer position.

getActualVelocity

public double getActualVelocity()
get the actual velocity while moving.

Returns:
the velocity in counts per cycle. It is rounded to its nearest integer position.

getMaxVelocity

public double getMaxVelocity()
get the maximum value of velocity

Returns:
the maximum velocity

getVelocityStep

public double getVelocityStep()
get the step suggested for changing the velocity

Returns:
the suggested step

getVelocityUnit

public java.lang.String getVelocityUnit()
get the unit in which the velocity is expressed

Returns:
the units

clearErrors

protected void clearErrors()
Clear errors


setMotorOn

protected void setMotorOn(boolean b)
switch the motor on or off.

Parameters:
b - do you want to switch the motor on?

getMotorOn

protected boolean getMotorOn()
check if the motor is on or off.

Returns:
the motor is on?

setBrake

protected void setBrake(boolean b)
switch the brake on or off.

Parameters:
b - do you want to switch the brake on?

getBrake

protected boolean getBrake()
check if the brake is on or off.

Returns:
the brake is on?

getEventStatus

protected java.util.Hashtable getEventStatus()
get the status of event. CURRENTLY NOT IMPLEMENTED.

Returns:
the properties of the event.

getSignalStatus

protected java.util.Hashtable getSignalStatus()
get the status of signal. CURRENTLY NOT IMPLEMENTED.

Returns:
the properties of the signal.

getActivityStatus

protected java.util.Hashtable getActivityStatus()
get the status of activity. CURRENTLY NOT IMPLEMENTED.

Returns:
the property of activity

sleep

public void sleep()
sleep until the axis has reached its position

Specified by:
sleep in interface PositionControl
Specified by:
sleep in class PositionControlAdapter

createPositionPanel

protected javax.swing.JPanel createPositionPanel(boolean monitor,
                                                 boolean vertical,
                                                 boolean inverted)
Create a JPanel with the controls of the position

Parameters:
monitor - monitor the actual position every 0.1 s.
vertical - the direction of motion is vertical
inverted - invert the direction of motion

createVelocityPanel

protected javax.swing.JPanel createVelocityPanel(boolean monitor)
Create a JPanel with the controls of the velocity

Parameters:
monitor - monitor the actual velocity every 0.1 s.

createButtonControlPanel

protected javax.swing.JPanel createButtonControlPanel()
Create a JPanel with buttons for controlling the motor.
ATTENZIONE! NON E' COMPLETO!!!


getControlComponent

public abstract java.awt.Component getControlComponent()
The motor can be controlled by a visual component, with buttons, sliders and so on. Call this to get the Component (actually, a JPanel). This component displays also many informations.

Specified by:
getControlComponent in interface Control
Specified by:
getControlComponent in interface PositionControl
Specified by:
getControlComponent in class PositionControlAdapter
Returns:
the Component with the controls for the position

createMotorDevice

public static Mercury createMotorDevice(java.lang.String t,
                                        int p,
                                        java.io.DataInput rfi,
                                        java.io.DataOutput rfo,
                                        int n,
                                        double gf)
Call this to build a driver for a given motor, instead of calling the constructor.

Parameters:
t - the type of motor connected to the board (see RAW,C150PD, C136, M126PD).
p - the number of the ttyS port
rfi - the input file connected to the port
rfo - the output file connected to the port
n - the number of the axis
gf - if there's a mechanical device such as a gear, gf is the ratio final motion/motor motion. gf=1 for RAW.

createMotorDevice

public static Mercury createMotorDevice(java.lang.String t,
                                        int p,
                                        int n,
                                        double gf)
Call this to build a driver for a given motor, instead of calling the constructor.

Parameters:
t - the type of motor connected to the board (see RAW,C150PD, C136, M126PD).
p - the number of the ttyS port
n - the number of the axis
gf - if there's a mechanical device such as a gear, gf is the ratio final motion/motor motion. gf=1 for RAW.

createMotorDevice

public static Mercury createMotorDevice(java.lang.String t,
                                        int p,
                                        int n)
Call this to build a driver for a given motor, instead of calling the constructor.

Parameters:
t - the type of motor connected to the board (see RAW,C150PD, C136, M126PD).
p - the number of the ttyS port
n - the number of the axis

toString

public java.lang.String toString()
Report port number, device number and version

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
Useful controls for the Mercury board. Parameters can be supplied.
Syntax:
java it.unimi.pi.Mercury {options} {commands}
The options can be:
-h : print the help
-m type : set the motor type ("Raw" by default)
-p ttyS_number : set the ttyS port number (0 by default)
-n axis_number : set the axis number (0 by default)
-g gear_factor : set the gear factor (1 by default)
The commands can be:
setMinimum position : set the minimum of the position (only root can do this)
setMaximum position : set the maximum of the position (only root can do this)
setPosition position : move the motor to the given position
setLimits : graphical interface for setting limits of the given motor (only root can do this)
monitor : open a window with the control component for the desired motor.
motors : print a list of known motor types. "Raw" is a generic motor, with the units used by the board.


setLimits

public void setLimits()
runs a graphical configuration of the limits. Only root can do this. This operation allows the movement of the device outside the current limits; this could damage the device.