ikayaki.squid
Class Handler

java.lang.Object
  extended by ikayaki.squid.Handler
All Implemented Interfaces:
SerialIOListener, EventListener

public class Handler
extends Object
implements SerialIOListener

Offers an interface for controlling the sample handler.

Author:
Aki Korpua, Esko Luontola

Field Summary
private  int ACCELERATION
          Value between 0 and 127 default 5.
private  SynchronousQueue<String> answerQueue
          Synchronous queue for waiting result message from handler
private  int AXIAL_AF_POSITION
          Axial AF demag position in steps, must be divisible by 10.
private  int BACKGROUND_POSITION
          Position in steps, must be divisible by 10.
private  int currentMotor
          Currently selected motor to send the commands to.
private  int currentPosition
          The position where the handler is currently, or where it is heading right now.
private  int currentRotation
          Angles are between 0 (0) and 2000 (360).
private  int currentVelocity
          Last set velocity.
private  int DECELERATION
          Value between 0 and 127 default 10.
private  int estimatedPositionEnd
           
private  int estimatedPositionStart
          Starting point at start of movement
private  long estimatedPositionStartTime
          Time in milliseconds when we started movement
private  int estimatedRotationEnd
           
private  int estimatedRotationStart
           
private  long estimatedRotationStartTime
           
private  int HANDLER_ROTATION
           
private  int MEASUREMENT_POSITION
          Position in steps, must be divisible by 10.
private  int MEASUREMENT_VELOCITY
          Speed in measurement, should be small.
private  int POLL_TIMEOUT
          timeout how long we wait answer from Squid-system, debugging to prevent lock-ups if communication fails.
private  int ROTATION_ACCELERATION
          Value between 0 and 127.
private  int ROTATION_DECELERATION
          Value between 0 and 127.
private  int ROTATION_VELOCITY
          Value between 50 and 8500, but should be small
private  int SAMPLE_LOAD_POSITION
          Value between 1 and 16,777,215.
protected  SerialIO serialIO
          COM port for communication.
private  int TRANSVERSE_YAF_POSITION
          AF demag position for transverse.
private  boolean waitingForMessage
          Only one at time can be waiting for answer, works like semaphore for commanding handler
private  int VELOCITY
          Value between 50 and 12 000.
private  LastExecutor workQueue
          Executes the commands to the handler one at a time.
 
Constructor Summary
protected Handler()
          Creates a new handler interface.
 
Method Summary
private  void fireMovementStopped()
          Stops calculating estimated current position
private  void fireRotationStopped()
          Stops calculating estimated current position
 int getEstimatedPosition()
          Returns an estimation that where handler is right now.
 int getEstimatedRotation()
          Used for graphics of squid, estimates from speed and starting time where handler is.
 int getPosition()
          Returns the position where the handler is currently, or where it is heading right now.
 int getRotation()
          Returns the handler's current rotation, or where it is rotating to right now.
protected  void go()
          Send handler on move (G).
 boolean isMoving()
          Tells whether handler is moving right now.
 boolean isOK()
          Checks if the serial communication channel is open.
 boolean isRotating()
          Tells whether handler is rotating right now.
 void join()
          Waits that all commands sent to the Handler have been executed.
protected  void moveSteps(int steps, int velocity)
          Commands the holder to move to the specified number of steps.
 void moveToBackground()
          Commands the holder to move to background position.
 void moveToDegausserY()
          Commands the holder to move to degauss Y (and X) position.
 void moveToDegausserZ()
          Commands the holder to move to degauss Z position.
 void moveToLeftLimit()
          Commands the holder to go to left limit.
 void moveToMeasurement()
          Commands the holder to move to measure position.
protected  void moveToPosition(int position)
          Moves the handler to an absolute position.
 void moveToRightLimit()
          Commands the holder to go to right limit.
 void moveToSampleLoad()
          Commands the holder to move to sample load position.
protected  void performSlew()
          Slew the motor up to maximum speed and continue until reaching a hard limit switch or receiving a quit (Q) command.
 void rotateTo(int rotationAngle)
          Rotates the handler to the specified angle.
protected  void seekHome()
          Commands the holder to seek home position and rotation.
protected  void selectMovement()
          Selects the movement motor to recieve all commands.
protected  void selectRotation()
          Selects the rotation motor to recieve all commands.
 void serialIOEvent(SerialIOEvent event)
          Propagates serial port message event.
