TMotorCANControl.servo_serial module

A module for controlling the motor in Servo mode over a serial port.

class TMotorCANControl.servo_serial.COMM_PACKET_ID[source]

Bases: object

Basically used as ENUM to identify what each packet ID does

COMM_ERASE_NEW_APP = 2
COMM_FW_VERSION = 0
COMM_GET_VALUES = 4
COMM_GET_VALUES_SETUP = 50
COMM_JUMP_TO_BOOTLOADER = 1
COMM_ROTOR_POSITION = 22
COMM_SET_CURRENT = 6
COMM_SET_CURRENT_BRAKE = 7
COMM_SET_DETECT = 11
COMM_SET_DUTY = 5
COMM_SET_HANDBRAKE = 10
COMM_SET_POS = 9
COMM_SET_POS_MULTI = 92
COMM_SET_POS_ORIGIN = 95
COMM_SET_POS_SINGLE = 93
COMM_SET_POS_SPD = 91
COMM_SET_POS_UNLIMITED = 94
COMM_SET_RPM = 8
COMM_WRITE_NEW_APP_DATA = 3
TMotorCANControl.servo_serial.ERROR_CODES = {0: 'FAULT_CODE_NONE', 1: 'FAULT_CODE_OVER_VOLTAGE', 2: 'FAULT_CODE_UNDER_VOLTAGE', 3: 'FAULT_CODE_DRIVE', 4: 'FAULT_CODE_ABS_OVER_CURRENT', 5: 'FAULT_CODE_OVER_TEMP_FET', 6: 'FAULT_CODE_OVER_TEMP_MOTOR', 7: 'FAULT_CODE_GATE_DRIVER_OVER_VOLTAGE', 8: 'FAULT_CODE_GATE_DRIVER_UNDER_VOLTAGE', 9: 'FAULT_CODE_MCU_UNDER_VOLTAGE', 10: 'FAULT_CODE_BOOTING_FROM_WATCHDOG_RESET', 11: 'FAULT_CODE_ENCODER_SPI', 12: 'FAULT_CODE_ENCODER_SINCOS_BELOW_MIN_AMPLITUDE', 13: 'FAULT_CODE_ENCODER_SINCOS_ABOVE_MAX_AMPLITUDE', 14: 'FAULT_CODE_FLASH_CORRUPTION', 15: 'FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_1', 16: 'FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_2', 17: 'FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_3', 18: 'FAULT_CODE_UNBALANCED_CURRENTS'}

A dictionary mapping error code numbers to the name of the error code

TMotorCANControl.servo_serial.PARAMETER_FLAGS = {'DUTY_CYCLE': 128, 'D_CURRENT': 32, 'INPUT_CURRENT': 16, 'INPUT_VOLTAGE': 512, 'MOSFET_TEMP': 1, 'MOTOR_ERROR_FLAG': 65536, 'MOTOR_ID': 262144, 'MOTOR_POSITION': 131072, 'MOTOR_SPEED': 256, 'MOTOR_TEMP': 4, 'OUTPUT_CURRENT': 8, 'Q_CURRENT': 64}

A dictionary of flags, where 1 means enable the desired parameter during feedback, and 0 means disable.

class TMotorCANControl.servo_serial.SERVO_SERIAL_CONTROL_STATE(value)[source]

Bases: Enum

An Enum to keep track of different control states

CURRENT_BRAKE = 2
CURRENT_LOOP = 1
DUTY_CYCLE = 0
HANDBRAKE = 5
IDLE = 7
POSITION = 4
POSITION_VELOCITY = 6
VELOCITY = 3
TMotorCANControl.servo_serial.Servo_Params_Serial = {'AK80-9': {'Curr_max': 15.0, 'Curr_min': -15.0, 'GEAR_RATIO': 9, 'Kt': 0.115, 'NUM_POLE_PAIRS': 21, 'P_max': 58.85, 'P_min': -58.85, 'Temp_max': 40.0, 'Type': 'AK80-9', 'V_max': 20.0, 'V_min': -20.0}}

Dictionary with the default parameters for the motors, indexed by their name

