gantrylib.md

crane

Crane

A class representing the gantrycrane.

__enter__()

Enter the runtime context for the crane.

Returns:
  • Crane

    The crane instance

__exit__(exc_type, exc_value, traceback)

Exit the runtime context and clean up resources.

Parameters:
  • exc_type (Type[BaseException] or None) –

    The type of the exception if one was raised, else None.

  • exc_value (BaseException or None) –

    The exception instance if one was raised, else None.

  • traceback (TracebackType or None) –

    The traceback object if an exception was raised, else None.

__init__(gantryPort, hoistPort, angleUARTPort, gantryUARTPort, calibrated=False, I_max=1)

Initializes a Crane instance.

Parameters:
  • gantryPort (string) –

    Serial port of the motor controller controlling the lateral movement motor.

  • hoistPort (string) –

    Serial port of the motor controller controlling the hoisting motor.

  • angleUARTPort (string) –

    Serial port of the Arduino that measures the swing angle

  • gantryUARTPort (string) –

    unused

  • calibrated (bool, default: False ) –

    Whether the crane's motors are already calibrated or not. Defaults to False.

  • I_max (int, default: 1 ) –

    Maximal motor current. Defaults to 1A

executeWaypointsPosition()

Attempt to execute the waypoints in position mode.

Works by setting the waypoint and altering the motor's velocity limit as the trajectory moves along.

Returns:
  • tuple( (list[float], list[float], list[float], list[float], list[float], list[float]) ) –

    tuple(t, x, v, a, theta, omega),

homeAllAxes()

Homes all axes.

Hoiststepper isn't homed, since we don't have a proper automated homing procedure for it.

homeGantry()

Homes the cart on the gantry

readAngle()

Reads the latest received angle from the angleUART

Returns:
  • tuple( (float, float) ) –

    Tuple(theta, omega)

setWaypoints(waypoints)

Sets the waypoints to be executed by the crane.

Parameters:
  • waypoints (list[Waypoint]) –

    List of Waypoints.

motors

Motor

A class representing a motor.

__init__(port, pulley_circumference, I_max)

Initializes a Motor instance.

Parameters:
  • port

    serial port of the motor controller

  • pulley_circumference

    circumference of the motor pulley

  • I_max

    maximum current

getPosition()

Get the current position.

Returns:
  • int

    The current position

getTorque()

Get the actually exerted torque.

Returns:
  • int

    The actually exerted torque.

getVelocity()

Get the current velocity.

Returns:
  • int

    The current velocity.

setAccelLimit(acc)

Set acceleration limit.

Parameters:
  • acc

    Acceleration limit.

setLimits(acc, vel)

Set acceleration and velocity limits.

Parameters:
  • acc

    Acceleration limit.

  • vel

    Velocity limit.

setPosition(pos)

Set the current position.

Parameters:
  • pos

    current position.

setPositionMode()

Set motor driver to position mode

setTorque(tgt)

Set the target torque.

Note: assumes printer is in torque mode. Printer can be set in torque mode with setTorqueMode.

Parameters:
  • tgt

    target torque

setTorqueMode()

Set motor drive to torque mode.

setVelocity(vel)

Set the current velocity

Parameters:
  • vel

    The current velocity.

setVelocityLimit(vel)

Set velocity limit.

Parameters:
  • vel

    Velocity limit.

setVelocityMode()

Set motor driver to velocity mode

Stepper

Bases: Motor

Specialization of the Motor class into a Stepper motor.

__init__(port, pulley_diameter, I_max)

Initialize a Stepper instance.

GantryStepper

Bases: Stepper

Specializes stepper into the gantry stepper, that is the motor that does the lateral movement.

__init__(port, calibrated=False, I_max=1)

Initializes an instance of GantryStepper.

Parameters:
  • port

    The serial port of the motor controller.

  • calibrated (bool, default: False ) –

    Whether the motor is calibrated or not. Defaults to False.

  • I_max

    The maximum currnet. Defaults to 1 Ampere.

HoistStepper

Bases: Stepper

Specializes stepper into the hoist stepper, that is the motor that does the hoisting movement.

__init__(port, calibrated=False, I_max=1)

Initializes an instance of GantryStepper.

Parameters:
  • port

    The serial port of the motor controller.

  • calibrated (bool, default: False ) –

    Whether the motor is calibrated or not. Defaults to False.

  • I_max

    The maximum currnet. Defaults to 1 Ampere.

trajectory_generator

TrajectoryGenerator

A class to generate an optimal trajectory that moves the crane laterally from one position to another one.

__init__(properties_file)

Initialize a TrajectoryGenerator instance.

Parameters:
  • properties_file (string) –

    path to a properties file containing problem details.

generateTrajectory(start, stop)

Generates an optimal, monotone trajectory from start to stop, adhering to the limits imposed by the configurationfile used to create the TrajectoryGenerator

Parameters:
  • start (float) –

    start position of the trajectory

  • stop (float) –

    stop position of the trajectory

Returns:
  • tuple

    tuple (ts, xs, dxs, ddxs, thetas, dthetas, ddthetas) where ts : sample times of solution [s] xs : positions of solution [m] dxs : velocity of solution [m/s] ddxs : acceleration of solution [m/s^2] thetas : angular position of solution [rad] dthetas : angular velocity of solution [rad/s] ddthetas: angular acceleration of solution [rad/s^2]