protected  void setAcceleration(int acceleration)
          Sends message to handler to set acceleration (Aa).
protected  void setDeceleration(int deceleration)
          Sends message to handler to set deceleration (Dd).
protected  void setMotorNegative()
          Set the motor direction of movement to negative. (-).
protected  void setMotorPositive()
          Set the motor direction of movement to positive. (+).
protected  void setOnline()
          Sends message to handler go online (@0).
protected  void setPosition(int position)
          Sets the position that we start heading to.
protected  void setRotation(int rotationSteps)
          Sets the rotation that we start heading to.
protected  void setUp()
          Starts up the handler and seeks the home position.
protected  void setVelocity(int velocity)
          Sends message to handler to set maximum velocity (Mv).
protected  void slewToLimit(boolean toRight)
           
protected  void stopExecution()
          This command stops execution of the internal program if it is used in the program.
protected  char takeMessage()
          take the device for any waiting messages such as errors or end of move
protected  void updateSettings()
          Checks which settings have changed and updates the handler interface.
protected  void waitForMessage()
          Wait for handler to be idle.
protected  String verify(char registry)
          Gives result for wanted registery.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

answerQueue

private SynchronousQueue<String> answerQueue
Synchronous queue for waiting result message from handler


workQueue

private LastExecutor workQueue
Executes the commands to the handler one at a time. All public interfaces should send their commands to this queue so that they would not conflict eachother.


POLL_TIMEOUT

private final int POLL_TIMEOUT
timeout how long we wait answer from Squid-system, debugging to prevent lock-ups if communication fails.

See Also:
Constant Field Values

serialIO

protected SerialIO serialIO
COM port for communication.


ACCELERATION

private int ACCELERATION
Value between 0 and 127 default 5. Settings in the 20-50 range are usually employed.


DECELERATION

private int DECELERATION
Value between 0 and 127 default 10. Settings in the 20-50 range are usually employed.


VELOCITY

private int VELOCITY
Value between 50 and 12 000. The decimal number issued is 10 times the actual pulse rate to the motor. Since the motor requires 200 pulses (full step) or 400 pulses (half step) per revolution, a speed setting of M10000 sets the motor to revolve at 5 revolutions per second in full step or 2.5 revolutions in half step. This rate is one-half the sample rate rotation due to the pulley ratios. The sample handler is set up at the factory for half stepping.


MEASUREMENT_VELOCITY

private int MEASUREMENT_VELOCITY
Speed in measurement, should be small.


SAMPLE_LOAD_POSITION

private int SAMPLE_LOAD_POSITION
Value between 1 and 16,777,215. Relative to Home.


TRANSVERSE_YAF_POSITION

private int TRANSVERSE_YAF_POSITION
AF demag position for transverse. Relative to Home.


AXIAL_AF_POSITION

private int AXIAL_AF_POSITION
Axial AF demag position in steps, must be divisible by 10. Relative to Home.


BACKGROUND_POSITION

private int BACKGROUND_POSITION
Position in steps, must be divisible by 10. Relative to Home.


MEASUREMENT_POSITION

private int MEASUREMENT_POSITION
Position in steps, must be divisible by 10. Relative to Home.


ROTATION_VELOCITY

private int ROTATION_VELOCITY
Value between 50 and 8500, but should be small


ROTATION_ACCELERATION

private int ROTATION_ACCELERATION
Value between 0 and 127.


ROTATION_DECELERATION

private int ROTATION_DECELERATION
Value between 0 and 127.


HANDLER_ROTATION

private int HANDLER_ROTATION

currentMotor

private int currentMotor
Currently selected motor to send the commands to.


currentPosition

private int currentPosition
The position where the handler is currently, or where it is heading right now. Integer.MIN_VALUE means the left limit, Integer.MAX_VALUE is the right limit.


currentRotation

private int currentRotation
Angles are between 0 (0) and 2000 (360).


currentVelocity

private int currentVelocity
Last set velocity. Negative for moving to left and positive for moving to right.


estimatedPositionStart

private int estimatedPositionStart
Starting point at start of movement


estimatedPositionStartTime

private long estimatedPositionStartTime
Time in milliseconds when we started movement


estimatedPositionEnd

private int estimatedPositionEnd

estimatedRotationStart

private int estimatedRotationStart

estimatedRotationStartTime

private long estimatedRotationStartTime

estimatedRotationEnd

private int estimatedRotationEnd

waitingForMessage

