sangaboard.sangaboard module

Sangaboard module.

This Python code allows control of the Sangaboard

class sangaboard.sangaboard.Sangaboard(port=None, timeout: int = 2, **kwargs)[source]

Bases: ExtensibleSerialInstrument

Class managing serial communications with a Sangaboard

The Sangaboard class handles setting up communications with the sangaboard, wraps the various serial commands in Python methods, and provides iterators and context managers to simplify opening/closing the hardware connection and some other tasks like conducting a linear scan.

Arguments to the constructor are passed to the constructor of Sangaboard.extensible_serial_instrument.ExtensibleSerialInstrument, most likely the only one necessary is port which should be set to the serial port you will use to communicate with the motor controller.

This class can be used as a context manager, i.e. it’s encouraged to use it as:

with Sangaboard() as sb:
    sb.move_rel([1000,0,0])

In that case, the serial port will automatically be closed at the end of the block, even if an error occurs. Otherwise, be sure to call the close() method to release the serial port.

valid_firmwares = [(1, 0), (0, 5), (0, 4)]

List of valid and deprecated firmwares, for communication checks.

Each is a tuple of (major version, minor version). So v1.0 is (1, 0).

deprecated_firmwares = [(0, 4)]

Firmwares that are valid for communication but throw deprecation wanrings.

port_settings = {'baudrate': 115200, 'bytesize': serial.EIGHTBITS, 'parity': serial.PARITY_NONE, 'stopbits': serial.STOPBITS_ONE}
port_settings_list = [{'baudrate': 115200, 'bytesize': serial.EIGHTBITS, 'parity': serial.PARITY_NONE, 'stopbits': serial.STOPBITS_ONE}, {'baudrate': 115200, 'bytesize': serial.EIGHTBITS, 'parity': serial.PARITY_NONE, 'stopbits': serial.STOPBITS_ONE}]
position

Get the position of the axes as a tuple of 3 integers.

step_time

Get or set the minimum time between steps of the motors in microseconds.

The step time is 1000000/max speed in steps/second. It is saved to EEPROM on the sangaboard, so it will be persistent even if the motor controller is turned off.

ramp_time

Get or set the acceleration time in microseconds.

The motors will accelerate/decelerate between stationary and maximum speed over ramp_time microseconds. Zero means the motor runs at full speed initially, with no accleration control. Small moves may last less than 2*ramp_time, in which case the acceleration will be the same, but the motor will never reach full speed. It is saved to EEPROM on the sangaboard, so it will be persistent even if the motor controller is turned off.

axis_names = ('x', 'y', 'z')
firmware = None
supported_light_sensors = ['TSL2591', 'ADS1115']
test_communications()[source]

Overrides superclass, used in self.open(), and port scanning

check_valid_firmware()[source]
move_rel(displacement, axis=None)[source]

Make a relative move.

displacement: integer or array/list of 3 integers axis: None (for 3-axis moves) or one of ‘x’,’y’,’z’

release_motors()[source]

De-energise the stepper motor coils

zero_position()[source]

Set the current position to zero

move_abs(final, **kwargs)[source]

Make an absolute move to a position

Note the sangaboard only accepts relative move commands, so this first queries the board for its position, then instructs it to make about relative move.

query(message, *args, **kwargs)[source]

Send a message and read the response.

See ExtensibleSerialInstrument.query()

list_modules()[source]

Return a list of strings detailing optional modules.

Each module will correspond to a string of the form Module Name: Model

print_help()[source]

Print the stage’s built-in help message.

class sangaboard.sangaboard.LightSensor(available, parent=None, model='Generic')[source]

Bases: OptionalModule

An optional module giving access to the light sensor.

If a light sensor is enabled in the motor controller’s firmware, then the sangaboard.Sangaboard will gain an optional module which is an instance of this class. It can be used to access the light sensor (usually via the I2C bus).

integration_time

Get or set the integration time of the light sensor in milliseconds.

intensity

Read the current intensity measured by the light sensor (arbitrary units).

valid_gains = None
property gain

“Get or set the current gain value of the light sensor.

Valid gain values are defined in the valid_gains property, and should be floating-point numbers.

class sangaboard.sangaboard.Endstops(available, parent=None, model='min')[source]

Bases: OptionalModule

An optional module for use with endstops.

If endstops are installed in the firmware the sangaboard.Sangaboard will gain an optional module which is an instance of this class. It can be used to retrieve the type, state of the endstops, read and write maximum positions, and home.

installed = []

List of installed endstop types (min, max, soft)

status

Get endstops status as {-1,0,1} for {min,no,max} endstop triggered for each axis

maxima

Vector of maximum positions, homing to max endstops will measure this, can be set to a known value for use with max only and min+soft endstops

home(direction='min', axes=('x', 'y', 'z'))[source]

Home given/all axes in the given direction (min/max/both)

Parameters:
  • direction – one of {min,max,both}

  • axes – list of axes e.g. [‘x’,’y’]

class sangaboard.sangaboard.Illumination(available, parent=None)[source]

Bases: OptionalModule

An optional module for illumination control.

If illumination module is built into the firmware the sangaboard.Sangaboard will gain an optional module which is an instance of this class.

Only one constant current channel is currently supported.

channels

Get the number of supported CC and PWM channels

pwm_frequency

Get or set the PWM channels frequency

Only supported on RP2040 based platforms. Maximum 1MHz, resolution only ~6bits at that frequency

cc_led

Get or set the CC value 0-1.0

On Sangaboard v0.5 this corresponds to 0-100mA with 32 steps.

set_pwm_led(channel: int, value: float)[source]
get_pwm_led(channel: int = None) float | List[float][source]