sabertooth2x12 - Sabertooth 2x12

Sabertooth2x12

Attributes
Methods
class sabertooth2x12.Sabertooth2x12(filename: str, address: int = 128, baudrate: int = 9600, sim: bool = False)[source]

Helper class to interface with the Sabertooth 2x12 regenerative motor driver.

address

???

Type

int

sim

Whether the device is simulated. If so, a simulated serial connection is constructed, rather than a physical serial connection.

Type

bool

Parameters
  • filename (str) – The name of the serial port to connect to, if a physical serial connection is desired.

  • address (int) – ???. Defaults to 128.

  • baudrate (int) – The baud rate of the serial connection. Defaults to 9600.

  • sim (bool) – Whether to use a simulated serial device. Defaults to False.

static make_packet(address: int, command: int, data: int) bytes[source]

Constructs a packet given an address, command, and data. The checksum is added on to the end of the packet. All four integers are packed as unsigned integers in the resulting packet.

Parameters
  • address (int) –

    ???

  • command (int) – The command to send.

  • data (int) – The data to put in the packet.

Returns

The constructed packet.

Return type

bytes

send_packet(command: int, data: int) None[source]

Sends a packet over the serial connection using the class’ address.

Parameters
  • command (int) – The command to send.

  • data (int) – The data to put in the packet.

set_motor1(speed: float) None[source]

Sets the speed of motor 1. This constructs a packet and sends it to update the driver.

Parameters

speed (float) – The speed to set the first motor to.

set_motor2(speed: float) None[source]

Sets the speed of motor 2. This constructs a packet and sends it to update the driver.

Parameters

speed (float) – The speed to set the second motor to.

SimulatedSabertooth2x12

Methods
class sabertooth2x12.SimulatedSabertooth2x12(*args, **kwargs)[source]

Creates a simulated serial device representing the Sabertooth 2x12 regenerative motor driver.

Implements mil_tools.SimulatedSerial.

write(data: bytes) None[source]

Handles byte data received by the simulated device. Verifies the checksum of the data received, and logs changes in the motor speeds set by the device.