Package dics :: Module cortex :: Class cortex
[hide private]
[frames] | no frames]

Class cortex
source code

Basic class representing an interface to a Cortex controller (or daisy chain of controllers). Presents functions corresponding to each of the commands accepted by a Cortex controller. Performs range checking on arguments and returns response from the controller.

Instance Methods [hide private]
  __init__(self, portname, units, name='cortex')
Arguments:
  __basicCommand(self, command)
Function used to send any command that expects the basic '# ' response, and parses the response received.
  __intCommand(self, command)
Function used to send any command that expects an integer N in a 'N# ' response, parses the response received, and returns the integer.
  getInput(self, cortex_num=1)
Gets the status of the 4-bit input of the Cortex Controller, returning it as an integer in the range 0-15.
  getLimitStatus(self, cortex_num=1)
Queries the limit switch status, returns -1 if lower limit made, +1 if upper limit made and 0 is neither is.
  getParams(self, cortex_num=1)
  getPosition(self, cortex_num=1)
Requests the current motor position from the controller, in steps from the datum and returns it as an integer.
  getRemaining(self, cortex_num=1)
Requests the number of steps left to go in the current move from the controller and returns the reply as an integer.
  isActive(self, cortex_num=1)
Requests the motor status from the controller, returns True if the motor is active, False otherwise.
  saveParams(self, cortex_num=1)
Writes all current controller parameters to EEPROM, if fitted.
  setCurrent(self, current=160, cortex_num=1)
Sets the motor current, in mA.
  setDatum(self, position=0, cortex_num=1)
Change the coordinate system so that the current position is equal to the argument.
  setDefaults(self, cortex_num=1)
Return all parameters to their default values, with the exception of the newline parameter on the first controller in the chain (newlines are required for communication using pySerial).
  setJoystick(self, jitter=4, deadband=20, slowband=10, sense=0, cortex_num=1)
Sets the joystick parameters.
  setLocalMode(self, yes=True, cortex_num=1)
Toggles local/manual mode.
  setMicrostepping(self, ratio, cortex_num=1)
Set the microstepping ratio using the numeric codes described in the Cortex controller documentation.
  setMotorParams(self, baseSpeed=1000, maxSpeed=60000, acceleration=30000, deceleration=120000, cortex_num=1)
Sets the motor motion parameters, base speed, maximum speed, acceleration and deceleration.
  __setNewline(self, yes=True, cortex_num=1)
Toggles the addition of newlines to the replies from the Cortex controller.
  setOutput(self, output, cortex_num=1)
Sets the state of the four bit optocoupler output of the Cortex controller.
  setSpeed(self, speed=150, cortex_num=1)
Sets the constant speed for moveConst, moveConstAbs and moveConstLimit commands.
  halt(self, cortex_num=1)
Smoothly halts the motor.
  move(self, steps, cortex_num=1)
Move a given number of steps (<2000000000) with acceleration (uses motion parameters defined by setMotorParams).
  moveAbs(self, position, cortex_num=1)
Move to a given position, with acceleration (uses motion parameters defined by setMotorParams).
  moveConst(self, steps, cortex_num=1)
Move a given number of steps (<2000000000) at a constant speed (uses speed set via setSpeed).
  moveConstAbs(self, position, cortex_num=1)
Move to a given position at a constant speed (used speed set via setSpeed).
  moveConstLimit(self, direction, cortex_num=1)
Move to a given limit at a constant speed (uses speed set via setSpeed).
  moveLimit(self, direction, cortex_num=1)
Move to a given limit with acceleration (uses motion parameters defined with setMotorParams).
  stop(self, cortex_num=1)
Emergency stop.
  trigger(self, input=-1, cortex_num=1)
Delay move until given a given input goes high.

Method Details [hide private]

__init__(self, portname, units, name='cortex')
(Constructor)

source code 

Arguments:

portname: device name of the serial port to use units: number of cortex units in the chain name: name to be used as a label in the logs

__basicCommand(self, command)

source code 
Function used to send any command that expects the basic
        '#
