20#include "motoron_protocol.h"
24extern const PROGMEM uint8_t motoronCrcTable[256];
31 Motoron18v18 = 0b0001,
32 Motoron24v14 = 0b0101,
33 Motoron18v20 = 0b1010,
34 Motoron24v16 = 0b1101,
88 uint8_t cmd = MOTORON_CMD_GET_FIRMWARE_VERSION;
91 if (productId !=
nullptr) { *productId = response[0] | (response[1] << 8); }
92 if (firmwareVersion !=
nullptr) { *firmwareVersion = response[2] | (response[3] << 8); }
138 MOTORON_CMD_SET_PROTOCOL_OPTIONS,
139 (uint8_t)(options & 0x7F),
140 (uint8_t)(~options & 0x7F),
142 sendCommandCore(
sizeof(cmd), cmd,
true);
170 | (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS)
171 | (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES));
178 & ~(1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS)
179 & ~(1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES));
186 | (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS));
193 & ~(1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS));
200 | (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES));
207 & ~(1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES));
214 | (1 << MOTORON_PROTOCOL_OPTION_I2C_GENERAL_CALL));
221 & ~(1 << MOTORON_PROTOCOL_OPTION_I2C_GENERAL_CALL));
228 void readEeprom(uint8_t offset, uint8_t length, uint8_t * buffer)
231 MOTORON_CMD_READ_EEPROM,
232 (uint8_t)(offset & 0x7F),
233 (uint8_t)(length & 0x7F),
245 readEeprom(MOTORON_SETTING_DEVICE_NUMBER, 1, &number);
262 cmd[0] = MOTORON_CMD_WRITE_EEPROM;
263 cmd[1] = offset & 0x7F;
264 cmd[2] = value & 0x7F;
265 cmd[3] = value >> 7 & 1;
266 cmd[4] = cmd[1] ^ 0x7F;
267 cmd[5] = cmd[2] ^ 0x7F;
268 cmd[6] = cmd[3] ^ 0x7F;
297 writeEeprom(MOTORON_SETTING_DEVICE_NUMBER, number & 0x7F);
298 writeEeprom(MOTORON_SETTING_DEVICE_NUMBER + 1, number >> 7 & 0x7F);
314 writeEeprom(MOTORON_SETTING_ALTERNATIVE_DEVICE_NUMBER, (number & 0x7F) | 0x80);
315 writeEeprom(MOTORON_SETTING_ALTERNATIVE_DEVICE_NUMBER + 1, number >> 7 & 0x7F);
330 writeEeprom(MOTORON_SETTING_ALTERNATIVE_DEVICE_NUMBER, 0);
331 writeEeprom(MOTORON_SETTING_ALTERNATIVE_DEVICE_NUMBER + 1, 0);
348 writeEeprom(MOTORON_SETTING_COMMUNICATION_OPTIONS, options);
362 if (baud < MOTORON_MIN_BAUD_RATE) { baud = MOTORON_MIN_BAUD_RATE; }
363 if (baud > MOTORON_MAX_BAUD_RATE) { baud = MOTORON_MAX_BAUD_RATE; }
364 writeEeprom16(MOTORON_SETTING_BAUD_DIVIDER, (16000000 + (baud >> 1)) / baud);
378 writeEeprom(MOTORON_SETTING_RESPONSE_DELAY, delay);
391 uint8_t cmd = MOTORON_CMD_REINITIALIZE;
392 sendCommandCore(1, &cmd,
true);
408 uint8_t cmd = MOTORON_CMD_RESET;
409 sendCommandCore(1, &cmd,
true);
426 void getVariables(uint8_t motor, uint8_t offset, uint8_t length, uint8_t * buffer)
429 MOTORON_CMD_GET_VARIABLES,
430 (uint8_t)(motor & 0x7F),
431 (uint8_t)(offset & 0x7F),
432 (uint8_t)(length & 0x7F),
442 uint8_t
getVar8(uint8_t motor, uint8_t offset)
458 return buffer[0] | ((uint16_t)buffer[1] << 8);
511 return getVar16(0, MOTORON_VAR_STATUS_FLAGS);
520 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_PROTOCOL_ERROR);
538 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_COMMAND_TIMEOUT_LATCHED);
547 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_MOTOR_FAULT_LATCHED);
556 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_NO_POWER_LATCHED);
596 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_MOTOR_FAULTING);
614 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_ERROR_ACTIVE);
623 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_MOTOR_OUTPUT_ENABLED);
632 return getStatusFlags() & (1 << MOTORON_STATUS_FLAG_MOTOR_DRIVING);
657 return getVar8(0, MOTORON_VAR_UART_FAULTS);
668 return getVar16(0, MOTORON_VAR_VIN_VOLTAGE);
684 uint16_t scale = (uint8_t)type & 1 ? 459 : 1047;
685 return (uint32_t)
getVinVoltage() * referenceMv / 1024 * scale / 47;
696 return getVar16(0, MOTORON_VAR_COMMAND_TIMEOUT) * 4;
708 return getVar8(0, MOTORON_VAR_ERROR_RESPONSE);
720 return getVar16(0, MOTORON_VAR_ERROR_MASK);
729 return getVar8(0, MOTORON_VAR_JUMPER_STATE);
741 return getVar16(motor, MOTORON_MVAR_TARGET_SPEED);
752 return getVar16(motor, MOTORON_MVAR_TARGET_BRAKE_AMOUNT);
764 return getVar16(motor, MOTORON_MVAR_CURRENT_SPEED);
775 return getVar16(motor, MOTORON_MVAR_BUFFERED_SPEED);
786 return getVar8(motor, MOTORON_MVAR_PWM_MODE);
798 return getVar16(motor, MOTORON_MVAR_MAX_ACCEL_FORWARD);
810 return getVar16(motor, MOTORON_MVAR_MAX_ACCEL_REVERSE);
822 return getVar16(motor, MOTORON_MVAR_MAX_DECEL_FORWARD);
834 return getVar16(motor, MOTORON_MVAR_MAX_DECEL_REVERSE);
840 uint16_t getMaxDecelerationTemporary(uint8_t motor)
842 return getVar16(motor, MOTORON_MVAR_MAX_DECEL_TMP);
855 return getVar16(motor, MOTORON_MVAR_STARTING_SPEED_FORWARD);
866 return getVar16(motor, MOTORON_MVAR_STARTING_SPEED_REVERSE);
878 return getVar8(motor, MOTORON_MVAR_DIRECTION_CHANGE_DELAY_FORWARD);
890 return getVar8(motor, MOTORON_MVAR_DIRECTION_CHANGE_DELAY_REVERSE);
903 return getVar16(motor, MOTORON_MVAR_CURRENT_LIMIT);
920 getVariables(motor, MOTORON_MVAR_CURRENT_SENSE_RAW,
sizeof(buffer), buffer);
922 r.raw = buffer[0] | ((uint16_t)buffer[1] << 8);
923 r.speed = buffer[2] | ((uint16_t)buffer[3] << 8);
924 r.processed = buffer[4] | ((uint16_t)buffer[5] << 8);
937 getVariables(motor, MOTORON_MVAR_CURRENT_SENSE_RAW,
sizeof(buffer), buffer);
939 r.raw = buffer[0] | ((uint16_t)buffer[1] << 8);
940 r.speed = buffer[2] | ((uint16_t)buffer[3] << 8);
953 getVariables(motor, MOTORON_MVAR_CURRENT_SENSE_SPEED,
sizeof(buffer), buffer);
955 r.speed = buffer[0] | ((uint16_t)buffer[1] << 8);
956 r.processed = buffer[2] | ((uint16_t)buffer[3] << 8);
970 return getVar16(motor, MOTORON_MVAR_CURRENT_SENSE_RAW);
992 return getVar16(motor, MOTORON_MVAR_CURRENT_SENSE_PROCESSED);
1005 return getVar8(motor, MOTORON_MVAR_CURRENT_SENSE_OFFSET);
1019 return getVar8(motor, MOTORON_MVAR_CURRENT_SENSE_MINIMUM_DIVISOR) << 2;
1036 if (value > 0x3FFF) { value = 0x3FFF; }
1038 MOTORON_CMD_SET_VARIABLE,
1039 (uint8_t)(motor & 0x1F),
1040 (uint8_t)(offset & 0x7F),
1041 (uint8_t)(value & 0x7F),
1042 (uint8_t)((value >> 7) & 0x7F),
1057 uint16_t timeout = (ms / 4) + ((ms & 3) ? 1 : 0);
1058 setVariable(0, MOTORON_VAR_COMMAND_TIMEOUT, timeout);
1077 setVariable(0, MOTORON_VAR_ERROR_RESPONSE, response);
1109 setErrorMask(defaultErrorMask & ~(1 << MOTORON_STATUS_FLAG_COMMAND_TIMEOUT));
1122 setVariable(0, MOTORON_VAR_UART_FAULTS, ~(uint16_t)flags & 0x3FFF);
1157 setVariable(motor, MOTORON_MVAR_MAX_ACCEL_FORWARD, accel);
1169 setVariable(motor, MOTORON_MVAR_MAX_ACCEL_REVERSE, accel);
1192 setVariable(motor, MOTORON_MVAR_MAX_DECEL_FORWARD, decel);
1204 setVariable(motor, MOTORON_MVAR_MAX_DECEL_REVERSE, decel);
1227 setVariable(motor, MOTORON_MVAR_STARTING_SPEED_FORWARD, speed);
1239 setVariable(motor, MOTORON_MVAR_STARTING_SPEED_REVERSE, speed);
1262 setVariable(motor, MOTORON_MVAR_DIRECTION_CHANGE_DELAY_FORWARD, duration);
1274 setVariable(motor, MOTORON_MVAR_DIRECTION_CHANGE_DELAY_REVERSE, duration);
1301 setVariable(motor, MOTORON_MVAR_CURRENT_LIMIT, limit);
1325 setVariable(motor, MOTORON_MVAR_CURRENT_SENSE_OFFSET, offset);
1345 setVariable(motor, MOTORON_MVAR_CURRENT_SENSE_MINIMUM_DIVISOR, speed >> 2);
1355 uint8_t cmd = MOTORON_CMD_COAST_NOW;
1371 uint8_t cmd[] = { MOTORON_CMD_CLEAR_MOTOR_FAULT, (uint8_t)(flags & 0x7F) };
1396 uint8_t cmd[] = { MOTORON_CMD_CLEAR_LATCHED_STATUS_FLAGS,
1397 (uint8_t)(flags & 0x7F),
1398 (uint8_t)(flags >> 7 & 0x7F)
1435 uint8_t cmd[] = { MOTORON_CMD_SET_LATCHED_STATUS_FLAGS,
1436 (uint8_t)(flags & 0x7F),
1437 (uint8_t)(flags >> 7 & 0x7F)
1463 MOTORON_CMD_SET_SPEED,
1464 (uint8_t)(motor & 0x7F),
1465 (uint8_t)(speed & 0x7F),
1466 (uint8_t)((speed >> 7) & 0x7F),
1484 MOTORON_CMD_SET_SPEED_NOW,
1485 (uint8_t)(motor & 0x7F),
1486 (uint8_t)(speed & 0x7F),
1487 (uint8_t)((speed >> 7) & 0x7F),
1509 MOTORON_CMD_SET_BUFFERED_SPEED,
1510 (uint8_t)(motor & 0x7F),
1511 (uint8_t)(speed & 0x7F),
1512 (uint8_t)((speed >> 7) & 0x7F),
1534 MOTORON_CMD_SET_ALL_SPEEDS,
1535 (uint8_t)(speed1 & 0x7F),
1536 (uint8_t)((speed1 >> 7) & 0x7F),
1537 (uint8_t)(speed2 & 0x7F),
1538 (uint8_t)((speed2 >> 7) & 0x7F),
1539 (uint8_t)(speed3 & 0x7F),
1540 (uint8_t)((speed3 >> 7) & 0x7F),
1549 MOTORON_CMD_SET_ALL_SPEEDS,
1550 (uint8_t)(speed1 & 0x7F),
1551 (uint8_t)((speed1 >> 7) & 0x7F),
1552 (uint8_t)(speed2 & 0x7F),
1553 (uint8_t)((speed2 >> 7) & 0x7F),
1562 MOTORON_CMD_SET_ALL_SPEEDS,
1563 (uint8_t)(speed1 & 0x7F),
1564 (uint8_t)((speed1 >> 7) & 0x7F),
1585 MOTORON_CMD_SET_ALL_SPEEDS_NOW,
1586 (uint8_t)(speed1 & 0x7F),
1587 (uint8_t)((speed1 >> 7) & 0x7F),
1588 (uint8_t)(speed2 & 0x7F),
1589 (uint8_t)((speed2 >> 7) & 0x7F),
1590 (uint8_t)(speed3 & 0x7F),
1591 (uint8_t)((speed3 >> 7) & 0x7F),
1600 MOTORON_CMD_SET_ALL_SPEEDS_NOW,
1601 (uint8_t)(speed1 & 0x7F),
1602 (uint8_t)((speed1 >> 7) & 0x7F),
1603 (uint8_t)(speed2 & 0x7F),
1604 (uint8_t)((speed2 >> 7) & 0x7F),
1613 MOTORON_CMD_SET_ALL_SPEEDS_NOW,
1614 (uint8_t)(speed1 & 0x7F),
1615 (uint8_t)((speed1 >> 7) & 0x7F),
1642 MOTORON_CMD_SET_ALL_BUFFERED_SPEEDS,
1643 (uint8_t)(speed1 & 0x7F),
1644 (uint8_t)((speed1 >> 7) & 0x7F),
1645 (uint8_t)(speed2 & 0x7F),
1646 (uint8_t)((speed2 >> 7) & 0x7F),
1647 (uint8_t)(speed3 & 0x7F),
1648 (uint8_t)((speed3 >> 7) & 0x7F),
1657 MOTORON_CMD_SET_ALL_BUFFERED_SPEEDS,
1658 (uint8_t)(speed1 & 0x7F),
1659 (uint8_t)((speed1 >> 7) & 0x7F),
1660 (uint8_t)(speed2 & 0x7F),
1661 (uint8_t)((speed2 >> 7) & 0x7F),
1670 MOTORON_CMD_SET_ALL_BUFFERED_SPEEDS,
1671 (uint8_t)(speed1 & 0x7F),
1672 (uint8_t)((speed1 >> 7) & 0x7F),
1686 uint8_t cmd = MOTORON_CMD_SET_ALL_SPEEDS_USING_BUFFERS;
1700 uint8_t cmd = MOTORON_CMD_SET_ALL_SPEEDS_NOW_USING_BUFFERS;
1725 MOTORON_CMD_SET_BRAKING,
1726 (uint8_t)(motor & 0x7F),
1727 (uint8_t)(amount & 0x7F),
1728 (uint8_t)((amount >> 7) & 0x7F),
1753 MOTORON_CMD_SET_BRAKING_NOW,
1754 (uint8_t)(motor & 0x7F),
1755 (uint8_t)(amount & 0x7F),
1756 (uint8_t)((amount >> 7) & 0x7F),
1773 uint8_t cmd = MOTORON_CMD_RESET_COMMAND_TIMEOUT;
1785 for (uint8_t i = 0; i < length; i++)
1787 crc = pgm_read_byte(&motoronCrcTable[crc ^ buffer[i]]);
1818 if (milliamps > 1000000) { milliamps = 1000000; }
1819 uint16_t limit = (uint32_t)(offset * 125 + 64) / 128 +
1820 milliamps * 20 / (referenceMv * ((uint8_t)type & 3));
1821 if (limit > 1000) { limit = 1000; }
1840 return ((uint32_t)referenceMv * ((uint8_t)type & 3) * 25 / 512);
1855 bool sendCrc =
protocolOptions & (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS);
1856 sendCommandCore(length, cmd, sendCrc);
1862 uint8_t responseLength, uint8_t * response)
1867 memset(response, 0, responseLength);
1870 readResponse(responseLength, response);
1875 virtual void sendCommandCore(uint8_t length,
const uint8_t * cmd,
bool sendCrc) = 0;
1876 virtual void flushTransmission() = 0;
1877 virtual void readResponse(uint8_t length, uint8_t * response) = 0;
1879 static const uint8_t defaultProtocolOptions =
1880 (1 << MOTORON_PROTOCOL_OPTION_I2C_GENERAL_CALL) |
1881 (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS) |
1882 (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES);
1884 static const uint16_t defaultErrorMask =
1885 (1 << MOTORON_STATUS_FLAG_COMMAND_TIMEOUT) |
1886 (1 << MOTORON_STATUS_FLAG_RESET);
1897 MotoronI2C(uint8_t address = 16) : bus(&Wire), address(address) {}
1922 this->address = address;
1935 void sendCommandCore(uint8_t length,
const uint8_t * cmd,
bool sendCrc)
override
1937 bus->beginTransmission(address);
1938 for (uint8_t i = 0; i < length; i++)
1949 void flushTransmission() { }
1951 void readResponse(uint8_t length, uint8_t * response)
override
1953 bool crcEnabled =
protocolOptions & (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES);
1954 uint8_t byteCount = bus->requestFrom(address, (uint8_t)(length + crcEnabled));
1955 if (byteCount != length + crcEnabled)
1957 memset(response, 0, length);
1962 uint8_t * ptr = response;
1963 for (uint8_t i = 0; i < length; i++)
1968 if (crcEnabled && bus->read() !=
calculateCrc(length, response))
1998 port(nullptr), deviceNumber(deviceNumber), communicationOptions(0)
2005 port(&port), deviceNumber(deviceNumber), communicationOptions(0)
2040 this->deviceNumber = deviceNumber;
2049 return deviceNumber;
2066 communicationOptions = options;
2075 return communicationOptions;
2086 communicationOptions |= (1 << MOTORON_COMMUNICATION_OPTION_7BIT_RESPONSES);
2093 communicationOptions &= ~(1 << MOTORON_COMMUNICATION_OPTION_7BIT_RESPONSES);
2104 communicationOptions |= (1 << MOTORON_COMMUNICATION_OPTION_14BIT_DEVICE_NUMBER);
2111 communicationOptions &= ~(1 << MOTORON_COMMUNICATION_OPTION_14BIT_DEVICE_NUMBER);
2123 if (communicationOptions & (1 << MOTORON_COMMUNICATION_OPTION_14BIT_DEVICE_NUMBER))
2125 if (deviceCount > 0x3FFF) {
lastError = 55;
return; }
2127 MOTORON_CMD_MULTI_DEVICE_ERROR_CHECK,
2128 (uint8_t)(startingDeviceNumber & 0x7F),
2129 (uint8_t)(startingDeviceNumber >> 7 & 0x7F),
2130 (uint8_t)(deviceCount & 0x7F),
2131 (uint8_t)(deviceCount >> 7 & 0x7F),
2137 if (deviceCount > 0x7F) {
lastError = 55;
return; }
2139 MOTORON_CMD_MULTI_DEVICE_ERROR_CHECK,
2140 (uint8_t)(startingDeviceNumber & 0x7F),
2141 (uint8_t)deviceCount,
2168 for (i = 0; i < deviceCount; i++)
2171 size_t byteCount = port->readBytes(&response, 1);
2172 if (byteCount < 1 || response != MOTORON_ERROR_CHECK_CONTINUE)
2187 uint8_t bytesPerDevice, uint8_t commandByte,
const uint8_t * data)
2189 if (port ==
nullptr) {
lastError = 52;
return; }
2190 if (bytesPerDevice > 15) {
lastError = 56;
return; }
2192 bool sendCrc =
protocolOptions & (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS);
2194 uint8_t header[10] = { 0 };
2195 if (communicationOptions & (1 << MOTORON_COMMUNICATION_OPTION_14BIT_DEVICE_NUMBER))
2197 if (deviceCount > 0x3FFF) {
lastError = 55;
return; }
2199 header[4] = startingDeviceNumber & 0x7F;
2200 header[5] = startingDeviceNumber >> 7 & 0x7F;
2201 header[6] = deviceCount & 0x7F;
2202 header[7] = deviceCount >> 7 & 0x7F;
2203 header[8] = bytesPerDevice;
2204 header[9] = commandByte & 0x7F;
2206 if (deviceNumber == 0xFFFF)
2208 header[3] = MOTORON_CMD_MULTI_DEVICE_WRITE;
2209 port->write(header + 3, 7);
2214 header[1] = deviceNumber & 0x7F;
2215 header[2] = deviceNumber >> 7 & 0x7F;
2216 header[3] = MOTORON_CMD_MULTI_DEVICE_WRITE & 0x7F;
2217 port->write(header, 10);
2222 if (deviceCount > 0x7F) {
lastError = 55;
return; }
2224 header[6] = startingDeviceNumber & 0x7F;
2225 header[7] = deviceCount;
2226 header[8] = bytesPerDevice;
2227 header[9] = commandByte & 0x7F;
2229 if (deviceNumber == 0xFFFF)
2231 header[5] = MOTORON_CMD_MULTI_DEVICE_WRITE;
2232 port->write(header + 5, 5);
2237 header[4] = deviceNumber & 0x7F;
2238 header[5] = MOTORON_CMD_MULTI_DEVICE_WRITE & 0x7F;
2239 port->write(header + 3, 7);
2244 if (sendCrc) { crc =
calculateCrc(
sizeof(header), header); }
2250 port->write(data, bytesPerDevice);
2251 if (sendCrc) { crc =
calculateCrc(bytesPerDevice, data, crc); }
2252 data += bytesPerDevice;
2257 if (sendCrc) { port->write(crc); }
2262 uint16_t deviceNumber;
2263 uint8_t communicationOptions;
2265 void sendCommandCore(uint8_t length,
const uint8_t * cmd,
bool sendCrc)
override
2267 if (port ==
nullptr) {
lastError = 52;
return; }
2269 if (deviceNumber == 0xFFFF)
2271 port->write(cmd, length);
2280 if (communicationOptions & (1 << MOTORON_COMMUNICATION_OPTION_14BIT_DEVICE_NUMBER))
2283 header[1] = deviceNumber & 0x7F;
2284 header[2] = deviceNumber >> 7 & 0x7F;
2285 header[3] = cmd[0] & 0x7F;
2286 port->write(header, 4);
2292 header[2] = deviceNumber & 0x7F;
2293 header[3] = cmd[0] & 0x7F;
2294 port->write(header + 1, 3);
2296 port->write(cmd + 1, length - 1);
2307 void flushTransmission()
2309 if (port ==
nullptr) {
return; }
2313 void readResponse(uint8_t length, uint8_t * response)
override
2315 if (port ==
nullptr)
2318 memset(response, 0, length);
2322 bool response7Bit = communicationOptions & (1 << MOTORON_COMMUNICATION_OPTION_7BIT_RESPONSES);
2323 if (response7Bit && length > 7)
2329 memset(response, 0, length);
2335 size_t byteCount = port->readBytes(response, length);
2336 if (byteCount != length)
2339 memset(response, 0, length);
2346 if (port->readBytes(&msbs, 1) != 1)
2353 bool crcEnabled =
protocolOptions & (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES);
2357 if (port->readBytes(&crc, 1) != 1)
2369 if (crc != expected_crc)
2378 for (uint8_t i = 0; i < length; i++)
2380 if (msbs & 1) { response[i] |= 0x80; }
@ Motoron550
M*550 Motorons.
@ MotoronHp
High-power Motorons.
@ Motoron256
M*256 Motorons.
void setDirectionChangeDelay(uint8_t motor, uint8_t duration)
void setCommandTimeoutMilliseconds(uint16_t ms)
uint16_t getMaxAccelerationForward(uint8_t motor)
uint16_t getCurrentLimit(uint8_t motor)
int16_t getBufferedSpeed(uint8_t motor)
void setErrorResponse(uint8_t response)
void setBraking(uint8_t motor, uint16_t amount)
int16_t getTargetSpeed(uint8_t motor)
uint16_t getMaxDecelerationForward(uint8_t motor)
bool getMotorDrivingFlag()
void clearUARTFaults(uint8_t flags)
void writeEepromAlternativeDeviceNumber(uint16_t number)
uint16_t getTargetBrakeAmount(uint8_t motor)
uint16_t getMaxAccelerationReverse(uint8_t motor)
uint8_t getErrorResponse()
void setErrorMask(uint16_t mask)
void writeEepromDeviceNumber(uint16_t number)
void setMaxDeceleration(uint8_t motor, uint16_t decel)
void setVariable(uint8_t motor, uint8_t offset, uint16_t value)
uint16_t getStartingSpeedReverse(uint8_t motor)
void enableI2cGeneralCall()
Enables the I2C general call address. See setProtocolOptions().
void setAllBufferedSpeeds(int16_t speed1, int16_t speed2)
An overload of setAllBufferedSpeeds() for 2-channel Motorons.
uint16_t getMaxDecelerationReverse(uint8_t motor)
uint16_t getVar16(uint8_t motor, uint8_t offset)
MotoronCurrentSenseReading getCurrentSenseReading(uint8_t motor)
void writeEeprom(uint8_t offset, uint8_t value)
void enableCrcForCommands()
Enables CRC for commands. See setProtocolOptions().
static uint8_t calculateCrc(uint8_t length, const uint8_t *buffer, uint8_t init=0)
void setCurrentSenseMinimumDivisor(uint8_t motor, uint16_t speed)
void disableCrc()
Disables CRC for commands and responses. See setProtocolOptions().
void setAllSpeedsUsingBuffers()
void setAllBufferedSpeeds(int16_t speed1, int16_t speed2, int16_t speed3)
uint8_t getCurrentSenseOffset(uint8_t motor)
uint16_t getCommandTimeoutMilliseconds()
uint32_t getVinVoltageMv(uint16_t referenceMv, MotoronVinSenseType type=MotoronVinSenseType::Motoron256)
void disableCrcForResponses()
Disables CRC for responses. See setProtocolOptions().
void setBufferedSpeed(uint8_t motor, int16_t speed)
void setStartingSpeedForward(uint8_t motor, uint16_t speed)
void setMaxAccelerationForward(uint8_t motor, uint16_t accel)
void getVariables(uint8_t motor, uint8_t offset, uint8_t length, uint8_t *buffer)
bool getMotorFaultLatchedFlag()
void setMaxAccelerationReverse(uint8_t motor, uint16_t accel)
void disableCrcForCommands()
Disables CRC for commands. See setProtocolOptions().
void enableCrcForResponses()
Enables CRC for responses. See setProtocolOptions().
uint16_t getStatusFlags()
void clearMotorFaultUnconditional()
void writeEepromDisableAlternativeDeviceNumber()
bool getCommandTimeoutLatchedFlag()
uint8_t getPwmMode(uint8_t motor)
void setProtocolOptionsLocally(uint8_t options)
uint8_t readEepromDeviceNumber()
uint8_t getDirectionChangeDelayForward(uint8_t motor)
uint8_t getDirectionChangeDelayReverse(uint8_t motor)
void setAllBufferedSpeeds(int16_t speed1)
An overload of setAllBufferedSpeeds() for 1-channel Motorons.
void setDirectionChangeDelayReverse(uint8_t motor, uint8_t duration)
void setPwmMode(uint8_t motor, uint8_t mode)
void setCurrentLimit(uint8_t motor, uint16_t limit)
void sendCommandAndReadResponse(uint8_t cmdLength, const uint8_t *cmd, uint8_t responseLength, uint8_t *response)
void disableI2cGeneralCall()
Disables the I2C general call address. See setProtocolOptions().
void setAllSpeeds(int16_t speed1, int16_t speed2, int16_t speed3)
uint8_t protocolOptions
See setProtocolOptions.
bool getProtocolErrorFlag()
void resetCommandTimeout()
void setLatchedStatusFlags(uint16_t flags)
uint8_t getProtocolOptionsLocally()
void getFirmwareVersion(uint16_t *productId, uint16_t *firmwareVersion)
void setAllSpeedsNow(int16_t speed1, int16_t speed2, int16_t speed3)
void setAllSpeeds(int16_t speed1)
An overload of setAllSpeeds() for single-channel Motorons.
void setMaxDecelerationReverse(uint8_t motor, uint16_t decel)
void setStartingSpeed(uint8_t motor, uint16_t speed)
void clearLatchedStatusFlags(uint16_t flags)
void setMaxDecelerationForward(uint8_t motor, uint16_t decel)
static constexpr uint16_t currentSenseUnitsMilliamps(MotoronCurrentSenseType type, uint16_t referenceMv)
MotoronCurrentSenseReading getCurrentSenseProcessedAndSpeed(uint8_t motor)
bool getMotorOutputEnabledFlag()
uint16_t getCurrentSenseRaw(uint8_t motor)
void setCurrentSenseOffset(uint8_t motor, uint8_t offset)
void setMaxAcceleration(uint8_t motor, uint16_t accel)
bool getErrorActiveFlag()
void sendCommand(uint8_t length, const uint8_t *cmd)
void setStartingSpeedReverse(uint8_t motor, uint16_t speed)
uint16_t getStartingSpeedForward(uint8_t motor)
void writeEepromBaudRate(uint32_t baud)
void setAllSpeeds(int16_t speed1, int16_t speed2)
An overload of setAllSpeeds() for 2-channel Motorons.
void setAllSpeedsNowUsingBuffers()
bool getNoPowerLatchedFlag()
uint16_t getCurrentSenseMinimumDivisor(uint8_t motor)
void disableCommandTimeout()
void setDirectionChangeDelayForward(uint8_t motor, uint8_t duration)
uint8_t getVar8(uint8_t motor, uint8_t offset)
void writeEeprom16(uint8_t offset, uint16_t value)
void setAllSpeedsNow(int16_t speed1)
An overload of setAllSpeedsNow() for single-channel Motorons.
void setBrakingNow(uint8_t motor, uint16_t amount)
void enableCrc()
Enables CRC for commands and responses. See setProtocolOptions().
uint16_t getCurrentSenseProcessed(uint8_t motor)
void readEeprom(uint8_t offset, uint8_t length, uint8_t *buffer)
void setSpeed(uint8_t motor, int16_t speed)
void writeEepromResponseDelay(uint8_t delay)
bool getMotorFaultingFlag()
static uint16_t calculateCurrentLimit(uint32_t milliamps, MotoronCurrentSenseType type, uint16_t referenceMv, uint16_t offset)
void setSpeedNow(uint8_t motor, int16_t speed)
void setAllSpeedsNow(int16_t speed1, int16_t speed2)
An overload of setAllSpeedsNow() for 2-channel Motorons.
void setProtocolOptions(uint8_t options)
void clearMotorFault(uint8_t flags=0)
MotoronCurrentSenseReading getCurrentSenseRawAndSpeed(uint8_t motor)
int16_t getCurrentSpeed(uint8_t motor)
void writeEepromCommunicationOptions(uint8_t options)
Represents an I2C connection to a Motoron Motor Controller.
void setBus(TwoWire *bus)
void setAddress(uint8_t address)
MotoronI2C(uint8_t address=16)
uint8_t getAddress()
Returns the 7-bit I2C address that this object is configured to use.
void setCommunicationOptions(uint8_t options)
MotoronSerial(Stream &port, uint16_t deviceNumber=0xFFFF)
void use7BitDeviceNumber()
void expect8BitResponses()
uint16_t multiDeviceErrorCheck(uint16_t startingDeviceNumber, uint16_t deviceCount)
void multiDeviceWrite(uint16_t startingDeviceNumber, uint16_t deviceCount, uint8_t bytesPerDevice, uint8_t commandByte, const uint8_t *data)
void multiDeviceErrorCheckStart(uint16_t startingDeviceNumber, uint16_t deviceCount)
uint8_t getCommunicationOptionsLocally()
MotoronSerial(uint16_t deviceNumber=0xFFFF)
uint16_t getDeviceNumber()
void use14BitDeviceNumber()
void setPort(Stream *port)
void setDeviceNumber(uint16_t deviceNumber)
void expect7BitResponses()