36 FeedbackDisconnect = 5,
53 SetTargetLowResRev = 0xE0,
54 SetTargetLowResFwd = 0xE1,
55 ForceDutyCycleTarget = 0xF2,
56 ForceDutyCycle = 0xF4,
60 GetEEPROMSettings = 0xE3,
62 SetRAMSettings = 0xE6,
63 GetRAMSettings = 0xEA,
64 GetCurrentChoppingOccurrenceCount = 0xEC,
156 if (target > 4095) { target = 4095; }
157 commandW7((uint8_t)JrkG2Command::SetTarget | (target & 0x1F), target >> 5);
184 if (target > 127) { target = 127; }
185 commandW7(JrkG2Command::SetTargetLowResRev, target);
211 if (target > 127) { target = 127; }
212 commandW7(JrkG2Command::SetTargetLowResFwd, target);
240 if (dutyCycle > 600) { dutyCycle = 600; }
241 if (dutyCycle < -600) { dutyCycle = -600; }
242 commandWs14(JrkG2Command::ForceDutyCycleTarget, dutyCycle);
272 if (dutyCycle > 600) { dutyCycle = 600; }
273 if (dutyCycle < -600) { dutyCycle = -600; }
274 commandWs14(JrkG2Command::ForceDutyCycle, dutyCycle);
291 commandQuick(JrkG2Command::MotorOff);
314 return getVar16SingleByte(VarOffset::Input);
326 return getVar16SingleByte(VarOffset::Target);
343 return getVar16SingleByte(VarOffset::Feedback);
354 return getVar16SingleByte(VarOffset::ScaledFeedback);
365 return getVar16SingleByte(VarOffset::Integral);
386 return getVar16SingleByte(VarOffset::DutyCycleTarget);
402 return getVar16SingleByte(VarOffset::DutyCycle);
412 return getVar8SingleByte(VarOffset::CurrentLowRes);
422 return getVar8SingleByte(VarOffset::PIDPeriodExceeded);
430 return getVar16SingleByte(VarOffset::PIDPeriodCount);
456 return getVar16SingleByte(VarOffset::ErrorFlagsHalting);
485 return getVar16SingleByte(VarOffset::ErrorFlagsOccurred);
502 return (
JrkG2ForceMode)(getVar8SingleByte(VarOffset::FlagByte1) & 0x03);
513 return getVar16SingleByte(VarOffset::VinVoltage);
520 return getVar16SingleByte(VarOffset::Current);
534 return (
JrkG2Reset)getVar8(VarOffset::DeviceReset);
546 return getVar32(VarOffset::UpTime);
564 return getVar16(VarOffset::RCPulseWidth);
583 return getVar16(VarOffset::FBTReading);
607 return getVar16(VarOffset::AnalogReadingSDA);
609 return getVar16(VarOffset::AnalogReadingFBA);
630 uint8_t readings = getVar8(VarOffset::DigitalReadings);
631 return (readings >> (uint8_t)pin) & 1;
643 return getVar16(VarOffset::RawCurrent);
655 return getVar16(VarOffset::EncodedHardCurrentLimit);
666 return getVar16(VarOffset::LastDutyCycle);
675 return getVar8(VarOffset::CurrentChoppingConsecutiveCount);
690 return commandR8(JrkG2Command::GetCurrentChoppingOccurrenceCount);
715 uint8_t tmp = getRAMSetting8(SettingOffset::OptionsByte3);
716 if (getLastError()) {
return; }
719 tmp |= 1 << (uint8_t)JrkG2OptionsByte3::ResetIntegral;
723 tmp &= ~(1 << (uint8_t)JrkG2OptionsByte3::ResetIntegral);
725 setRAMSetting8(SettingOffset::OptionsByte3, tmp);
733 return getRAMSetting8(SettingOffset::OptionsByte3) >>
734 (uint8_t)JrkG2OptionsByte3::ResetIntegral & 1;
751 uint8_t tmp = getRAMSetting8(SettingOffset::OptionsByte3);
752 if (getLastError()) {
return; }
755 tmp |= 1 << (uint8_t)JrkG2OptionsByte3::CoastWhenOff;
759 tmp &= ~(1 << (uint8_t)JrkG2OptionsByte3::CoastWhenOff);
761 setRAMSetting8(SettingOffset::OptionsByte3, tmp);
769 return getRAMSetting8(SettingOffset::OptionsByte3) >>
770 (uint8_t)JrkG2OptionsByte3::CoastWhenOff & 1;
797 setPIDCoefficient(SettingOffset::ProportionalMultiplier, multiplier, exponent);
806 return getRAMSetting16(SettingOffset::ProportionalMultiplier);
815 return getRAMSetting8(SettingOffset::ProportionalExponent);
836 setPIDCoefficient(SettingOffset::IntegralMultiplier, multiplier, exponent);
845 return getRAMSetting16(SettingOffset::IntegralMultiplier);
854 return getRAMSetting8(SettingOffset::IntegralExponent);
875 setPIDCoefficient(SettingOffset::DerivativeMultiplier, multiplier, exponent);
884 return getRAMSetting16(SettingOffset::DerivativeMultiplier);
893 return getRAMSetting8(SettingOffset::DerivativeExponent);
910 setRAMSetting16(SettingOffset::PIDPeriod, period);
918 return getRAMSetting16(SettingOffset::PIDPeriod);
934 setRAMSetting16(SettingOffset::IntegralLimit, limit);
942 return getRAMSetting16(SettingOffset::IntegralLimit);
955 setRAMSetting16(SettingOffset::MaxDutyCycleWhileFeedbackOutOfRange, duty);
964 return getRAMSetting16(SettingOffset::MaxDutyCycleWhileFeedbackOutOfRange);
978 setRAMSetting16(SettingOffset::MaxAccelerationForward, accel);
987 return getRAMSetting16(SettingOffset::MaxAccelerationForward);
1001 setRAMSetting16(SettingOffset::MaxAccelerationReverse, accel);
1010 return getRAMSetting16(SettingOffset::MaxAccelerationReverse);
1024 setRAMSetting16x2(SettingOffset::MaxAccelerationForward, accel, accel);
1038 setRAMSetting16(SettingOffset::MaxDecelerationForward, decel);
1047 return getRAMSetting16(SettingOffset::MaxDecelerationForward);
1061 setRAMSetting16(SettingOffset::MaxDecelerationReverse, decel);
1070 return getRAMSetting16(SettingOffset::MaxDecelerationReverse);
1084 setRAMSetting16x2(SettingOffset::MaxDecelerationForward, decel, decel);
1097 setRAMSetting16(SettingOffset::MaxDutyCycleForward, duty);
1106 return getRAMSetting16(SettingOffset::MaxDutyCycleForward);
1119 setRAMSetting16(SettingOffset::MaxDutyCycleReverse, duty);
1128 return getRAMSetting16(SettingOffset::MaxDutyCycleReverse);
1141 setRAMSetting16x2(SettingOffset::MaxDutyCycleForward, duty, duty);
1158 setRAMSetting16(SettingOffset::EncodedHardCurrentLimitForward,
1171 return getRAMSetting16(SettingOffset::EncodedHardCurrentLimitForward);
1188 setRAMSetting16(SettingOffset::EncodedHardCurrentLimitReverse, encoded_limit);
1200 return getRAMSetting16(SettingOffset::EncodedHardCurrentLimitReverse);
1218 setRAMSetting16x2(SettingOffset::EncodedHardCurrentLimitForward,
1219 encoded_limit, encoded_limit);
1232 setRAMSetting8(SettingOffset::BrakeDurationForward, duration);
1241 return getRAMSetting8(SettingOffset::BrakeDurationForward);
1254 setRAMSetting8(SettingOffset::BrakeDurationReverse, duration);
1263 return getRAMSetting8(SettingOffset::BrakeDurationReverse);
1276 setRAMSetting8x2(SettingOffset::BrakeDurationForward, duration, duration);
1289 setRAMSetting16(SettingOffset::SoftCurrentLimitForward, current);
1298 return getRAMSetting16(SettingOffset::SoftCurrentLimitForward);
1311 setRAMSetting16(SettingOffset::SoftCurrentLimitReverse, current);
1320 return getRAMSetting16(SettingOffset::SoftCurrentLimitReverse);
1334 setRAMSetting16x2(SettingOffset::SoftCurrentLimitForward, current, current);
1359 segmentRead(JrkG2Command::GetEEPROMSettings, offset, length, buffer);
1381 segmentRead(JrkG2Command::GetRAMSettings, offset, length, buffer);
1406 segmentWrite(JrkG2Command::SetRAMSettings, offset, length, buffer);
1429 segmentRead(JrkG2Command::GetVariables, offset, length, buffer);
1437 uint8_t _lastError = 0;
1445 ScaledFeedback = 0x06,
1447 DutyCycleTarget = 0x0A,
1449 CurrentLowRes = 0x0E,
1450 PIDPeriodExceeded = 0x0F,
1451 PIDPeriodCount = 0x10,
1452 ErrorFlagsHalting = 0x12,
1453 ErrorFlagsOccurred = 0x14,
1464 RCPulseWidth = 0x24,
1466 AnalogReadingSDA = 0x28,
1467 AnalogReadingFBA = 0x2A,
1468 DigitalReadings = 0x2C,
1470 EncodedHardCurrentLimit = 0x2F,
1471 LastDutyCycle = 0x31,
1472 CurrentChoppingConsecutiveCount = 0x33,
1473 CurrentChoppingOccurrenceCount = 0x34,
1478 OptionsByte1 = 0x01,
1479 OptionsByte2 = 0x02,
1481 InputErrorMinimum = 0x04,
1482 InputErrorMaximum = 0x06,
1483 InputMinimum = 0x08,
1484 InputMaximum = 0x0A,
1485 InputNeutralMinimum = 0x0C,
1486 InputNeutralMaximum = 0x0E,
1487 OutputMinimum = 0x10,
1488 OutputNeutral = 0x12,
1489 OutputMaximum = 0x14,
1490 InputScalingDegree = 0x16,
1491 InputAnalogSamplesExponent = 0x17,
1492 FeedbackMode = 0x18,
1493 FeedbackErrorMinimum = 0x19,
1494 FeedbackErrorMaximum = 0x1B,
1495 FeedbackMinimum = 0x1D,
1496 FeedbackMaximum = 0x1F,
1497 FeedbackDeadZone = 0x21,
1498 FeedbackAnalogSamplesExponent = 0x22,
1500 SerialBaudRateGenerator = 0x24,
1501 SerialTimeout = 0x26,
1502 SerialDeviceNumber = 0x28,
1506 VinCalibration = 0x30,
1507 PwmFrequency = 0x32,
1508 CurrentSamplesExponent = 0x33,
1509 HardOvercurrentThreshold = 0x34,
1510 CurrentOffsetCalibration = 0x35,
1511 CurrentScaleCalibration = 0x37,
1514 FBTTimingTimeout = 0x3B,
1516 FBTDividerExponent = 0x3E,
1517 IntegralDividerExponent = 0x3F,
1518 SoftCurrentRegulationLevelForward = 0x40,
1519 SoftCurrentRegulationLevelReverse = 0x42,
1520 OptionsByte3 = 0x50,
1521 ProportionalMultiplier = 0x51,
1522 ProportionalExponent = 0x53,
1523 IntegralMultiplier = 0x54,
1524 IntegralExponent = 0x56,
1525 DerivativeMultiplier = 0x57,
1526 DerivativeExponent = 0x59,
1528 IntegralLimit = 0x5C,
1529 MaxDutyCycleWhileFeedbackOutOfRange = 0x5E,
1530 MaxAccelerationForward = 0x60,
1531 MaxAccelerationReverse = 0x62,
1532 MaxDecelerationForward = 0x64,
1533 MaxDecelerationReverse = 0x66,
1534 MaxDutyCycleForward = 0x68,
1535 MaxDutyCycleReverse = 0x6A,
1536 EncodedHardCurrentLimitForward = 0x6C,
1537 EncodedHardCurrentLimitReverse = 0x6E,
1538 BrakeDurationForward = 0x70,
1539 BrakeDurationReverse = 0x71,
1540 SoftCurrentLimitForward = 0x72,
1541 SoftCurrentLimitReverse = 0x74,
1544 uint8_t getVar8SingleByte(uint8_t offset)
1546 return commandR8((uint8_t)JrkG2Command::GetVariable8 | (offset + 1));
1549 uint16_t getVar16SingleByte(uint8_t offset)
1551 return commandR16((uint8_t)JrkG2Command::GetVariable16 | (offset + 1));
1554 uint8_t getVar8(uint8_t offset)
1557 segmentRead(JrkG2Command::GetVariables, offset, 1, &result);
1561 uint16_t getVar16(uint8_t offset)
1564 segmentRead(JrkG2Command::GetVariables, offset, 2, buffer);
1565 return ((uint16_t)buffer[0] << 0) | ((uint16_t)buffer[1] << 8);
1568 uint32_t getVar32(uint8_t offset)
1571 segmentRead(JrkG2Command::GetVariables, offset, 4, buffer);
1572 return ((uint32_t)buffer[0] << 0) |
1573 ((uint32_t)buffer[1] << 8) |
1574 ((uint32_t)buffer[2] << 16) |
1575 ((uint32_t)buffer[3] << 24);
1578 void setRAMSetting8(uint8_t offset, uint8_t val)
1580 segmentWrite(JrkG2Command::SetRAMSettings, offset, 1, &val);
1583 void setRAMSetting16(uint8_t offset, uint16_t val)
1585 uint8_t buffer[2] = {(uint8_t)val, (uint8_t)(val >> 8)};
1586 segmentWrite(JrkG2Command::SetRAMSettings, offset, 2, buffer);
1589 void setRAMSetting8x2(uint8_t offset, uint8_t val1, uint8_t val2)
1591 uint8_t buffer[2] = {val1, val2};
1592 segmentWrite(JrkG2Command::SetRAMSettings, offset, 2, buffer);
1595 void setRAMSetting16x2(uint8_t offset, uint16_t val1, uint16_t val2)
1597 uint8_t buffer[4] = {(uint8_t)val1, (uint8_t)(val1 >> 8),
1598 (uint8_t)val2, (uint8_t)(val2 >> 8)};
1599 segmentWrite(JrkG2Command::SetRAMSettings, offset, 4, buffer);
1604 void setPIDCoefficient(uint8_t offset, uint16_t multiplier, uint8_t exponent)
1606 uint8_t buffer[3] = {(uint8_t)multiplier, (uint8_t)(multiplier >> 8), exponent};
1607 segmentWrite(JrkG2Command::SetRAMSettings, offset, 3, buffer);
1610 uint8_t getRAMSetting8(uint8_t offset)
1613 segmentRead(JrkG2Command::GetRAMSettings, offset, 1, &result);
1617 uint16_t getRAMSetting16(uint8_t offset)
1620 segmentRead(JrkG2Command::GetRAMSettings, offset, 2, buffer);
1621 return ((uint16_t)buffer[0] << 0) | ((uint16_t)buffer[1] << 8);
1628 commandQuick((uint8_t)cmd);
1633 commandW7((uint8_t)cmd, val);
1638 commandWs14((uint8_t)cmd, val);
1643 return commandR8((uint8_t)cmd);
1648 return commandR16((uint8_t)cmd);
1652 uint8_t length, uint8_t * buffer)
1654 segmentRead((uint8_t)cmd, offset, length, buffer);
1658 uint8_t length, uint8_t * buffer)
1660 segmentWrite((uint8_t)cmd, offset, length, buffer);
1665 virtual void commandQuick(uint8_t cmd) = 0;
1666 virtual void commandW7(uint8_t cmd, uint8_t val) = 0;
1667 virtual void commandWs14(uint8_t cmd, int16_t val) = 0;
1668 virtual uint8_t commandR8(uint8_t cmd) = 0;
1669 virtual uint16_t commandR16(uint8_t cmd) = 0;
1670 virtual void segmentRead(uint8_t cmd, uint8_t offset,
1671 uint8_t length, uint8_t * buffer) = 0;
1672 virtual void segmentWrite(uint8_t cmd, uint8_t offset,
1673 uint8_t length, uint8_t * buffer) = 0;
1713 _deviceNumber(deviceNumber)
1721 Stream *
const _stream;
1722 const uint8_t _deviceNumber;
1724 void commandQuick(uint8_t cmd) { sendCommandHeader(cmd); }
1725 void commandW7(uint8_t cmd, uint8_t val);
1726 void commandWs14(uint8_t cmd, int16_t val);
1727 uint8_t commandR8(uint8_t cmd);
1728 uint16_t commandR16(uint8_t cmd);
1729 void segmentRead(uint8_t cmd, uint8_t offset,
1730 uint8_t length, uint8_t * buffer);
1731 void segmentWrite(uint8_t cmd, uint8_t offset,
1732 uint8_t length, uint8_t * buffer);
1734 void sendCommandHeader(uint8_t cmd);
1735 void serialW7(uint8_t val) { _stream->write(val & 0x7F); }
1753 JrkG2I2C(uint8_t address = 11) : _address(address & 0x7F)
1763 const uint8_t _address;
1765 void commandQuick(uint8_t cmd);
1766 void commandW7(uint8_t cmd, uint8_t val);
1767 void commandWs14(uint8_t cmd, int16_t val);
1768 uint8_t commandR8(uint8_t cmd);
1769 uint16_t commandR16(uint8_t cmd);
1770 void segmentRead(uint8_t cmd, uint8_t offset,
1771 uint8_t length, uint8_t * buffer);
1772 void segmentWrite(uint8_t cmd, uint8_t offset,
1773 uint8_t length, uint8_t * buffer) ;
uint16_t getEncodedHardCurrentLimit()
uint16_t getMaxDutyCycleWhileFeedbackOutOfRange()
const uint16_t JrkG2InputNull
void setEncodedHardCurrentLimit(uint16_t encoded_limit)
JrkG2ForceMode getForceMode()
void setMaxDecelerationReverse(uint16_t decel)
void setMaxAccelerationReverse(uint16_t accel)
uint16_t getMaxDecelerationForward()
uint16_t getMaxDutyCycleReverse()
void setSoftCurrentLimitReverse(uint16_t current)
uint16_t getPIDPeriodCount()
void setCoastWhenOff(bool coast)
void setMaxDeceleration(uint16_t decel)
uint8_t getDerivativeExponent()
uint8_t getDeviceNumber()
Gets the serial device number this object is using.
uint16_t getSoftCurrentLimitReverse()
uint16_t getMaxDutyCycleForward()
uint16_t getMaxAccelerationReverse()
void getRAMSettings(uint8_t offset, uint8_t length, uint8_t *buffer)
void setProportionalCoefficient(uint16_t multiplier, uint8_t exponent)
void setMaxDecelerationForward(uint16_t decel)
JrkG2Pin
This enum defines the Jrk G2's control and feedback pins.
uint16_t getDerivativeMultiplier()
int16_t getDutyCycleTarget()
void setMaxDutyCycle(uint16_t duty)
void setMaxDutyCycleForward(uint16_t duty)
uint16_t getSoftCurrentLimitForward()
uint8_t getCurrentChoppingConsecutiveCount()
void setSoftCurrentLimit(uint16_t current)
uint8_t getAddress()
Gets the I2C address this object is using.
void forceDutyCycleTarget(int16_t dutyCycle)
uint8_t getBrakeDurationForward()
void setDerivativeCoefficient(uint16_t multiplier, uint8_t exponent)
JrkG2I2C(uint8_t address=11)
void getEEPROMSettings(uint8_t offset, uint8_t length, uint8_t *buffer)
void getVariables(uint8_t offset, uint8_t length, uint8_t *buffer)
uint16_t getErrorFlagsOccurred()
void setMaxAccelerationForward(uint16_t accel)
uint8_t getIntegralExponent()
uint8_t getCurrentChoppingOccurrenceCount()
uint16_t getScaledFeedback()
uint16_t getIntegralMultiplier()
void setTargetLowResFwd(uint8_t target)
const uint8_t JrkG2CommReadError
void setBrakeDurationForward(uint8_t duration)
uint8_t getBrakeDurationReverse()
bool getPIDPeriodExceeded()
void setBrakeDuration(uint8_t duration)
uint16_t getAnalogReading(JrkG2Pin pin)
JrkG2Reset getDeviceReset()
bool getDigitalReading(JrkG2Pin pin)
void setRAMSettings(uint8_t offset, uint8_t length, uint8_t *buffer)
uint16_t getEncodedHardCurrentLimitReverse()
void setMaxDutyCycleWhileFeedbackOutOfRange(uint16_t duty)
void setIntegralCoefficient(uint16_t multiplier, uint8_t exponent)
void setMaxAcceleration(uint16_t accel)
void setMaxDutyCycleReverse(uint16_t duty)
void forceDutyCycle(int16_t dutyCycle)
void setBrakeDurationReverse(uint8_t duration)
uint16_t getRCPulseWidth()
void setTargetLowResRev(uint8_t target)
uint16_t getMaxDecelerationReverse()
void setTarget(uint16_t target)
void setResetIntegral(bool reset)
uint16_t getMaxAccelerationForward()
uint16_t getProportionalMultiplier()
uint16_t getErrorFlagsHalting()
uint16_t getIntegralLimit()
uint8_t getCurrentLowRes()
void setIntegralLimit(uint16_t limit)
uint16_t getEncodedHardCurrentLimitForward()
int16_t getLastDutyCycle()
void setSoftCurrentLimitForward(uint16_t current)
void setEncodedHardCurrentLimitForward(uint16_t encoded_limit)
void setEncodedHardCurrentLimitReverse(uint16_t encoded_limit)
void setPIDPeriod(uint16_t period)
JrkG2Serial(Stream &stream, uint8_t deviceNumber=255)
uint8_t getProportionalExponent()