' response, and parses the response received.  If
        the standard response is not received an appropriate
        exception is raised.

        Arguments: command - string containing the command to send.

__intCommand(self, command)

source code 
Function used to send any command that expects an integer
        N in a 'N#
' response, parses the response received, and returns
        the integer.  If the expected response is not received an appropriate
        exception is raised.

        Arguments: command - string containing the command to send.

getInput(self, cortex_num=1)

source code 

Gets the status of the 4-bit input of the Cortex Controller,
returning it as an integer in the range 0-15.

Arguments: cortex_num - which controller of a daisy chain to
                        query, default 1.

getLimitStatus(self, cortex_num=1)

source code 
Queries the limit switch status, returns -1 if lower limit made,
+1 if upper limit made and 0 is neither is.  Note, this command
ALWAYS stops the motors, use isActive() first to determine if the
motors are in motion.

Arguments: cortex_num - which controller of a daisy chain to
                        query, default 1.

getParams(self, cortex_num=1)

source code 

getPosition(self, cortex_num=1)

source code 
Requests the current motor position from the controller,
in steps from the datum and returns it as an integer.

Arguments: cortex_num - which controller of a daisy chain to
                        query, default 1.

getRemaining(self, cortex_num=1)

source code 
Requests the number of steps left to go in the current move
from the controller and returns the reply as an integer.

Arguments: cortex_num - which controller of a daisy chain to
                        query, default 1.

isActive(self, cortex_num=1)

source code 
Requests the motor status from the controller, returns True
if the motor is active, False otherwise.

Arguments: cortex_num - which controller of a daisy chain to
                        query, default 1.

saveParams(self, cortex_num=1)

source code 
Writes all current controller parameters to EEPROM, if
fitted.

Arguments: cortex_num - which controller of a daisy chain to
                        command, default 1.

setCurrent(self, current=160, cortex_num=1)

source code 
Sets the motor current, in mA.  Allowed range is
0-600mA, in steps of 40mA (intermediate values, if given,
are rounded down to the nearest multiple of 40).  N.B.
Do not exceed 160mA in continous use unless a heatsink is
fitted.

Arguments: current - motor current, in mA, integer in range
                     0-600.
           cortex_num - which controller of a daisy chain to
                        command, default 1.

setDatum(self, position=0, cortex_num=1)

source code 
Change the coordinate system so that the current position
is equal to the argument.

Arguments: position - value to assign to the current position,
                      default 0.
           cortex_num - which controller of a daisy chain to
                        command, default 1.

setDefaults(self, cortex_num=1)

source code 
Return all parameters to their default values, with the
exception of the newline parameter on the first controller in
the chain (newlines are required for communication using
pySerial).  The default values are given in the Cortex
controller doumentation.

Arguments: cotrex_num - which controller of a daisy chain to
                        reset to defaults, default 1.

setJoystick(self, jitter=4, deadband=20, slowband=10, sense=0, cortex_num=1)

source code 
Sets the joystick parameters. No sanity checking of
arguments implemented yet.

Arguments: jitter - allowable joystick noise, default 4
           deadband - joystick deadband, default 20
           slowband - slow motion band, default 10
           sense - joystick not reversed, default 0
           cortex_num - which controller in a daisy chain
                        to command, default 1.

setLocalMode(self, yes=True, cortex_num=1)

source code 
Toggles local/manual mode.  If the first argument is
True sets local mode on, if False sets local mode off.

Arguments: yes - boolean, if True set local mode on,
                 and vice versa, default True
           cortex_num - which controller in a daisy chain
                        to command, default 1.

setMicrostepping(self, ratio, cortex_num=1)

source code 
Set the microstepping ratio using the numeric codes
described in the Cortex controller documentation.  The
argument ratio should be an integer in the range 0-63.

Arguments: ratio - microstepping ratio code, integer
                   in range 0-63.
           cortex_num - which controller in a diasy chain
                        to set, default 1.

setMotorParams(self, baseSpeed=1000, maxSpeed=60000, acceleration=30000, deceleration=120000, cortex_num=1)