Parameters
  • Type (str) – the name of this type of motor (ie, AK##-##)

  • P_min (float) – Minimum position in radians

  • P_max (float) – Maximum position in radians

  • V_min (float) – Minimum speed command in velocity control in rad/s

  • V_max (float) – Maximum speed command in velocity control in rad/s

  • Curr_min (float) – Minimum current command during current control in A

  • Curr_max (float) – Maximum current command during current control in A

  • Temp_max (float) – Temperature above which motor should be turned off in Celsius

  • Kt (float) – Torque constant of motor in Nm/A, before gearbox, q-axis

  • GEAR_RATIO (int) – The gear ratio of the motor “n” as in n:1

  • NUM_POLE_PAIRS (int) – Number of pole pairs in the motor

class TMotorCANControl.servo_serial.TMotorManager_servo_serial(port='/dev/ttyUSB0', baud=961200, motor_params={'Curr_max': 15.0, 'Curr_min': -15.0, 'GEAR_RATIO': 9, 'Kt': 0.115, 'NUM_POLE_PAIRS': 21, 'P_max': 58.85, 'P_min': -58.85, 'Temp_max': 40.0, 'Type': 'AK80-9', 'V_max': 20.0, 'V_min': -20.0}, max_mosfett_temp=50)[source]

Bases: object

The user-facing class that manages the motor. This class should be used in the “context” of a with as block, in order to safely enter/exit control of the motor.

__enter__()[source]

Used to safely power the motor on.

__exit__(etype, value, tb)[source]

Used to safely power the motor off and close the reader thread and serial port.

__init__(port='/dev/ttyUSB0', baud=961200, motor_params={'Curr_max': 15.0, 'Curr_min': -15.0, 'GEAR_RATIO': 9, 'Kt': 0.115, 'NUM_POLE_PAIRS': 21, 'P_max': 58.85, 'P_min': -58.85, 'Temp_max': 40.0, 'Type': 'AK80-9', 'V_max': 20.0, 'V_min': -20.0}, max_mosfett_temp=50)[source]

Initialize the motor manager. Note that this will not turn on the motor, until __enter__ is called (automatically called in a with block)

Parameters
  • port – the name of the serial port to connect to (ie, /dev/ttyUSB0, COM3, etc)

  • baud – the baud rate to use for connection. Should always be 961200 as far as I can tell.

  • motor_params – A parameter dictionary defining the motor parameters, as defined above.

  • max_mosfett_temp – Temperature of the mosfett above which to throw an error, in Celsius

_send_specific_command(command)[source]

Sends the specified command rather than the current value of <this object>._command

Parameters

command – bytearray with the command to send.

property acceleration

Output acceleration in rad/s/s

property acceleration_motorside

Motor-side acceleration in rad/s/s

property angle_motorside

Motor-side angle in rad

check_connection()[source]

For now, just sends some parameter read commands and waits 0.2 seconds to see if we got a response.

comm_begin_position_feedback(set_command=True)[source]

Tell the motor to send back its current position every 10ms

Parameters

set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_get_motor_parameters(set_command=True)[source]

Request the current motor parameters

Parameters

set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_set_current_loop(current, set_command=True)[source]

send am Iq current to motor, the motor output torque = Iq *KT, so it can be used as a torque loop

Parameters
  • current – q axis current to use in A, sign denotes direction

  • set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_set_duty_cycle(duty, set_command=True)[source]

send a certain duty cycle voltage to motor

Parameters
  • duty – -1.0 to 1.0 duty cycle to use

  • set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_set_motor_parameter_return_format_all(set_command=True)[source]

Tell the motor to send back all possible fields when an update is requested.

Parameters

set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_set_multi_turn(set_command=True)[source]

Tell the motor to operate in multi-turn mode, rather than being limited to Just 360 degrees of position feedback.

Parameters

set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_set_position(pos, set_command=True)[source]

send a certain position to motor, the motor will run to the specified position, (default speed 12000erpm acceleration 40000erpm)

Parameters
  • pos – Desired position in degrees

  • set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_set_position_velocity(pos, vel, acc, set_command=True)[source]

send a certain position, speed and acceleration to motor. The motor will run at a given acceleration and maximum speed to a specified position.

Parameters
  • pos – Desired position in degrees

  • vel – Desired speed in ERPM

  • acc – Desired acceleration in ERPM/minute? TODO verify this

  • set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

comm_set_speed_ERPM(speed, set_command=True)[source]

send a certain motion speed to motor

Parameters
  • speed – speed to use in ERPM, sign denotes direction

  • set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

property current_bus

Bus input current in amps

property current_daxis

D-axis current in amps

property current_qaxis

Q-axis current in amps

device_info_string()[source]

Prints the motor’s serial port and device type.

enter_current_control()[source]

Set the control state to CURENT_LOOP In this mode, you can send an Iq current to motor, the motor output torque = Iq *KT, so it can be used as a torque loop

enter_duty_cycle_control()[source]

Set the control state to DUTY_CYCLE In this mode, you can send a certain duty cycle voltage to motor

enter_idle_mode()[source]

Set the control state to IDLE and current command to none. In this mode, no command will be sent.

enter_position_control()[source]

Set the control state to POSITION In this mode, you can send a certain position to motor, the motor will run to the specified position, (default speed 12000erpm acceleration 40000erpm)

enter_position_velocity_control()[source]

Set the control state to POSITION_VELOCITY In this mode, you can send a certain position, speed and acceleration to motor. The motor will run at a given acceleration and maximum speed to a specified position.

enter_velocity_control()[source]

Set the control state to VELOCITY In this mode, you can send a certain motion speed to motor

property error

Error Codes: 0 : ‘FAULT_CODE_NONE’ 1 : ‘FAULT_CODE_OVER_VOLTAGE’ 2 : ‘FAULT_CODE_UNDER_VOLTAGE’ 3 : ‘FAULT_CODE_DRIVE’ 4 : ‘FAULT_CODE_ABS_OVER_CURRENT’ 5 : ‘FAULT_CODE_OVER_TEMP_FET’ 6 : ‘FAULT_CODE_OVER_TEMP_MOTOR’ 7 : ‘FAULT_CODE_GATE_DRIVER_OVER_VOLTAGE’ 8 : ‘FAULT_CODE_GATE_DRIVER_UNDER_VOLTAGE’ 9 : ‘FAULT_CODE_MCU_UNDER_VOLTAGE’ 10 : ‘FAULT_CODE_BOOTING_FROM_WATCHDOG_RESET’ 11 : ‘FAULT_CODE_ENCODER_SPI’ 12 : ‘FAULT_CODE_ENCODER_SINCOS_BELOW_MIN_AMPLITUDE’ 13 : ‘FAULT_CODE_ENCODER_SINCOS_ABOVE_MAX_AMPLITUDE’ 14 : ‘FAULT_CODE_FLASH_CORRUPTION’ 15 : ‘FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_1’ 16 : ‘FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_2’ 17 : ‘FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_3’ 18 : ‘FAULT_CODE_UNBALANCED_CURRENTS’

get_current_bus_amps()[source]

Returns: The most recently updated qaxis current in amps

get_current_daxis_amps()[source]

Returns: The most recently updated qaxis current in amps

get_current_qaxis_amps()[source]

Returns: The most recently updated qaxis current in amps

get_motor_acceleration_radians_per_second_squared()[source]

Wrapper for get_output_acceleration that accounts for gear ratio to get motor-side acceleration

Returns

The most recently updated motor-side acceleration in rad/s/s.

get_motor_angle_radians()[source]

Wrapper for get_output_angle that accounts for gear ratio to get motor-side angle

Returns

The most recently updated motor-side angle in rad.

get_motor_error_code()[source]

Returns: The most recently updated motor error code. Note the program should throw a runtime error before you get a chance to read this value if it is ever anything besides 0.

Codes:

0 : ‘FAULT_CODE_NONE’ 1 : ‘FAULT_CODE_OVER_VOLTAGE’ 2 : ‘FAULT_CODE_UNDER_VOLTAGE’ 3 : ‘FAULT_CODE_DRIVE’ 4 : ‘FAULT_CODE_ABS_OVER_CURRENT’ 5 : ‘FAULT_CODE_OVER_TEMP_FET’ 6 : ‘FAULT_CODE_OVER_TEMP_MOTOR’ 7 : ‘FAULT_CODE_GATE_DRIVER_OVER_VOLTAGE’ 8 : ‘FAULT_CODE_GATE_DRIVER_UNDER_VOLTAGE’ 9 : ‘FAULT_CODE_MCU_UNDER_VOLTAGE’ 10 : ‘FAULT_CODE_BOOTING_FROM_WATCHDOG_RESET’ 11 : ‘FAULT_CODE_ENCODER_SPI’ 12 : ‘FAULT_CODE_ENCODER_SINCOS_BELOW_MIN_AMPLITUDE’ 13 : ‘FAULT_CODE_ENCODER_SINCOS_ABOVE_MAX_AMPLITUDE’ 14 : ‘FAULT_CODE_FLASH_CORRUPTION’ 15 : ‘FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_1’ 16 : ‘FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_2’ 17 : ‘FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_3’ 18 : ‘FAULT_CODE_UNBALANCED_CURRENTS’

get_motor_error_string()[source]
get_motor_torque_newton_meters()[source]

Wrapper for get_output_torque that accounts for gear ratio to get motor-side torque

Returns

The most recently updated motor-side torque in Nm.

get_motor_velocity_radians_per_second()[source]

Wrapper for get_output_velocity that accounts for gear ratio to get motor-side velocity

Returns

The most recently updated motor-side velocity in rad/s.

get_output_acceleration_radians_per_second_squared()[source]
Returns

The most recently updated output acceleration in radians per second per second

get_output_angle_radians()[source]

Returns: The most recently updated output angle in radians

get_output_torque_newton_meters()[source]
Returns

the most recently updated output torque in Nm

get_output_velocity_radians_per_second()[source]
Returns

The most recently updated output velocity in radians per second

get_temperature_celsius()[source]

Returns: The most recently updated motor temperature in degrees C.

get_voltage_bus_volts()[source]

Returns: The most recently updated input voltage in volts

get_voltage_daxis_volts()[source]

Returns: The most recently updated daxis voltage in volts

get_voltage_qaxis_volts()[source]

Returns: The most recently updated qaxis voltage in volts

parse_motor_parameters_async(data)[source]

Update this motor’s asynch state (except position) based on received data

Parameters

data – The data array to parse the parameters from

parse_position_feedback_async(data)[source]

Update this motor’s asynch position based on recieved data

Parameters

data – The data array to parse the position from.

parse_set_position_feedback_async(data)[source]

Update this motor’s asynch position based on recieved data.

Parameters

data – The data array to parse the position from.

property position

Output angle in rad

power_off()[source]

There is no official power off command that I can see, so this will set the duty cycle to 0.0

power_on()[source]

Send the startup sequence command. Not sure why it’s like this, but the command is [0x40, 0x80, 0x20, 0x02, 0x21, 0xc0]

send_command()[source]

Sends the current command that the user has specified.

set_duty_cycle_percent(duty)[source]

Update the current command to the desired duty cycle. Note, this does not send a command, it updates the TMotorManager’s saved command, which will be sent when update() is called.

Parameters

duty – The desired duty cycle -1.0 to 1.0

set_motor_angle_radians(pos)[source]

Wrapper for set_output_angle that accounts for gear ratio to control motor-side angle

Parameters

pos – The desired motor-side position in rad.

set_motor_current_qaxis_amps(curr)[source]

Update the current command to the desired current. Note, this does not send a command, it updates the TMotorManager’s saved command, which will be sent when update() is called.

Parameters

curr – The desired q-axis current in A

set_motor_torque_newton_meters(torque)[source]

Version of set_output_torque that accounts for gear ratio to control motor-side torque

Parameters

torque – The desired motor-side torque in Nm.

set_motor_velocity_radians_per_second(vel)[source]

Wrapper for set_output_velocity that accounts for gear ratio to control motor-side velocity

Parameters

vel – The desired motor-side velocity in rad/s.

set_output_angle_radians(pos, vel=0.75, acc=0.5)[source]

Update the current command to the desired position, when in position or position-velocity mode. Note, this does not send a command, it updates the TMotorManager’s saved command, which will be sent when update() is called.

Parameters
  • pos – The desired output angle in rad

  • vel – The desired speed to get there in rad/s (when in POSITION_VELOCITY mode)

  • acc – The desired acceleration to get there in rad/s/s, ish (when in POSITION_VELOCITY mode)

set_output_torque_newton_meters(torque)[source]

Update the current command to the desired current, based on the requested torque. Note, this does not send a command, it updates the TMotorManager’s saved command, which will be sent when update() is called.

Parameters

torque – The desired output torque in Nm.

set_output_velocity_radians_per_second(vel)[source]

Update the current command to the desired velocity. Note, this does not send a command, it updates the TMotorManager’s saved command, which will be sent when update() is called.

Parameters

vel – The desired output speed in rad/s

set_zero_position(set_command=True)[source]

Set the current position of the motor to be the new zero position.

Parameters

set_command – set the TMotorManager’s current command to this if True

Returns

The command as a bytearray

property temperature

Temperature in Degrees Celsius

property torque

Output torque in Nm

property torque_motorside

Motor-side torque in Nm

update()[source]

Synchronizes the current motor state with the asynchronously updated state. Sends the current motor command Sends the command to get parameter feedback

Raises

RuntimeError – if this method is called before the motor is entered.

update_async(data)[source]

Update the asynchronous motor state. Called by a reader thread.

Parameters

data – An array of N bytes of data to parse, [packet id, data_1, …, data_N]

Raises

RuntimeError – If the packet recieved contains an error code.

property velocity

Output velocity in rad/s

property velocity_motorside

Motor-side velocity in rad/s

property voltage_bus

Bus input voltage in volts

property voltage_daxis

D-axis voltage in volts

property voltage_qaxis

Q-axis voltage in volts

TMotorCANControl.servo_serial.buffer_append_int16(buffer, number)[source]

split a 16 bit signed integer into 2 bytes and append to buffer.

Parameters
  • Buffer – memory allocated to store data.

  • number – value.

TMotorCANControl.servo_serial.buffer_append_int32(buffer, number)[source]

split a 32 bit signed integer into 4 bytes and append to buffer.

Parameters
  • Buffer – memory allocated to store data.

  • number – value.

TMotorCANControl.servo_serial.buffer_append_int64(buffer, number)[source]

split a 64 bit signed integer into 8 bytes and append to buffer.

Parameters
  • Buffer – memory allocated to store data.

  • number – value.

TMotorCANControl.servo_serial.buffer_append_uint16(buffer, number)[source]

split a 16 bit unsigned integer into 2 bytes and append to buffer.

Parameters
  • Buffer – memory allocated to store data.

  • number – value.

TMotorCANControl.servo_serial.buffer_append_uint32(buffer, number)[source]

split a 32 bit unsigned integer into 4 bytes and append to buffer.

Parameters
  • Buffer – memory allocated to store data.

  • number – value.

TMotorCANControl.servo_serial.buffer_append_uint64(buffer, number)[source]

split a 64 bit unsigned integer into 8 bytes and append to buffer.

Parameters
  • Buffer – memory allocated to store data.

  • number – value.

TMotorCANControl.servo_serial.buffer_get_int16(buffer, ind)[source]

Grab the 16 bit integer at data[ind:ind+1]

Parameters
  • buffer – array with bytes of data

  • ind – location to index

Returns

ind+1]