private boolean waitingForMessage
Only one at time can be waiting for answer, works like semaphore for commanding handler

Constructor Detail

Handler

protected Handler()
           throws SerialIOException
Creates a new handler interface. Opens connection to handler COM port and reads settings from the Settings class.

Throws:
SerialIOException
Method Detail

setUp

protected void setUp()
              throws SerialIOException
Starts up the handler and seeks the home position. Will wait until the handler is ready for operation.

Throws:
SerialIOException

updateSettings

protected void updateSettings()
Checks which settings have changed and updates the handler interface. This method will be called by the Squid class.


isMoving

public boolean isMoving()
Tells whether handler is moving right now.


isRotating

public boolean isRotating()
Tells whether handler is rotating right now.


getPosition

public int getPosition()
Returns the position where the handler is currently, or where it is heading right now. Integer.MAX_VALUE means the right limit and Integer.MIN_VALUE means the left limit.

Returns:
position relative to home.

getRotation

public int getRotation()
Returns the handler's current rotation, or where it is rotating to right now.

Returns:
rotation in range of 0 to 359 degrees

setPosition

protected void setPosition(int position)
Sets the position that we start heading to. Integer.MAX_VALUE means the right limit and Integer.MIN_VALUE means the left limit.


setRotation

protected void setRotation(int rotationSteps)
Sets the rotation that we start heading to. The value is in rotation steps and relative to the home position (no limit to how high the value can be).


fireMovementStopped

private void fireMovementStopped()
Stops calculating estimated current position


fireRotationStopped

private void fireRotationStopped()
Stops calculating estimated current position


getEstimatedPosition

public int getEstimatedPosition()
Returns an estimation that where handler is right now. Used for drawing graphics.

Returns:
the estimated position we are at, or current position if it is known.

getEstimatedRotation

public int getEstimatedRotation()
Used for graphics of squid, estimates from speed and starting time where handler is.

Returns:
estimated rotation of where we are at in angles.

isOK

public boolean isOK()
Checks if the serial communication channel is open.

Returns:
true if ok.

seekHome

protected void seekHome()
                 throws SerialIOException
Commands the holder to seek home position and rotation. Waits for the home to be found and resets the home position and rotation.

Throws:
SerialIOException

moveToSampleLoad

public void moveToSampleLoad()
Commands the holder to move to sample load position. Only starts the movement and will not wait for it to finish.


moveToDegausserZ

public void moveToDegausserZ()
Commands the holder to move to degauss Z position. Only starts the movement and will not wait for it to finish.


moveToDegausserY

public void moveToDegausserY()
Commands the holder to move to degauss Y (and X) position. Only starts the movement and will not wait for it to finish.


moveToMeasurement

public void moveToMeasurement()
Commands the holder to move to measure position. Only starts the movement and will not wait for it to finish.


moveToBackground

public void moveToBackground()
Commands the holder to move to background position. Only starts the movement and will not wait for it to finish.


moveToLeftLimit

public void moveToLeftLimit()
Commands the holder to go to left limit. Only starts the movement and will not wait for it to finish.


moveToRightLimit

public void moveToRightLimit()
Commands the holder to go to right limit. Only starts the movement and will not wait for it to finish.


moveToPosition

protected void moveToPosition(int position)
                       throws SerialIOException
Moves the handler to an absolute position. Waits for the handler to arrive there. Changes the speed of the handler when necessary.

Parameters:
position - the position to move to, relative to home. If equal to Integer.MIN_VALUE, will go to left limit. If equal to Integer.MAX_VALUE, will go to right limit.
Throws:
SerialIOException

moveSteps

protected void moveSteps(int steps,
                         int velocity)
                  throws SerialIOException
Commands the holder to move to the specified number of steps. Only sends the move commands and will not wait for the handler to arrive.

Parameters:
steps - the number of steps to move to.
Throws:
IllegalArgumentException - if steps is not in range -16777215 to 16777215.
SerialIOException

slewToLimit

protected void slewToLimit(boolean toRight)
                    throws SerialIOException
Throws:
SerialIOException

rotateTo

public void rotateTo(int rotationAngle)
Rotates the handler to the specified angle. If angle is over than 360 or lower than 0, it is divided by 360 and value is remainder.

Parameters:
rotationAngle - the angle in degrees to rotate the handler to.

join

public void join()
          throws InterruptedException
Waits that all commands sent to the Handler have been executed.

Throws:
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