source code 
Sets the motor motion parameters, base speed, maximum
speed, acceleration and deceleration.

Arguments: baseSpeed - starting speed for move, moveAbs
                       and moveLimit commands, default
                       1000.
           maxSpeed - top speed, default 60000
           acceleration - acceleration, default 30000
           deceleration - deceleration, default 120000
           cortex_num - which controller in a daisy chain
                        to set, default 1.

__setNewline(self, yes=True, cortex_num=1)

source code 
Toggles the addition of newlines to the replies from the
Cortex controller.  If the first argument is True sets
newlines on, if False sets newlines off.  In order for
proper communications with the first cortex controller
in the chain it must have newlines set to True.  For
inter-controller communications to work all other
controllers (if present) should have newlines False.

Arguments: yes - boolean, if True set local mode on,
                 and vice versa, default True
           cortex_num - which controller in a daisy chain
                        to command, default 1.

setOutput(self, output, cortex_num=1)

source code 
Sets the state of the four bit optocoupler output
of the Cortex controller.

Arguments: output - integer in range 0-15 corresponding
                    to desired state of the 4 bit output.
           cortex_num - which controller in a chain to
                        set, default 1.

setSpeed(self, speed=150, cortex_num=1)

source code 
Sets the constant speed for moveConst, moveConstAbs
and moveConstLimit commands.

Arguments: speed - required speed in steps/sec,
                   integer in range 62-60000
           cortex_num - which controller in a chain
                        to set, default 1.

halt(self, cortex_num=1)

source code 
Smoothly halts the motor.  For emergency stops use
the stop command.

Arguments: cortex_num - which controller in a chain
                        to halt, default 1.

move(self, steps, cortex_num=1)

source code 
Move a given number of steps (<2000000000) with
acceleration (uses motion parameters defined by
setMotorParams).

Arguments: steps - number of steps to move, integer in
                   range -2000000000:+2000000000
           cortex_num - which controller to instruct to
                        move, default 1.

moveAbs(self, position, cortex_num=1)

source code 
Move to a given position, with acceleration (uses motion
parameters defined by setMotorParams).

Arguments: position - position, measure in steps from the datum
                      to move to.
           cortex_num - which controller to instruct to
                        move, default 1.

moveConst(self, steps, cortex_num=1)

source code 
Move a given number of steps (<2000000000) at a
constant speed (uses speed set via setSpeed).

Arguments: steps - number of steps to move, integer in
                   range -2000000000:+2000000000
           cortex_num - which controller to instruct to
                        move, default 1.

moveConstAbs(self, position, cortex_num=1)

source code 
Move to a given position at a constant speed (used
speed set via setSpeed).

Arguments: position - position, measure in steps from the datum
                      to move to.
           cortex_num - which controller to instruct to
                        move, default 1.

moveConstLimit(self, direction, cortex_num=1)

source code 
Move to a given limit at a constant speed (uses speed
set via setSpeed).

Arguments: direction - the direction to move in, 1 for
                       towards the upper limit, -1 for
                       towards the lower limit, or 0
                       for, er, something else (Cortex
                       documentation doesn't explain this).
           cortex_num - which controller to instruct to
                        move, default 1.

moveLimit(self, direction, cortex_num=1)

source code 
Move to a given limit with acceleration (uses motion
parameters defined with setMotorParams).

Arguments: direction - the direction to move in, 1 for
                       towards the upper limit, -1 for
                       towards the lower limit, or 0
                       for, er, something else (Cortex
                       documentation doesn't explain this).
           cortex_num - which controller to instruct to
                        move, default 1.

stop(self, cortex_num=1)

source code 
Emergency stop.

Arguments: cortex_num - which controller in a chain to stop,
                        default 1.

trigger(self, input=-1, cortex_num=1)

source code 
Delay move until given a given input goes high.  If no
input is specified then moves occur as they are requested.

Arguments: input - the number of the input to trigger on,
                   integer in the range 0-3 (I think). If
                   omitted triggering is suspended.
           cortex_num - which controller in a chain to set
                        triggering for, default 1.