Return type

16 bit integer at data[ind

TMotorCANControl.servo_serial.buffer_get_int32(buffer, ind)[source]

Grab the 32 bit integer at data[ind:ind+3]

Parameters
  • buffer – array with bytes of data

  • ind – location to index

Returns

ind+3]

Return type

32-bit signed integer at data[ind

TMotorCANControl.servo_serial.buffer_get_int8(buffer, ind)[source]

Grab the 8 bit integer at data[ind]

Parameters
  • buffer – array with bytes of data

  • ind – location to index

Returns

8 bit integer at data[ind]

TMotorCANControl.servo_serial.crc16(data, DL)[source]

Calculate the crc16 value for the given data array and data length. This is just translated to python from the C code in the manual on the cubmars website.

Parameters
  • data – array of data to creat checksum value for

  • DL – data length

Returns

16-bit integer checksum.

TMotorCANControl.servo_serial.crc16_tab = [0, 4129, 8258, 12387, 16516, 20645, 24774, 28903, 33032, 37161, 41290, 45419, 49548, 53677, 57806, 61935, 4657, 528, 12915, 8786, 21173, 17044, 29431, 25302, 37689, 33560, 45947, 41818, 54205, 50076, 62463, 58334, 9314, 13379, 1056, 5121, 25830, 29895, 17572, 21637, 42346, 46411, 34088, 38153, 58862, 62927, 50604, 54669, 13907, 9842, 5649, 1584, 30423, 26358, 22165, 18100, 46939, 42874, 38681, 34616, 63455, 59390, 55197, 51132, 18628, 22757, 26758, 30887, 2112, 6241, 10242, 14371, 51660, 55789, 59790, 63919, 35144, 39273, 43274, 47403, 23285, 19156, 31415, 27286, 6769, 2640, 14899, 10770, 56317, 52188, 64447, 60318, 39801, 35672, 47931, 43802, 27814, 31879, 19684, 23749, 11298, 15363, 3168, 7233, 60846, 64911, 52716, 56781, 44330, 48395, 36200, 40265, 32407, 28342, 24277, 20212, 15891, 11826, 7761, 3696, 65439, 61374, 57309, 53244, 48923, 44858, 40793, 36728, 37256, 33193, 45514, 41451, 53516, 49453, 61774, 57711, 4224, 161, 12482, 8419, 20484, 16421, 28742, 24679, 33721, 37784, 41979, 46042, 49981, 54044, 58239, 62302, 689, 4752, 8947, 13010, 16949, 21012, 25207, 29270, 46570, 42443, 38312, 34185, 62830, 58703, 54572, 50445, 13538, 9411, 5280, 1153, 29798, 25671, 21540, 17413, 42971, 47098, 34713, 38840, 59231, 63358, 50973, 55100, 9939, 14066, 1681, 5808, 26199, 30326, 17941, 22068, 55628, 51565, 63758, 59695, 39368, 35305, 47498, 43435, 22596, 18533, 30726, 26663, 6336, 2273, 14466, 10403, 52093, 56156, 60223, 64286, 35833, 39896, 43963, 48026, 19061, 23124, 27191, 31254, 2801, 6864, 10931, 14994, 64814, 60687, 56684, 52557, 48554, 44427, 40424, 36297, 31782, 27655, 23652, 19525, 15522, 11395, 7392, 3265, 61215, 65342, 53085, 57212, 44955, 49082, 36825, 40952, 28183, 32310, 20053, 24180, 11923, 16050, 3793, 7920]

CRC 16 table as given in the manual, to be used to verify the packets recived

TMotorCANControl.servo_serial.create_packet(data)[source]

Packages the data into a packet to be sent.

Parameters

data – array of N+1 bytes of data, [packet id, data_1, …, data_N]

Returns

array in the format, [0x02, data length, packet id, data_1, …, data_N, crc_1, crc_2, 0x03]

Return type

packet

class TMotorCANControl.servo_serial.motor_listener[source]

Bases: Protocol

Implements the pyserial “Protocol” class to handle messages asynchronously TODO when pyserial implmements asyncio support, switch to that

__init__()[source]

Initializes the class, including the state machine variables and a reference to the motor manager in the main thread that this class will update.

connection_lost(transport)[source]

Could add other things to happen here on connection termination.

Parameters

transport – the connection

connection_made(transport)[source]

Could add other things to happen here on connection initialization.

Parameters

transport – the connection

data_received(data)[source]

Handle data that’s been recieved, by stepping through a state machine one byte at a time. States:

0: expecting 0x02 for beginning of next message 1: expecting data length field 2: will keep reading data until DL + 2 3: expecting 0x03 for ending of this message

Parameters

data – array of received data to parse

handle_packet(packet)[source]

Called whenever the state machine finishes reading a packet, to update motor manager object.

Parameters

packet – array of data to parse.

TMotorCANControl.servo_serial.parse_packet(packet)[source]

Check that the packet makes sense, and get the data out of it.

Parameters

packet – array in the format [0x02, data length, packet id, data_1, …, data_N, crc_1, crc_2, 0x03]

Returns

Just the packet id and actual data from the recieved packet, [packet id, data_1, …, data_N] None: returns None if the packet failed to successfully parse

Return type

data

class TMotorCANControl.servo_serial.servo_serial_motor_state[source]

Bases: object

An object representing the state of the motor

__init__()[source]

Initialize the motor state to zero.

set_state(mos_temperature=None, motor_temperature=None, output_current=None, input_current=None, id_current=None, iq_current=None, duty=None, speed=None, input_voltage=None, position_set=None, controlID=None, Vd=None, Vq=None, error=None, acceleration=None, position=None)[source]

Set the motor state based on input to the function. If any field is not specified, then that field will not be altered.