10 def enum_value(x):
return x.value
13 def enum_value(x):
return x
15from motoron_protocol
import *
26 MOTORON_18V18 = 0b0001
27 MOTORON_24V14 = 0b0101
28 MOTORON_18V20 = 0b1010
29 MOTORON_24V16 = 0b1101
38 Represents a connection to a Pololu Motoron Motoron Controller.
41 __DEFAULT_PROTOCOL_OPTIONS = (
42 (1 << PROTOCOL_OPTION_I2C_GENERAL_CALL) |
43 (1 << PROTOCOL_OPTION_CRC_FOR_COMMANDS) |
44 (1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
47 DEFAULT_ERROR_MASK = (
48 (1 << STATUS_FLAG_COMMAND_TIMEOUT) |
49 (1 << STATUS_FLAG_RESET))
58 Sends the "Get firmware version" command to get the device
's firmware
59 product ID and firmware version numbers.
61 For more information, see the
"Get firmware version"
62 command
in the Motoron user
's guide.
64 \return A dictionary
in this format:
66 {
'product_id': 204,
'firmware_version': {
'major': 1,
'minor': 0}}
69 cmd = [CMD_GET_FIRMWARE_VERSION]
71 product_id, minor, major = struct.unpack('<HBB', response)
73 'product_id': product_id,
74 'firmware_version': {
'major': major,
'minor': minor}
79 Sends the "Set protocol options" command to the device to specify options
80 related to how the device processes commands
and sends responses.
81 The options are also saved
in this object
and are used later
82 when sending other commands
or reading responses.
84 When CRC
for commands
is enabled, this library generates the CRC
85 byte
and appends it to the end of each command it sends. The Motoron
86 checks it to help ensure the command was received correctly.
88 When CRC
for responses
is enabled, this library reads the CRC byte sent
89 by the Motoron
in its responses
and makes sure it
is correct. If the
90 response CRC byte
is incorrect, get_last_error() will
return a non-zero
91 error code after the command has been run.
93 When the I2C general call address
is enabled, the Motoron receives
94 commands sent to address 0
in addition to its usual I2C address.
95 The general call address
is write-only; reading bytes
from it
is not
98 By default (
in this libary
and the Motoron itself), CRC
for commands
and
99 responses
is enabled,
and the I2C general call address
is enabled.
101 This method always sends its command
with a CRC byte, so it will work
102 even
if CRC was previously disabled but has been re-enabled on the device
103 (e.g. due to a reset).
105 The \p options argument should be 0
or combination of the following
106 expressions made using the bitwise
or operator (|):
107 - (1 << motoron.PROTOCOL_OPTION_CRC_FOR_COMMANDS)
108 - (1 << motoron.PROTOCOL_OPTION_CRC_FOR_RESPONSES)
109 - (1 << motoron.PROTOCOL_OPTION_I2C_GENERAL_CALL)
111 For more information, see the
"Set protocol optons"
112 command
in the Motoron user
's guide.
121 CMD_SET_PROTOCOL_OPTIONS,
125 self._send_command_core(cmd, True)
129 Sets the protocol options for this object, without sending a command to
132 If the options you specify here do
not match the actual configuration of
133 the Motoron, future communication could fail.
144 | (1 << PROTOCOL_OPTION_CRC_FOR_COMMANDS)
145 | (1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
152 & ~(1 << PROTOCOL_OPTION_CRC_FOR_COMMANDS)
153 & ~(1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
160 | (1 << PROTOCOL_OPTION_CRC_FOR_COMMANDS))
167 & ~(1 << PROTOCOL_OPTION_CRC_FOR_COMMANDS))
174 | (1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
181 & ~(1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
188 | (1 << PROTOCOL_OPTION_I2C_GENERAL_CALL))
195 & ~(1 << PROTOCOL_OPTION_I2C_GENERAL_CALL))
199 Reads the specified bytes from the Motoron
's EEPROM memory.
201 For more information, see the "Read EEPROM" command
in the
202 Motoron user
's guide.
213 Reads the EEPROM device number from the device.
214 This
is the I2C address that the device uses
if it detects that JMP1
215 is shorted to GND when it starts up. It
is stored
in non-volatile
222 Writes a value to one byte in the Motoron
's EEPROM memory.
224 **Warning: Be careful not to write to the EEPROM
in a fast loop. The
225 EEPROM memory of the Motoron
's microcontroller is only rated for
226 100,000 erase/write cycles.**
228 For more information, see the "Write EEPROM" command
in the
229 Motoron user
's guide.
247 Writes a 2-byte value in the Motoron
's EEPROM memory.
249 This command only has an effect if JMP1
is shorted to GND.
251 **Warning: Be careful
not to write to the EEPROM
in a fast loop. The
252 EEPROM memory of the Motoron’s microcontroller
is only rated
for
253 100,000 erase/write cycles.
260 Writes to the EEPROM device number, changing it to the specified value.
262 This command only has an effect if JMP1
is shorted to GND.
264 **Warning: Be careful
not to write to the EEPROM
in a fast loop. The
265 EEPROM memory of the Motoron
's microcontroller is only rated for
266 100,000 erase/write cycles.**
273 Writes to the alternative device number stored in EEPROM, changing it to
276 This function
is only useful on Motorons
with a serial interface,
277 and only has an effect
if JMP1
is shorted to GND.
279 **Warning: Be careful
not to write to the EEPROM
in a fast loop. The
280 EEPROM memory of the Motoron
's microcontroller is only rated for
281 100,000 erase/write cycles.**
290 Writes to EEPROM to disable the alternative device number.
292 This function is only useful on Motorons
with a serial interface,
293 and only has an effect
if JMP1
is shorted to GND.
295 **Warning: Be careful
not to write to the EEPROM
in a fast loop. The
296 EEPROM memory of the Motoron
's microcontroller is only rated for
297 100,000 erase/write cycles.**
306 Writes to the serial options byte stored in EEPROM, changing it to
309 The bits
in this byte are defined by the
310 MOTORON_COMMUNICATION_OPTION_* constants.
312 This function
is only useful on Motorons
with a serial interface,
313 and only has an effect
if JMP1
is shorted to GND.
315 **Warning: Be careful
not to write to the EEPROM
in a fast loop. The
316 EEPROM memory of the Motoron
's microcontroller is only rated for
317 100,000 erase/write cycles.**
323 Writes to the baud rate stored in EEPROM, changing it to the
326 This function
is only useful on Motorons
with a serial interface,
327 and only has an effect
if JMP1
is shorted to GND.
329 **Warning: Be careful
not to write to the EEPROM
in a fast loop. The
330 EEPROM memory of the Motoron
's microcontroller is only rated for
331 100,000 erase/write cycles.**
333 if (baud < MIN_BAUD_RATE): baud = MIN_BAUD_RATE
334 if (baud > MAX_BAUD_RATE): baud = MAX_BAUD_RATE
339 Writes to the serial response delay setting stored in EEPROM, changing
340 it to the specified value,
in units of microseconds.
342 This function
is only useful on Motorons
with a serial interface,
343 and only has an effect
if JMP1
is shorted to GND.
345 **Warning: Be careful
not to write to the EEPROM
in a fast loop. The
346 EEPROM memory of the Motoron
's microcontroller is only rated for
347 100,000 erase/write cycles.**
353 Sends a "Reinitialize" command to the Motoron, which resets most of the
354 Motoron
's variables to their default state.
356 For more information, see the "Reinitialize" command
in the Motoron
362 cmd = [CMD_REINITIALIZE]
363 self._send_command_core(cmd,
True)
368 Sends a "Reset" command to the Motoron, which does a full hardware reset.
370 This command
is equivalent to briefly driving the Motoron
's RST pin low.
371 The Motoron's RST is briefly driven low by the Motoron itself as a
372 result of this command.
374 After running this command, we recommend waiting for at least 5
375 milliseconds before you
try to communicate
with the Motoron.
377 \param ignore_nack Optional argument:
if `
True` (the default), this method
378 ignores a NACK error
if it occurs on sending the Reset command. This
is
379 useful
in case the Motoron has CRC off
and executes the reset before it
380 can ACK the CRC byte (which this method always sends to make it more
388 self._send_command_core(cmd,
True)
393 if not (ignore_nack
and (e.args[0] == 5
or e.args[0] == 121)):
raise
398 Reads information from the Motoron using a
"Get variables" command.
400 This library has helper methods to read every variable, but this method
401 is useful
if you want to get the raw bytes,
or if you want to read
402 multiple consecutive variables at the same time
for efficiency.
404 \param motor 0 to read general variables,
or a motor number to read
405 motor-specific variables.
406 \param offset The location of the first byte to read.
407 \param length How many bytes to read.
419 Reads one byte from the Motoron using a
"Get variables" command
420 and returns the result
as an unsigned 8-bit integer.
422 \param motor 0 to read a general variable,
or a motor number to read
423 a motor-specific variable.
424 \param offset The location of the byte to read.
430 Reads two bytes from the Motoron using a
"Get variables" command
431 and returns the result
as an unsigned 16-bit integer.
433 \param motor 0 to read general variables,
or a motor number to read
434 motor-specific variables.
435 \param offset The location of the first byte to read.
438 return struct.unpack(
'<H', buffer)[0]
442 Reads two bytes from the Motoron using a
"Get variables" command
443 and returns the result
as a signed 16-bit integer.
445 \param motor 0 to read general variables,
or a motor number to read
446 motor-specific variables.
447 \param offset The location of the first byte to read.
450 return struct.unpack(
'<h', buffer)[0]
454 Reads the "Status flags" variable
from the Motoron.
456 The bits
in this variable are defined by the STATUS_FLAGS_*
457 constants
in the motoron package:
459 - motoron.STATUS_FLAG_PROTOCOL_ERROR
460 - motoron.STATUS_FLAG_CRC_ERROR
461 - motoron.STATUS_FLAG_COMMAND_TIMEOUT_LATCHED
462 - motoron.STATUS_FLAG_MOTOR_FAULT_LATCHED
463 - motoron.STATUS_FLAG_NO_POWER_LATCHED
464 - motoron.STATUS_FLAG_RESET
465 - motoron.STATUS_FLAG_COMMAND_TIMEOUT
466 - motoron.STATUS_FLAG_MOTOR_FAULTING
467 - motoron.STATUS_FLAG_NO_POWER
468 - motoron.STATUS_FLAG_ERROR_ACTIVE
469 - motoron.STATUS_FLAG_MOTOR_OUTPUT_ENABLED
470 - motoron.STATUS_FLAG_MOTOR_DRIVING
472 Here
is some example code that uses bitwise operators to check
473 whether there
is currently a motor fault
or a lack of power:
476 mask = ((1 << motoron.STATUS_FLAG_NO_POWER) |
477 (1 << motoron.STATUS_FLAG_MOTOR_FAULTING))
478 if mc.get_status_flags() & mask:
481 This library has helper methods that make it easier
if you just want to
498 latched status flags to their default values.
500 For more information, see the
"Status flags" variable
in the Motoron
509 For more information, see the
"Status flags" variable
in the Motoron
518 For more information, see the
"Status flags" variable
in the Motoron
527 For more information, see the
"Status flags" variable
in the Motoron
536 For more information, see the
"Status flags" variable
in the Motoron
545 For more information, see the
"Status flags" variable
in the Motoron
554 This bit
is set to 1 when the Motoron powers on, its processor
is
558 By default, the Motoron
is configured to treat this bit
as an error,
559 so you will need to clear it before you can turn on the motors.
561 For more information, see the
"Status flags" variable
in the Motoron
570 For more information, see the
"Status flags" variable
in the Motoron
579 For more information, see the
"Status flags" variable
in the Motoron
588 For more information, see the
"Status flags" variable
in the Motoron
597 For more information, see the
"Status flags" variable
in the Motoron
606 For more information, see the
"Status flags" variable
in the Motoron
613 Reads voltage on the Motoron's VIN pin, in raw device units.
615 For more information, see the "VIN voltage" variable
in the Motoron
624 Reads the voltage on the Motoron's VIN pin and converts it to millivolts.
626 For more information, see the "VIN voltage" variable
in the Motoron
629 \param reference_mv Optional argument that specifies the reference voltage
630 (voltage on the 3V3 pin), in millivolts. This
is assumed to be 3300 by
631 default, but you can provide a different value
for a more accurate
633 \param type Specifies what type of Motoron you are using. This should be one
638 scale = 459 if enum_value(type) & 1
else 1047
643 Reads the "Command timeout" variable
and converts it to milliseconds.
645 For more information, see the
"Command timeout" variable
in the Motoron
654 Reads the "Error response" variable, which defines how the Motoron will
655 stop its motors when an error
is happening.
657 For more information, see the
"Error response" variable
in the Motoron
666 Reads the "Error mask" variable, which defines which status flags are
667 considered to be errors.
669 For more information, see the
"Error mask" variable
in the Motoron
678 Reads the "Jumper state" variable.
680 For more information, see the
"Jumper state" variable
in the Motoron
687 Reads the target speed of the specified motor, which is the speed at
688 which the motor has been commanded to move.
690 For more information, see the
"Target speed" variable
in the Motoron
699 Reads the target brake amount for the specified motor.
701 For more information, see the
"Target speed" variable
in the Motoron
704 \sa set_target_brake_amount()
710 Reads the current speed of the specified motor, which is the speed that
711 the Motoron
is currently trying to apply to the motor.
713 For more information, see the
"Target speed" variable
in the Motoron
722 Reads the buffered speed of the specified motor.
724 For more information, see the "Buffered speed" variable
in the Motoron
733 Reads the PWM mode of the specified motor.
735 For more information, see the "PWM mode" variable
in the Motoron
744 Reads the maximum acceleration of the specified motor for the forward
747 For more information, see the
"Max acceleration forward" variable
in the
748 Motoron user
's guide.
756 Reads the maximum acceleration of the specified motor for the reverse
759 For more information, see the
"Max acceleration reverse" variable
in the
760 Motoron user
's guide.
768 Reads the maximum deceleration of the specified motor for the forward
771 For more information, see the
"Max deceleration forward" variable
in the
772 Motoron user
's guide.
780 Reads the maximum deceleration of the specified motor for the reverse
783 For more information, see the
"Max deceleration reverse" variable
in the
784 Motoron user
's guide.
794 def get_max_deceleration_temporary(self, motor):
801 Reads the starting speed for the specified motor
in the forward direction.
803 For more information, see the
"Starting speed forward" variable
in the
804 Motoron user
's guide.
812 Reads the starting speed for the specified motor
in the reverse direction.
814 For more information, see the
"Starting speed reverse" variable
in the
815 Motoron user
's guide.
823 Reads the direction change delay for the specified motor
in the
826 For more information, see the
"Direction change delay forward" variable
827 in the Motoron user
's guide.
835 Reads the direction change delay for the specified motor
in the
838 For more information, see the
"Direction change delay reverse" variable
839 in the Motoron user
's guide.
847 Reads the current limit for the specified motor.
849 This only works
for the high-power Motorons.
851 For more information, see the
"Current limit" variable
in the Motoron user
's
860 Reads all the results from the last current sense measurement
for the
863 This function reads the
"Current sense raw",
"Current sense speed",
and
864 "Current sense processed" variables
from the Motoron using a single
865 command, so the values returned are all guaranteed to be part of the
868 This only works
for the high-power Motorons.
873 raw, speed, processed = struct.unpack('<HhH', buffer)
874 return {
'raw': raw,
'speed': speed,
'processed': processed }
879 sense measurement
and the speed.
881 This only works
for the high-power Motorons.
884 raw, speed = struct.unpack('<Hh', buffer)
885 return {
'raw': raw,
'speed': speed }
890 current sense measurement
and the speed.
892 This only works
for the high-power Motorons.
895 speed, processed = struct.unpack('<hH', buffer)
896 return {
'speed': speed,
'processed': processed }
900 Reads the raw current sense measurement for the specified motor.
902 This only works
for the high-power Motorons.
904 For more information, see the
"Current sense raw" variable
905 in the Motoron user
's guide.
914 Reads the processed current sense reading for the specified motor.
916 This only works
for the high-power Motorons.
918 The units of this reading depend on the logic voltage of the Motoron
919 and on the specific model of Motoron that you have,
and you can use
920 current_sense_units_milliamps() to calculate the units.
922 The accuracy of this reading can be improved by measuring the current
924 See the
"Current sense processed" variable
in the Motoron user
's guide for
925 or the current_sense_calibrate example
for more information.
927 Note that this reading will be 0xFFFF
if an overflow happens during the
928 calculation due to very high current.
936 Reads the current sense offset setting.
938 This only works for the high-power Motorons.
940 For more information, see the
"Current sense offset" variable
in the
941 Motoron user
's guide.
949 Reads the current sense minimum divisor setting and returns it
as a speed
952 This only works
for the high-power Motorons.
954 For more information, see the
"Current sense minimum divisor" variable
in
955 the Motoron user
's guide.
964 Configures the Motoron using a "Set variable" command.
966 This library has helper methods to set every variable, so you should
967 not need to call this function directly.
969 \param motor 0 to set a general variable,
or a motor number to set
970 motor-specific variables.
971 \param offset The address of the variable to set (only certain offsets
973 \param value The value to set the variable to.
977 if value > 0x3FFF: value = 0x3FFF
989 Sets the command timeout period, in milliseconds.
991 For more information, see the
"Command timeout" variable
992 in the Motoron user
's guide.
997 timeout = math.ceil(ms / 4)
1002 Sets the error response, which defines how the Motoron will
1003 stop its motors when an error is happening.
1005 The response parameter should be one of these constants
from the motoron
1008 - motoron.ERROR_RESPONSE_COAST
1009 - motoron.ERROR_RESPONSE_BRAKE
1010 - motoron.ERROR_RESPONSE_COAST_NOW
1011 - motoron.ERROR_RESPONSE_BRAKE_NOW
1013 For more information, see the
"Error response" variable
in the Motoron
1022 Sets the "Error mask" variable, which defines which status flags are
1023 considered to be errors.
1025 For more information, see the
"Error mask" variable
in the Motoron
1034 This disables the Motoron's command timeout feature by resetting the
1035 the "Error mask" variable to its default value but
with the command
1036 timeout bit cleared.
1038 By default, the Motoron
's command timeout will occur if no valid commands
1039 are received in 1500 milliseconds,
and the command timeout
is treated
as
1040 an error, so the motors will shut down. You can use this function
if you
1041 want to disable that feature.
1043 Note that this function overrides any previous values you set
in the
1044 "Error mask" variable, so
if you are using
set_error_mask()
in your program
1045 to configure which status flags are treated
as errors, you do
not need to
1046 use this function
and you probably should
not use this function.
1054 Sets the PWM mode for the specified motor.
1056 The mode parameter should be one of the following these constants
from
1057 the motoron package:
1059 - motoron.PWM_MODE_DEFAULT (20 kHz)
1060 - motoron.PWM_MODE_1_KHZ 1
1061 - motoron.PWM_MODE_2_KHZ 2
1062 - motoron.PWM_MODE_4_KHZ 3
1063 - motoron.PWM_MODE_5_KHZ 4
1064 - motoron.PWM_MODE_10_KHZ 5
1065 - motoron.PWM_MODE_20_KHZ 6
1066 - motoron.PWM_MODE_40_KHZ 7
1067 - motoron.PWM_MODE_80_KHZ 8
1069 For more information, see the
"PWM mode" variable
in the Motoron user
's
1078 Sets the maximum acceleration of the specified motor for the forward
1081 For more information, see the
"Max acceleration forward" variable
in the
1082 Motoron user
's guide.
1090 Sets the maximum acceleration of the specified motor for the reverse
1093 For more information, see the
"Max acceleration reverse" variable
in the
1094 Motoron user
's guide.
1102 Sets the maximum acceleration of the specified motor (both directions).
1104 If this function succeeds, it is equivalent to calling
1112 Sets the maximum deceleration of the specified motor for the forward
1115 For more information, see the
"Max deceleration forward" variable
in the
1116 Motoron user
's guide.
1124 Sets the maximum deceleration of the specified motor for the reverse
1127 For more information, see the
"Max deceleration reverse" variable
in the
1128 Motoron user
's guide.
1136 Sets the maximum deceleration of the specified motor (both directions).
1138 If this function succeeds, it is equivalent to calling
1146 Sets the starting speed of the specified motor for the forward
1149 For more information, see the
"Starting speed forward" variable
in the
1150 Motoron user
's guide.
1158 Sets the starting speed of the specified motor for the reverse
1161 For more information, see the
"Starting speed reverse" variable
in the
1162 Motoron user
's guide.
1170 Sets the starting speed of the specified motor (both directions).
1172 If this function succeeds, it is equivalent to calling
1180 Sets the direction change delay of the specified motor for the forward
1181 direction,
in units of 10 ms.
1183 For more information, see the
"Direction change delay forward" variable
1184 in the Motoron user
's guide.
1192 Sets the direction change delay of the specified motor for the reverse
1193 direction,
in units of 10 ms.
1195 For more information, see the
"Direction change delay reverse" variable
1196 in the Motoron user
's guide.
1204 Sets the direction change delay of the specified motor (both directions),
1207 If this function succeeds, it
is equivalent to calling
1215 Sets the current limit for the specified motor.
1217 This only works
for the high-power Motorons.
1219 The units of the current limit depend on the type of Motoron you have
1220 and the logic voltage of your system. See the
"Current limit" variable
1221 in the Motoron user
's guide for more information, or see
1222 calculate_current_limit().
1230 Sets the current sense offset setting for the specified motor.
1232 This
is one of the settings that determines how current sense
1233 readings are processed. It
is supposed to be the value returned by
1235 it
is driving its motor outputs at speed 0.
1237 The current_sense_calibrate example shows how to measure the current
1238 sense offsets
and load them onto the Motoron using this function.
1240 If you do
not care about measuring motor current, you do
not need to
1243 For more information, see the
"Current sense offset" variable
in the
1244 Motoron user
's guide.
1246 This only works for the high-power Motorons.
1254 Sets the current sense minimum divisor setting for the specified motor,
1255 given a speed between 0
and 800.
1257 This
is one of the settings that determines how current sense
1258 readings are processed.
1260 If you do
not care about measuring motor current, you do
not need to
1263 For more information, see the
"Current sense minimum divisor" variable
in
1264 the Motoron user
's guide.
1266 This only works for the high-power Motorons.
1274 Sends a "Coast now" command to the Motoron, causing all of the motors to
1275 immediately start coasting.
1277 For more information, see the
"Coast now" command
in the Motoron
1280 cmd = [CMD_COAST_NOW]
1285 Sends a "Clear motor fault" command to the Motoron.
1287 If any of the Motoron
's motors chips are currently experiencing a
1288 fault (error), or bit 0 of the flags argument
is 1, this command makes
1289 the Motoron attempt to recover
from the faults.
1291 For more information, see the
"Clear motor fault" command
in the Motoron
1296 cmd = [ CMD_CLEAR_MOTOR_FAULT, (flags & 0x7F) ]
1301 Sends a "Clear motor fault" command to the Motoron
with the
1302 "unconditional" flag set, so the Motoron will attempt to recover
1303 from any motor faults even
if no fault
is currently occurring.
1313 For each bit
in the flags argument that
is 1, this command clears the
1314 corresponding bit
in the
"Status flags" variable, setting it to 0.
1316 For more information, see the
"Clear latched status flags" command
in the
1317 Motoron user
's guide.
1322 CMD_CLEAR_LATCHED_STATUS_FLAGS,
1324 (flags >> 7) & 0x7F,
1330 Clears the Motoron's reset flag.
1333 particularly important to clear: it gets set to 1 after the Motoron
1334 powers on
or experiences a reset,
and it
is considered to be an error
1335 by default, so it prevents the motors
from running. Therefore, it
is
1337 the Reset flag before you can get the motors running.
1339 We recommend that immediately after you clear the reset flag. you should
1340 configure the Motoron
's motor settings and error response settings.
1341 That way, if the Motoron experiences an unexpected reset
while your system
1342 is running, it will stop running its motors
and it will
not start them
1343 again until all the important settings have been configured.
1353 For each bit
in the flags argument that
is 1, this command sets the
1354 corresponding bit
in the
"Status flags" variable to 1.
1356 For more information, see the
"Set latched status flags" command
in the
1357 Motoron user
's guide.
1362 CMD_SET_LATCHED_STATUS_FLAGS,
1364 (flags >> 7) & 0x7F,
1370 Sets the target speed of the specified motor.
1372 The current speed will start moving to the specified target speed,
1373 obeying any acceleration and deceleration limits.
1375 The motor number should be between 1
and the number of motors supported
1378 The speed should be between -800
and 800. Values outside that range
1379 will be clipped to -800
or 800 by the Motoron firmware.
1381 For more information, see the
"Set speed" command
in the Motoron
1390 (speed >> 7) & 0x7F,
1396 Sets the target and current speed of the specified motor, ignoring
1397 any acceleration
and deceleration limits.
1399 For more information, see the
"Set speed" command
in the Motoron
1408 (speed >> 7) & 0x7F,
1414 Sets the buffered speed of the specified motor.
1416 This command does not immediately cause any change to the motor: it
1417 stores a speed
for the specified motor
in the Motoron so it can be
1418 used by later commands.
1420 For more information, see the
"Set speed" command
in the Motoron
1427 CMD_SET_BUFFERED_SPEED,
1430 (speed >> 7) & 0x7F,
1436 Sets the target speeds of all the motors at the same time.
1438 The number of speed arguments you provide to this function must be equal
1439 to the number of motor channels your Motoron has, or else this command
1442 This
is equivalent to calling
set_speed() once
for each motor, but it
is
1443 more efficient because all of the speeds are sent
in the same command.
1445 There are a few different ways you can call this method (
and the related
1446 methods that set speeds
for all the motors):
1450 mc.set_all_speeds(100, -200, 300)
1453 speeds = [-400, 500, -600]
1454 mc.set_all_speeds(*speeds)
1457 For more information, see the
"Set all speeds" command
in the Motoron
1462 cmd = [CMD_SET_ALL_SPEEDS]
1463 for speed
in speeds:
1466 (speed >> 7) & 0x7F,
1472 Sets the target and current speeds of all the motors at the same time.
1474 The number of speed arguments you provide to this function must be equal
1475 to the number of motor channels your Motoron has,
or else this command
1478 This
is equivalent to calling
set_speed_now() once
for each motor, but it
is
1479 more efficient because all of the speeds are sent
in the same command.
1481 For more information, see the
"Set all speeds" command
in the Motoron
1486 cmd = [CMD_SET_ALL_SPEEDS_NOW]
1487 for speed
in speeds:
1490 (speed >> 7) & 0x7F,
1496 Sets the buffered speeds of all the motors.
1498 The number of speed arguments you provide to this function must be equal
1499 to the number of motor channels your Motoron has, or else this command
1502 This command does
not immediately cause any change to the motors: it
1503 stores speed
for each motor
in the Motoron so they can be used by later
1506 For more information, see the
"Set all speeds" command
in the Motoron
1512 cmd = [CMD_SET_ALL_BUFFERED_SPEEDS]
1513 for speed
in speeds:
1516 (speed >> 7) & 0x7F,
1522 Sets each motor's target speed equal to the buffered speed.
1524 This command is the same
as set_all_speeds()
except that the speeds are
1530 cmd = [CMD_SET_ALL_SPEEDS_USING_BUFFERS]
1535 Sets each motor's target speed and current speed equal to the buffered
1544 cmd = [CMD_SET_ALL_SPEEDS_NOW_USING_BUFFERS]
1549 Commands the motor to brake, coast, or something
in between.
1551 Sending this command causes the motor to decelerate to speed 0 obeying
1552 any relevant deceleration limits. Once the current speed reaches 0, the
1553 motor will attempt to brake
or coast
as specified by this command, but
1554 due to hardware limitations it might
not be able to.
1556 The motor number parameter should be between 1
and the number of motors
1557 supported by the Motoron.
1559 The amount parameter gets stored
in the
"Target brake amount" variable
1560 for the motor
and should be between 0 (coasting)
and 800 (braking).
1561 Values above 800 will be clipped to 800 by the Motoron firmware.
1563 See the
"Set braking" command
in the Motoron user
's guide for more
1572 (amount >> 7) & 0x7F,
1578 Commands the motor to brake, coast, or something
in between.
1580 Sending this command causes the motor
's current speed to change to 0.
1581 The motor will attempt to brake or coast
as specified by this command,
1582 but due to hardware limitations it might
not be able to.
1584 The motor number parameter should be between 1
and the number of motors
1585 supported by the Motoron.
1587 The amount parameter gets stored
in the
"Target brake amount" variable
1588 for the motor
and should be between 0 (coasting)
and 800 (braking).
1589 Values above 800 will be clipped to 800 by the Motoron firmware.
1591 See the
"Set braking" command
in the Motoron user
's guide for more
1597 CMD_SET_BRAKING_NOW,
1600 (amount >> 7) & 0x7F,
1606 Resets the command timeout.
1608 This prevents the command timeout status flags from getting set
for some
1609 time. (The command timeout
is also reset by every other Motoron command,
1610 as long
as its parameters are valid.)
1612 For more information, see the
"Reset command timeout" command
in the
1613 Motoron user
's guide.
1617 cmd = [CMD_RESET_COMMAND_TIMEOUT]
1620 def _send_command(self, cmd):
1621 send_crc = bool(self.
protocol_options & (1 << PROTOCOL_OPTION_CRC_FOR_COMMANDS))
1622 self._send_command_core(cmd, send_crc)
1624 def _send_command_and_read_response(self, cmd, response_length):
1626 return self._read_response(response_length)
1628def calculate_current_limit(milliamps, type, reference_mv, offset):
1630 Calculates a current limit value that can be passed to the Motoron
1633 \param milliamps The desired current limit, in units of mA.
1634 \param type Specifies what type of Motoron you are using. This should be one
1636 \param reference_mv The reference voltage (IOREF),
in millivolts.
1637 For example, use 3300
for a 3.3 V system
or 5000
for a 5 V system.
1638 \param offset The offset of the raw current sense signal
for the Motoron
1639 channel. This
is the same measurement that you would put into the
1640 Motoron
's "Current sense offset" variable using set_current_sense_offset(),
1641 so see the documentation of that function for more info.
1642 The offset
is typically 10
for 5 V systems
and 15
for 3.3 V systems,
1643 (50*1024/reference_mv) but it can vary widely.
1645 if milliamps > 1000000: milliamps = 1000000
1646 limit = offset * 125 / 128 + milliamps * 20 / (reference_mv * (enum_value(type) & 3))
1647 if limit > 1000: limit = 1000
1648 return math.floor(limit)
1650def current_sense_units_milliamps(type, reference_mv):
1652 Calculates the units for the Motoron
's current sense reading returned by
1656 multiply it by the value returned
from this function.
1658 \param type Specifies what type of Motoron you are using. This should be one
1660 \param reference_mv The reference voltage (IOREF),
in millivolts.
1661 For example, use 3300
for a 3.3 V system
or 5000
for a 5 V system.
1663 return reference_mv * (enum_value(type) & 3) * 25 / 512
1667 Represents an I2C connection to a Pololu Motoron Motor Controller.
1672 Creates a new MotoronI2C object to communicate with the Motoron over I2C.
1674 \param bus Optional argument that specifies which I2C bus to use.
1675 This can be an integer, an SMBus object
from the smbus2 package,
or an
1676 object
with an interface similar to SMBus.
1677 The default bus
is 1, which corresponds to `/dev/i2c-1`.
1678 \param address Optional argument that specifies the 7-bit I2C address to
1679 use. This must match the address that the Motoron
is configured to use.
1680 The default address
is 16.
1690 Configures this object to use the specified I2C bus object.
1692 The bus argument should be one of the following:
1693 - The number of an I2C bus to open with smbus2
1694 (e.g. 2
for `/dev/i2c-2`)
1695 - An SMBus object
from smbus2.
1696 - A machine.I2C object
from MicroPython.
1698 def set_bus(self, bus):
1699 if isinstance(bus, int):
1701 bus = smbus2.SMBus(bus)
1705 type_is_smbus =
True
1706 except AttributeError:
1707 type_is_smbus =
False
1713 self.
_msg = smbus2.i2c_msg
1720 def _smbus_send_command_core(self, cmd, send_crc):
1722 write = self.
_msg.write(self.
address, cmd + [calculate_crc(cmd)])
1725 self.
bus.i2c_rdwr(write)
1727 def _smbus_read_response(self, length):
1733 crc_enabled = bool(self.
protocol_options & (1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
1734 read = self.
_msg.read(self.
address, length + crc_enabled)
1735 self.
bus.i2c_rdwr(read)
1736 response = bytes(read)
1739 response = response[:-1]
1740 if crc != calculate_crc(response):
1741 raise RuntimeError(
'Incorrect CRC received.')
1744 def _mpy_send_command_core(self, cmd, send_crc):
1746 self.
bus.writeto(self.
address, bytes(cmd + [calculate_crc(cmd)]))
1750 def _mpy_read_response(self, length):
1751 crc_enabled = bool(self.
protocol_options & (1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
1752 response = self.
bus.readfrom(self.
address, length + crc_enabled)
1755 response = response[:-1]
1756 if crc != calculate_crc(response):
1757 raise RuntimeError(
'Incorrect CRC received.')
1763 Represents a serial connection to a Pololu Motoron Motor Controller.
1768 Creates a new MotoronSerial object.
1770 The `deviceNumber` argument is optional. If it
is omitted
or None,
1771 the object will use the compact protocol.
1773 The `port` argument specifies the serial port to use
and is passed
1798 Configures this object to use the specified serial port object.
1800 The port argument should be one of the following:
1801 - The name of a serial port to open with pyserial
1802 (e.g.
"COM6" or "/dev/ttyS0")
1803 - A Serial object
from pyserial.
1804 - A machine.UART object
from MicroPython.
1806 if isinstance(port, str):
1808 self.
port = serial.Serial(port, 115200, timeout=0.1, write_timeout=0.1)
1815 Configures this object to work with Motorons that are configured to send
1816 7-bit serial responses.
1822 Configures this object to work with Motorons that are configured to send
1823 responses
in the normal 8-bit format.
1829 Configures this object to send 14-bit device numbers when using the
1830 Pololu protocol, instead of the default 7-bit.
1836 Configures this object to send 7-bit device numbers, which is the default.
1842 Sends a "Multi-device error check" command but does
not read any
1845 Note: Before using this, most users should make sure the MotoronSerial
1846 object
is configured to use the compact protocol: construct the object
1847 without specifying a device number,
or set device_number to
None.
1850 if device_count < 0
or device_count > 0x3FFF:
1851 raise RuntimeError(
'Invalid device count.')
1853 CMD_MULTI_DEVICE_ERROR_CHECK,
1854 starting_device_number & 0x7F,
1855 starting_device_number >> 7 & 0x7F,
1856 device_count & 0x7F,
1857 device_count >> 7 & 0x7F,
1860 if device_count < 0
or device_count > 0x7F:
1861 raise RuntimeError(
'Invalid device count.')
1863 CMD_MULTI_DEVICE_ERROR_CHECK,
1864 starting_device_number & 0x7F,
1873 Sends a "Multi-device error check" command
and reads the responses.
1875 This function assumes that each addressed Motoron can see the responses
1876 sent by the other Motorons (e.g. they are
in a half-duplex RS-485 network).
1878 Returns the number of devices that indicated they have no errors.
1879 If the
return value
is less than device count, you can add the
return
1880 value to the starting_device_number to get the device number of the
1881 first device where the check failed. This device either did
not
1882 respond
or it responded
with an indication that it has an error,
or an
1883 unexpected byte was received
for some reason.
1885 Note: Before using this, most users should make sure the MotoronSerial
1886 object
is configured to use the compact protocol: construct the object
1887 without specifying a device number,
or set device_number to
None.
1890 responses = self.port.read(device_count)
1891 for i, v
in enumerate(responses):
1892 if v != ERROR_CHECK_CONTINUE:
return i
1893 return len(responses)
1896 command_byte, data):
1898 Sends a "Multi-device write" command.
1900 Note: Before using this, most users should make sure the MotoronSerial
1901 object
is configured to use the compact protocol: construct the object
1902 without specifying a device number,
or call setDeviceNumber
with an
1907 if device_count < 0
or device_count > 0x3FFF:
1908 raise RuntimeError(
'Invalid device count.')
1910 CMD_MULTI_DEVICE_WRITE,
1911 starting_device_number & 0x7F,
1912 starting_device_number >> 7 & 0x7F,
1913 device_count & 0x7F,
1914 device_count >> 7 & 0x7F,
1917 if device_count < 0
or device_count > 0x7F:
1918 raise RuntimeError(
'Invalid device count.')
1920 CMD_MULTI_DEVICE_WRITE,
1921 starting_device_number & 0x7F,
1925 if data ==
None: data = []
1926 if len(data) % device_count:
1927 raise RuntimeError(
"Expected data length to be a multiple of " \
1928 f
"{device_count}, got {len(data)}.")
1929 bytes_per_device = len(data) // device_count
1930 if bytes_per_device > 15:
raise RuntimeError(
'Data too long.')
1932 cmd += [bytes_per_device, command_byte & 0x7F]
1937 def _send_command_core(self, cmd, send_crc):
1953 if send_crc: cmd += [calculate_crc(cmd)]
1955 self.
port.write(bytes(cmd))
1957 def _read_response(self, length):
1958 crc_enabled = bool(self.
protocol_options & (1 << PROTOCOL_OPTION_CRC_FOR_RESPONSES))
1961 if response_7bit
and length > 7:
1962 raise RuntimeError(
'The Motoron does not support response payloads ' \
1963 'longer than 7 bytes in 7-bit response mode.')
1966 read_length = length + response_7bit + crc_enabled
1967 response = self.
port.read(read_length)
1968 if response
is None: response = b
''
1969 if len(response) != read_length:
1970 raise RuntimeError(f
"Expected to read {read_length} bytes, got {len(response)}.")
1974 response = response[:-1]
1975 if crc != calculate_crc(response):
1976 raise RuntimeError(
'Incorrect CRC received.')
1980 response = bytearray(response[:-1])
1981 for i
in range(length):
1982 if msbs & 1: response[i] |= 0x80
1984 response = bytes(response)
Represents a connection to a Pololu Motoron Motoron Controller.
def enable_crc_for_commands(self)
Enables CRC for commands.
def disable_i2c_general_call(self)
Disables the I2C general call address.
def set_starting_speed_reverse(self, motor, speed)
Sets the starting speed of the specified motor for the reverse direction.
def set_max_acceleration_forward(self, motor, accel)
Sets the maximum acceleration of the specified motor for the forward direction.
def enable_crc(self)
Enables CRC for commands and responses.
def get_max_acceleration_forward(self, motor)
Reads the maximum acceleration of the specified motor for the forward direction.
def set_direction_change_delay_reverse(self, motor, duration)
Sets the direction change delay of the specified motor for the reverse direction, in units of 10 ms.
def set_starting_speed(self, motor, speed)
Sets the starting speed of the specified motor (both directions).
def get_motor_output_enabled_flag(self)
Returns the "Motor output enabled" bit from get_status_flags().
def set_max_acceleration_reverse(self, motor, accel)
Sets the maximum acceleration of the specified motor for the reverse direction.
def get_current_sense_raw_and_speed(self, motor)
This is like get_current_sense_reading() but it only reads the raw current sense measurement and the ...
def get_target_brake_amount(self, motor)
Reads the target brake amount for the specified motor.
def get_current_sense_offset(self, motor)
Reads the current sense offset setting.
def get_command_timeout_milliseconds(self)
Reads the "Command timeout" variable and converts it to milliseconds.
def write_eeprom_baud_rate(self, baud)
Writes to the baud rate stored in EEPROM, changing it to the specified value.
def write_eeprom(self, offset, value)
Writes a value to one byte in the Motoron's EEPROM memory.
def set_max_deceleration_reverse(self, motor, decel)
Sets the maximum deceleration of the specified motor for the reverse direction.
def clear_latched_status_flags(self, flags)
Clears the specified flags in get_status_flags().
def write_eeprom_alternative_device_number(self, number)
Writes to the alternative device number stored in EEPROM, changing it to the specified value.
def set_max_acceleration(self, motor, accel)
Sets the maximum acceleration of the specified motor (both directions).
def set_variable(self, motor, offset, value)
Configures the Motoron using a "Set variable" command.
def set_buffered_speed(self, motor, speed)
Sets the buffered speed of the specified motor.
def get_jumper_state(self)
Reads the "Jumper state" variable.
def get_crc_error_flag(self)
Returns the "CRC error" bit from get_status_flags().
def set_current_sense_offset(self, motor, offset)
Sets the current sense offset setting for the specified motor.
def set_protocol_options(self, options)
Sends the "Set protocol options" command to the device to specify options related to how the device p...
def set_latched_status_flags(self, flags)
Sets the specified flags in get_status_flags().
def get_current_limit(self, motor)
Reads the current limit for the specified motor.
def enable_i2c_general_call(self)
Enables the I2C general call address.
def write_eeprom_communication_options(self, options)
Writes to the serial options byte stored in EEPROM, changing it to the specified value.
def enable_crc_for_responses(self)
Enables CRC for responses.
def get_no_power_latched_flag(self)
Returns the "No power latched" bit from get_status_flags().
def clear_reset_flag(self)
Clears the Motoron's reset flag.
def read_eeprom(self, offset, length)
Reads the specified bytes from the Motoron's EEPROM memory.
def disable_crc_for_responses(self)
Disables CRC for responses.
def disable_command_timeout(self)
This disables the Motoron's command timeout feature by resetting the the "Error mask" variable to its...
def set_error_mask(self, mask)
Sets the "Error mask" variable, which defines which status flags are considered to be errors.
def get_current_speed(self, motor)
Reads the current speed of the specified motor, which is the speed that the Motoron is currently tryi...
def get_status_flags(self)
Reads the "Status flags" variable from the Motoron.
def get_error_mask(self)
Reads the "Error mask" variable, which defines which status flags are considered to be errors.
def get_vin_voltage_mv(self, reference_mv=3300, type=VinSenseType.MOTORON_256)
Reads the voltage on the Motoron's VIN pin and converts it to millivolts.
def get_buffered_speed(self, motor)
Reads the buffered speed of the specified motor.
def get_vin_voltage(self)
Reads voltage on the Motoron's VIN pin, in raw device units.
def set_braking_now(self, motor, amount)
Commands the motor to brake, coast, or something in between.
def clear_motor_fault(self, flags=0)
Sends a "Clear motor fault" command to the Motoron.
def set_all_speeds_now_using_buffers(self)
Sets each motor's target speed and current speed equal to the buffered speed.
def set_command_timeout_milliseconds(self, ms)
Sets the command timeout period, in milliseconds.
def get_current_sense_minimum_divisor(self, motor)
Reads the current sense minimum divisor setting and returns it as a speed between 0 and 800.
def get_direction_change_delay_reverse(self, motor)
Reads the direction change delay for the specified motor in the reverse direction.
def get_command_timeout_latched_flag(self)
Returns the "Command timeout latched" bit from get_status_flags().
def get_max_acceleration_reverse(self, motor)
Reads the maximum acceleration of the specified motor for the reverse direction.
def _send_command_and_read_response(self, cmd, response_length)
def set_current_limit(self, motor, limit)
Sets the current limit for the specified motor.
def coast_now(self)
Sends a "Coast now" command to the Motoron, causing all of the motors to immediately start coasting.
def get_max_deceleration_reverse(self, motor)
Reads the maximum deceleration of the specified motor for the reverse direction.
def clear_motor_fault_unconditional(self)
Sends a "Clear motor fault" command to the Motoron with the "unconditional" flag set,...
def write_eeprom_response_delay(self, delay)
Writes to the serial response delay setting stored in EEPROM, changing it to the specified value,...
def get_variables(self, motor, offset, length)
Reads information from the Motoron using a "Get variables" command.
def set_error_response(self, response)
Sets the error response, which defines how the Motoron will stop its motors when an error is happenin...
def get_var_u16(self, motor, offset)
Reads two bytes from the Motoron using a "Get variables" command and returns the result as an unsigne...
def get_error_response(self)
Reads the "Error response" variable, which defines how the Motoron will stop its motors when an error...
def get_firmware_version(self)
Sends the "Get firmware version" command to get the device's firmware product ID and firmware version...
def get_starting_speed_reverse(self, motor)
Reads the starting speed for the specified motor in the reverse direction.
def set_all_speeds_using_buffers(self)
Sets each motor's target speed equal to the buffered speed.
def reinitialize(self)
Sends a "Reinitialize" command to the Motoron, which resets most of the Motoron's variables to their ...
def write_eeprom_disable_alternative_device_number(self)
Writes to EEPROM to disable the alternative device number.
def get_current_sense_reading(self, motor)
Reads all the results from the last current sense measurement for the specified motor.
def write_eeprom_device_number(self, number)
Writes to the EEPROM device number, changing it to the specified value.
def get_error_active_flag(self)
Returns the "Error active" bit from get_status_flags().
def reset(self, ignore_nack=True)
Sends a "Reset" command to the Motoron, which does a full hardware reset.
def get_starting_speed_forward(self, motor)
Reads the starting speed for the specified motor in the forward direction.
def set_starting_speed_forward(self, motor, speed)
Sets the starting speed of the specified motor for the forward direction.
def get_current_sense_raw(self, motor)
Reads the raw current sense measurement for the specified motor.
def set_direction_change_delay(self, motor, duration)
Sets the direction change delay of the specified motor (both directions), in units of 10 ms.
def get_target_speed(self, motor)
Reads the target speed of the specified motor, which is the speed at which the motor has been command...
protocol_options
The bits in this variable are defined by the motoron.PROTOCOL_OPTION_* constants.
def read_eeprom_device_number(self)
Reads the EEPROM device number from the device.
def set_max_deceleration_forward(self, motor, decel)
Sets the maximum deceleration of the specified motor for the forward direction.
def get_protocol_error_flag(self)
Returns the "Protocol error" bit from get_status_flags().
def set_pwm_mode(self, motor, mode)
Sets the PWM mode for the specified motor.
def get_var_s16(self, motor, offset)
Reads two bytes from the Motoron using a "Get variables" command and returns the result as a signed 1...
def reset_command_timeout(self)
Resets the command timeout.
def set_braking(self, motor, amount)
Commands the motor to brake, coast, or something in between.
def get_direction_change_delay_forward(self, motor)
Reads the direction change delay for the specified motor in the forward direction.
def set_max_deceleration(self, motor, decel)
Sets the maximum deceleration of the specified motor (both directions).
def get_no_power_flag(self)
Returns the "No power" bit from get_status_flags().
def set_all_speeds(self, *speeds)
Sets the target speeds of all the motors at the same time.
def get_current_sense_processed_and_speed(self, motor)
This is like get_current_sense_reading() but it only reads the processed current sense measurement an...
def set_all_speeds_now(self, *speeds)
Sets the target and current speeds of all the motors at the same time.
def get_pwm_mode(self, motor)
Reads the PWM mode of the specified motor.
def write_eeprom16(self, offset, value)
Writes a 2-byte value in the Motoron's EEPROM memory.
def get_reset_flag(self)
Returns the "Reset" bit from get_status_flags().
def set_speed(self, motor, speed)
Sets the target speed of the specified motor.
def set_protocol_options_locally(self, options)
Sets the protocol options for this object, without sending a command to the Motoron.
def _send_command(self, cmd)
def get_motor_fault_latched_flag(self)
Returns the "Motor fault latched" bit from get_status_flags().
def disable_crc(self)
Disables CRC for commands and responses.
def get_motor_faulting_flag(self)
Returns the "Motor faulting" bit from get_status_flags().
def set_direction_change_delay_forward(self, motor, duration)
Sets the direction change delay of the specified motor for the forward direction, in units of 10 ms.
def get_max_deceleration_forward(self, motor)
Reads the maximum deceleration of the specified motor for the forward direction.
def disable_crc_for_commands(self)
Disables CRC for commands.
def set_all_buffered_speeds(self, *speeds)
Sets the buffered speeds of all the motors.
def set_speed_now(self, motor, speed)
Sets the target and current speed of the specified motor, ignoring any acceleration and deceleration ...
def get_var_u8(self, motor, offset)
Reads one byte from the Motoron using a "Get variables" command and returns the result as an unsigned...
def get_current_sense_processed(self, motor)
Reads the processed current sense reading for the specified motor.
def set_current_sense_minimum_divisor(self, motor, speed)
Sets the current sense minimum divisor setting for the specified motor, given a speed between 0 and 8...
def get_motor_driving_flag(self)
Returns the "Motor driving" bit from get_status_flags().
Represents an I2C connection to a Pololu Motoron Motor Controller.
def _mpy_read_response(self, length)
def _smbus_read_response(self, length)
def _mpy_send_command_core(self, cmd, send_crc)
address
The 7-bit I2C address used by this object.
def __init__(self, *bus=1, address=16)
Creates a new MotoronI2C object to communicate with the Motoron over I2C.
def _smbus_send_command_core(self, cmd, send_crc)
Represents a serial connection to a Pololu Motoron Motor Controller.
def set_port(self, port)
Configures this object to use the specified serial port object.
def expect_7bit_responses(self)
Configures this object to work with Motorons that are configured to send 7-bit serial responses.
device_number
The device number that will be included in commands sent by this object.
def multi_device_error_check_start(self, starting_device_number, device_count)
Sends a "Multi-device error check" command but does not read any responses.
def use_14bit_device_number(self)
Configures this object to send 14-bit device numbers when using the Pololu protocol,...
port
The serial port used by this object.
def multi_device_write(self, starting_device_number, device_count, command_byte, data)
Sends a "Multi-device write" command.
communication_options
The serial options used by this object.
def expect_8bit_responses(self)
Configures this object to work with Motorons that are configured to send responses in the normal 8-bi...
def __init__(self, *port=None, device_number=None)
Creates a new MotoronSerial object.
def use_7bit_device_number(self)
Configures this object to send 7-bit device numbers, which is the default.
def multi_device_error_check(self, starting_device_number, device_count)
Sends a "Multi-device error check" command and reads the responses.