setOnline

protected void setOnline()
                  throws SerialIOException
Sends message to handler go online (@0).

Throws:
SerialIOException

selectMovement

protected void selectMovement()
                       throws SerialIOException
Selects the movement motor to recieve all commands. Sets the default velocity, acceleration and deceleration for the motor. If the movement motor is already selected, does nothing.

Throws:
SerialIOException

selectRotation

protected void selectRotation()
                       throws SerialIOException
Selects the rotation motor to recieve all commands. Sets the default velocity, acceleration and deceleration for the motor. If the rotation motor is already selected, does nothing.

Throws:
SerialIOException

setAcceleration

protected void setAcceleration(int acceleration)
                        throws SerialIOException
Sends message to handler to set acceleration (Aa).

Parameters:
acceleration - Acceleration is a number from 0 to 127
Throws:
IllegalArgumentException - if the parameter is not in range.
SerialIOException

setDeceleration

protected void setDeceleration(int deceleration)
                        throws SerialIOException
Sends message to handler to set deceleration (Dd).

Parameters:
deceleration - Deceleration is a number from 0 to 127
Throws:
IllegalArgumentException - if the parameter is not in range.
SerialIOException

setVelocity

protected void setVelocity(int velocity)
                    throws SerialIOException
Sends message to handler to set maximum velocity (Mv).

Parameters:
velocity - Velocity range is 50 to 8,500
Throws:
IllegalArgumentException - if the parameter is not in range.
SerialIOException

stopExecution

protected void stopExecution()
                      throws SerialIOException
This command stops execution of the internal program if it is used in the program. If the motor is indexing it will ramp down and then stop. Use this command to stop the motor after issuing a slew command. (Q).

Throws:
SerialIOException

performSlew

protected void performSlew()
                    throws SerialIOException
Slew the motor up to maximum speed and continue until reaching a hard limit switch or receiving a quit (Q) command. (S). Automatically runs selectMovement() before slewing.

Throws:
SerialIOException

setMotorPositive

protected void setMotorPositive()
                         throws SerialIOException
Set the motor direction of movement to positive. (+).

Throws:
SerialIOException

setMotorNegative

protected void setMotorNegative()
                         throws SerialIOException
Set the motor direction of movement to negative. (-).

Throws:
SerialIOException

go

protected void go()
           throws SerialIOException
Send handler on move (G).

Throws:
SerialIOException

waitForMessage

protected void waitForMessage()
                       throws SerialIOException
Wait for handler to be idle. Blocking (F). Without the this command the SMC25 (Handler system) will continue to accept commands while the motor is moving. This may be desirable, as when changing speed during a move or working with the inputs or outputs. Or it may be undesirable, such as when you wish to make a series of indexes. Without the this command any subsequent Go commands received while the motor is indexing would set the "Not allowed while moving" message. Caution: If this command is used while the motor is executing a Slew command the only way to stop is with a reset or a hard limit switch input.

Throws:
SerialIOException

verify

protected String verify(char registry)
                 throws SerialIOException
Gives result for wanted registery. (V v).

Parameters:
registry - A Acceleration
B Base speed
D Deceleration
E Internal program
G Steps remaining in current move. Zero if not indexing.
H Hold time
I Input pins
J Slow jog speed
M Maximum speed
N Number of steps to index
O Output pins
P Position. If motor is indexing this returns the position at the end of the index.
R Internal program pointer used by trace (T) or continue (X) commands. Also updated by enter (E) command.
W Ticks remaining on wait counter
X Crystal frequency
Returns:
registery as a string
Throws:
SerialIOException

takeMessage

protected char takeMessage()
                    throws SerialIOException
take the device for any waiting messages such as errors or end of move. (

Returns:
0 Normal, no service required
1 Command error, illegal command sent
2 Range error, an out of range numeric parameter was sent
3 Command invalid while moving (e.g. G, S, H)
4 Command only valid in program (e.g. I, U, L)
5 End of move notice, a previous G command is complete
6 End of wait notice, a previousW command is complete
7 Hard limit stop, the move was stopped by the hard limit
8 End of program notice, internal program has completed
G Motor is indexing and no other notice pending
Throws:
SerialIOException

serialIOEvent

public void serialIOEvent(SerialIOEvent event)
Description copied from interface: SerialIOListener
Propagates serial port message event.

Specified by:
serialIOEvent in interface SerialIOListener
Parameters:
event - the event that happened.