generateTrajectoryLQR(start, stop)

Generates an optimal trajectory using a Linear Quadratic Regulator

Parameters:
  • start (float) –

    Start position

  • stop (float) –

    Stop position

Returns:
  • tuple

    tuple (ts, xs, dxs, ddxs, thetas, dthetas, ddthetas) where ts : sample times of solution [s] xs : positions of solution [m] dxs : velocity of solution [m/s] ddxs : acceleration of solution [m/s^2] thetas : angular position of solution [rad] dthetas : angular velocity of solution [rad/s] ddthetas: angular acceleration of solution [rad/s^2]

saveDataToMat(filename, data, keys)

Save output to a .mat file.

Parameters:
  • filename (string) –

    The filename

  • data (tuple) –

    data as returned by the trajectory generation methods.

  • keys (list) –

    list of keys to use.

saveParamToMat(filename)

Save the parameters of this current trajectory generator to a mat file.

Parameters:
  • filename (string) –

    The filename.

saveToCSV(filename, data, columnnames)

Save output to CSV file.

Parameters:
  • filename (string) –

    The filename.

  • data (tuple) –

    data as returned by the trajectory generation methods.

  • columnnames (list) –

    list of columnnames.

gantry_controller

GantryController

A class representing a controller for the gantry crane

__enter__()

Enter the runtime context of the gantry controller.

Returns:
  • GantryController

    The instance of the GantryController

__exit__(exc_type, exc_value, traceback)

Exit the runtime context and clean up resources

Parameters:
  • exc_type (Type[BaseException] or None) –

    The type of the exception if one was raised, else None.

  • exc_value (BaseException or None) –

    The exception instance if one was raised, else None.

  • traceback (TracebackType or None) –

    The traceback object if an exception was raised, else None.

__init__(properties_file)

Initialize a GantryController instance

Parameters:
  • properties_file (string) –

    path to a properties file that holds details of the gantrycrane.

connectToCrane() abstractmethod

Method to connect to the gantry crane.

This method must be implemented by subclasses to define how to connect to a specific gantry crane.

executeTrajectory(traj) abstractmethod

Execute a trajectory

This methods must be implemented by subclasses to define how the trajectory is executed.

Parameters:
  • traj (tuple) –

    Trajectory tuple as returned by the TrajectoryGenerator

generateTrajectory(start, stop, genmethod='ocp')

Generate a trajectory using the trajectory generator

Parameters:
  • start (float) –

    The start position of the trajectory

  • stop (float) –

    The stop position of the trajectory

  • genmethod (str, default: 'ocp' ) –

    Method of generation, either "ocp" or "lqr". Defaults to "ocp".

Returns:
  • tuple

    Tuple containing the trajectory

hoist(pos) abstractmethod

Perform a hoisting movement

Must be implemented by subclasses.

Parameters:
  • pos (float) –

    The target height

moveTrajectoryWithoutLog(traj)

Move according to the given trajectory

Parameters:
  • traj (tuple) –

    Trajectory as returned by the trajectory generator.

Returns:
  • tuple

    The measured trajectory

moveWithLog(target, generator='ocp')

Make a movement and log it to a database

Parameters:
  • target (float) –

    target position in meters

  • generator (str, default: 'ocp' ) –

    Method of generation, either "ocp" or "lqr". Defaults to "ocp".

Returns:
  • tuple( (tuple, tuple) ) –

    A tuple containing the generated trajectory and the measured trajectory

moveWithoutLog(target, generator='ocp')

Make a movement but don't log it to the database

Parameters:
  • target (float) –

    target position in meters

  • generator (str, default: 'ocp' ) –

    Method of generation, either "ocp" or "lqr". Defaults to "ocp".

Returns:
  • tuple( (tuple, tuple) ) –

    A tuple containing the generated trajectory and the measured trajectory

simpleMove(target) abstractmethod

Perform a simple lateral move without trajectory generation

Must be implemented by subclasses.

Parameters:
  • target (float) –

    The target position

storeMeasurement(measurement)

Store a measurement in the database

measurement is assumed to be a tuple as returned by executeTrajectory format: (ts, x, v, a, theta, omega) ts : timestamps [datetime format] x : position [m] v : velocity [m/s] a : acceleration [m/s2] theta : angular position [rad] omega : angular velocity [rad/s]

Parameters:
  • measurement (tuple) –

    Tuple as returned by executeTrajectory

storeTrajectory(traj)

Store a trajectory in the database

traj is assumed to be tuple as returned by generateTrajectory format: (ts, xs, dxs, ddxs, thetas, dthetas, ddthetas) ts : sample times of solution [s] xs : positions of solution [m] dxs : velocity of solution [m/s] ddxs : acceleration of solution [m/s^2] thetas : angular position of solution [rad] dthetas : angular velocity of solution [rad/s] ddthetas: angular acceleration of solution [rad/s^2] us : input force acting on cart [N]

Parameters:
  • traj (tuple) –

    Trajectory tuple as returned by the trajectory generator.