Jrk G2 library for Arduino
JrkG2Serial Class Reference

#include <JrkG2.h>

Inheritance diagram for JrkG2Serial:
[legend]
Collaboration diagram for JrkG2Serial:
[legend]

## Public Member Functions

JrkG2Serial (Stream &stream, uint8_t deviceNumber=255)

uint8_t getDeviceNumber ()
Gets the serial device number this object is using.

uint8_t getLastError ()

Motor control commands
void setTarget (uint16_t target)

void setTargetLowResRev (uint8_t target)

void setTargetLowResFwd (uint8_t target)

void forceDutyCycleTarget (int16_t dutyCycle)

void forceDutyCycle (int16_t dutyCycle)

void stopMotor ()

uint16_t getInput ()

uint16_t getTarget ()

uint16_t getFeedback ()

uint16_t getScaledFeedback ()

int16_t getIntegral ()

int16_t getDutyCycleTarget ()

int16_t getDutyCycle ()

uint8_t getCurrentLowRes ()

bool getPIDPeriodExceeded ()

uint16_t getPIDPeriodCount ()

uint16_t getErrorFlagsHalting ()

uint16_t getErrorFlagsOccurred ()

JrkG2ForceMode getForceMode ()

uint16_t getVinVoltage ()

uint16_t getCurrent ()

JrkG2Reset getDeviceReset ()

uint32_t getUpTime ()

uint16_t getRCPulseWidth ()

uint16_t getRawCurrent ()

uint16_t getEncodedHardCurrentLimit ()

int16_t getLastDutyCycle ()

uint8_t getCurrentChoppingConsecutiveCount ()

uint8_t getCurrentChoppingOccurrenceCount ()

RAM settings commands
void setResetIntegral (bool reset)

bool getResetIntegral ()

void setCoastWhenOff (bool coast)

bool getCoastWhenOff ()

void setProportionalCoefficient (uint16_t multiplier, uint8_t exponent)

uint16_t getProportionalMultiplier ()

uint8_t getProportionalExponent ()

void setIntegralCoefficient (uint16_t multiplier, uint8_t exponent)

uint16_t getIntegralMultiplier ()

uint8_t getIntegralExponent ()

void setDerivativeCoefficient (uint16_t multiplier, uint8_t exponent)

uint16_t getDerivativeMultiplier ()

uint8_t getDerivativeExponent ()

void setPIDPeriod (uint16_t period)

uint16_t getPIDPeriod ()

void setIntegralLimit (uint16_t limit)

uint16_t getIntegralLimit ()

void setMaxDutyCycleWhileFeedbackOutOfRange (uint16_t duty)

uint16_t getMaxDutyCycleWhileFeedbackOutOfRange ()

void setMaxAccelerationForward (uint16_t accel)

uint16_t getMaxAccelerationForward ()

void setMaxAccelerationReverse (uint16_t accel)

uint16_t getMaxAccelerationReverse ()

void setMaxAcceleration (uint16_t accel)

void setMaxDecelerationForward (uint16_t decel)

uint16_t getMaxDecelerationForward ()

void setMaxDecelerationReverse (uint16_t decel)

uint16_t getMaxDecelerationReverse ()

void setMaxDeceleration (uint16_t decel)

void setMaxDutyCycleForward (uint16_t duty)

uint16_t getMaxDutyCycleForward ()

void setMaxDutyCycleReverse (uint16_t duty)

uint16_t getMaxDutyCycleReverse ()

void setMaxDutyCycle (uint16_t duty)

void setEncodedHardCurrentLimitForward (uint16_t encoded_limit)

uint16_t getEncodedHardCurrentLimitForward ()

void setEncodedHardCurrentLimitReverse (uint16_t encoded_limit)

uint16_t getEncodedHardCurrentLimitReverse ()

void setEncodedHardCurrentLimit (uint16_t encoded_limit)

void setBrakeDurationForward (uint8_t duration)

uint8_t getBrakeDurationForward ()

void setBrakeDurationReverse (uint8_t duration)

uint8_t getBrakeDurationReverse ()

void setBrakeDuration (uint8_t duration)

void setSoftCurrentLimitForward (uint16_t current)

uint16_t getSoftCurrentLimitForward ()

void setSoftCurrentLimitReverse (uint16_t current)

uint16_t getSoftCurrentLimitReverse ()

void setSoftCurrentLimit (uint16_t current)

Low-level settings and variables commands
void getEEPROMSettings (uint8_t offset, uint8_t length, uint8_t *buffer)

void getRAMSettings (uint8_t offset, uint8_t length, uint8_t *buffer)

void setRAMSettings (uint8_t offset, uint8_t length, uint8_t *buffer)

void getVariables (uint8_t offset, uint8_t length, uint8_t *buffer)

## Protected Attributes

uint8_t _lastError = 0

## Detailed Description

Represents a serial connection to a Jrk G2.

For the high-level commands you can use on this object, see JrkG2Base.

Definition at line 1679 of file JrkG2.h.

## Constructor & Destructor Documentation

 JrkG2Serial::JrkG2Serial ( Stream & stream, uint8_t deviceNumber = 255 )
inline

Creates a new JrkG2Serial object.

The stream argument should be a hardware or software serial object. This class will store a pointer to it and use it to communicate with the Jrk. You should initialize it and set it to use the correct baud rate before sending commands with this class.

The deviceNumber argument is optional. If it is omitted or 255, the JrkG2Serial object will use the compact protocol. If it is a number between 0 and 127, it specifies the device number to use in the Pololu protocol, allowing you to control multiple Jrk controllers on a single serial bus.

For example, to use the first open hardware serial port to send compact protocol commands to one Jrk, write this at the top of your sketch:

JrkG2Serial jrk(SERIAL_PORT_HARDWARE_OPEN);

For example, to use a SoftwareSerial port and send Pololu protocol commands to two different Jrk G2 controllers, write this at the top of your sketch:

#include <SoftwareSerial.h>
SoftwareSerial jrkG2Serial(10, 11);
JrkG2Serial jrk1(jrkG2Serial, 11);
JrkG2Serial jrk2(jrkG2Serial, 12);

Definition at line 1711 of file JrkG2.h.

## Member Function Documentation

 void JrkG2Base::forceDutyCycle ( int16_t dutyCycle )
inlineinherited

Forces the duty cycle of the Jrk to a value in the range -600 to +600.

The jrk will ignore the results of the usual algorithm for choosing the duty cycle, and instead set it to be equal to the value specified by this command, ignoring all motor limits except the maximum duty cycle parameters, and ignoring the 'Input invalid', 'Input disconnect', and 'Feedback disconnect' errors. This command will have an immediate effect, regardless of the PID period. The jrk will set its 'Integral' variable to 0 while in this mode.

This is useful if the jrk is configured to use feedback but you want to take control of the motor for some time, without respecting most motor limits.

Example usage:

jrkG2.forceDutyCycle(250);

This function sends a "Force duty cycle" command to the Jrk G2, which clears the "Awaiting command" error bit.

To get out of this mode, use setTarget(), setTargetLowResFwd(), setTargetLowResRev(), forceDutyCycleTarget(), or stopMotor().

Definition at line 270 of file JrkG2.h.

 void JrkG2Base::forceDutyCycleTarget ( int16_t dutyCycle )
inlineinherited

Forces the duty cycle target of the Jrk to a value in the range -600 to +600.

The Jrk will ignore the results of the usual algorithm for choosing the duty cycle target, and instead set it to be equal to the target specified by this command. The Jrk will set its 'Integral' variable to 0 while in this mode.

This is useful if the Jrk is configured to use feedback but you want to take control of the motor for some time, while still respecting errors and motor limits as usual.

Example usage:

jrkG2.forceDutyCycleTarget(250);

This function sends a "Force duty cycle target" command to the Jrk G2, which clears the "Awaiting command" error bit.

To get out of this mode, use setTarget(), setTargetLowResFwd(), setTargetLowResRev(), forceDutyCycle(), or stopMotor().

Definition at line 238 of file JrkG2.h.

 uint16_t JrkG2Base::getAnalogReading ( JrkG2Pin pin )
inlineinherited

Gets the analog reading from the specified pin.

The reading is left-justified, so 0xFFFE represents a voltage equal to the Jrk's 5V pin (approximately 4.8 V).

Returns JrkG2InputNull if the analog reading is disabled or not ready or the pin is invalid.

Example usage:

{
}

Definition at line 602 of file JrkG2.h.

 uint8_t JrkG2Base::getBrakeDurationForward ( )
inlineinherited

Gets the brake duration when switching from forward to reverse from the Jrk's RAM settings, in units of 5 ms.

Definition at line 1239 of file JrkG2.h.

 uint8_t JrkG2Base::getBrakeDurationReverse ( )
inlineinherited

Gets the brake duration when switching from reverse to forward from the Jrk's RAM settings, in units of 5 ms.

Definition at line 1261 of file JrkG2.h.

 bool JrkG2Base::getCoastWhenOff ( )
inlineinherited

Gets the "Coast when off" setting from the Jrk's RAM settings.

Definition at line 767 of file JrkG2.h.

 uint16_t JrkG2Base::getCurrent ( )
inlineinherited

Gets the Jrk's measurement of the current running through the motor, in milliamps.

Definition at line 518 of file JrkG2.h.

 uint8_t JrkG2Base::getCurrentChoppingConsecutiveCount ( )
inlineinherited

Gets the number of consecutive PID periods during which current chopping due to the hard current limit has been active.

Definition at line 673 of file JrkG2.h.

 uint8_t JrkG2Base::getCurrentChoppingOccurrenceCount ( )
inlineinherited

Gets and clears the "Current chopping occurrence count" variable, which is the number of PID periods during which current chopping due to the hard current limit has been active, since the last time the variable was cleared.

This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21. The Jrk G2 21v3 cannot sense when current chopping occurs so this command will always return 0.

Definition at line 688 of file JrkG2.h.

 uint8_t JrkG2Base::getCurrentLowRes ( )
inlineinherited

Gets the most-significant 8 bits of the "Current" variable.

The Jrk G2 supports this command mainly to be compatible with older Jrk models. In new applications, we recommend using getCurrent(), which provides a higher-resolution measurement.

Definition at line 410 of file JrkG2.h.

 uint8_t JrkG2Base::getDerivativeExponent ( )
inlineinherited

Gets the exponent part of the derivative coefficient from the Jrk's RAM settings.

Definition at line 891 of file JrkG2.h.

 uint16_t JrkG2Base::getDerivativeMultiplier ( )
inlineinherited

Gets the multiplier part of the derivative coefficient from the Jrk's RAM settings.

Definition at line 882 of file JrkG2.h.

 JrkG2Reset JrkG2Base::getDeviceReset ( )
inlineinherited

Gets the cause of the Jrk's last full microcontroller reset.

Example usage:

if (jrk.getDeviceReset() == JrkG2Reset::Brownout)
{
// There was a brownout reset; the power supply could not keep up.
}

Definition at line 532 of file JrkG2.h.

 bool JrkG2Base::getDigitalReading ( JrkG2Pin pin )
inlineinherited

Gets a digital reading from the specified pin.

A return value of 0 means low while 1 means high. In most cases, pins configured as analog inputs cannot be read as digital inputs, so their values will be 0. See getAnalogReading() for those pins.

Example usage:

{
// Something is driving the RC pin high.
}

Definition at line 628 of file JrkG2.h.

 int16_t JrkG2Base::getDutyCycle ( )
inlineinherited

Gets the duty cycle variable.

The duty cycle variable is the duty cycle at which the jrk is currently driving the motor. A value of -600 means full speed reverse, while a value of 600 means full speed forward. A value of 0 means stopped (braking or coasting). The duty cycle could be different from the duty cycle target because it normally takes into account the Jrk's configurable motor limits and errors. The duty cycle can be overridden with forceDutyCycle().

Definition at line 400 of file JrkG2.h.

 int16_t JrkG2Base::getDutyCycleTarget ( )
inlineinherited

Gets the duty cycle target variable.

In general, this is the duty cycle that the Jrk is trying to achieve. A value of -600 or less means full speed reverse, while a value of 600 or more means full speed forward. A value of 0 means stopped (braking or coasting). In no feedback mode (open-loop speed control mode), the duty cycle target is normally the target minus 2048. In other feedback modes, the duty cycle target is normally the sum of the proportional, integral, and derivative terms of the PID algorithm. In any mode, the duty cycle target can be overridden with forceDutyCycleTarget().

If an error is stopping the motor, the duty cycle target variable will not be directly affected, but the duty cycle variable will change/decelerate to zero.

Definition at line 384 of file JrkG2.h.

 void JrkG2Base::getEEPROMSettings ( uint8_t offset, uint8_t length, uint8_t * buffer )
inlineinherited

Gets a contiguous block of settings from the Jrk G2's EEPROM.

The maximum length that can be fetched is 15 bytes.

Example usage:

// Get the Jrk's serial device number.
uint8_t deviceNumber;
jrk.getEEPROMSettings(0x28, 1, &deviceNumber);

For information on how the settings are encoded, see the Jrk G2 user's guide.

Definition at line 1357 of file JrkG2.h.

 uint16_t JrkG2Base::getEncodedHardCurrentLimit ( )
inlineinherited

Gets the encoded value representing the hardware current limit the jrk is currently using.

This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21. The Jrk G2 21v3 does not have a configurable hard current limit.

Definition at line 653 of file JrkG2.h.

 uint16_t JrkG2Base::getEncodedHardCurrentLimitForward ( )
inlineinherited

Gets the encoded hard current limit for driving in the forward direction from the Jrk's RAM settings.

This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21. The Jrk G2 21v3 does not have a configurable hard current limit.

Definition at line 1169 of file JrkG2.h.

 uint16_t JrkG2Base::getEncodedHardCurrentLimitReverse ( )
inlineinherited

Gets the encoded hard current limit for driving in the reverse direction from the Jrk's RAM settings.

This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21. The Jrk G2 21v3 does not have a configurable hard current limit.

Definition at line 1198 of file JrkG2.h.

 uint16_t JrkG2Base::getErrorFlagsHalting ( )
inlineinherited

Gets the errors that are currently stopping the motor and clears any latched errors that are enabled. Calling this function is equivalent to reading the "Currently stopping motor?" column in the Errors tab of the configuration utility, and then clicking the "Clear Errors" button.

Each bit in the returned register represents a different error. The bits are defined in the JrkG2Error enum.

Example usage:

uint16_t errors = jrk.getErrorFlagsHalting();
if (errors & (1 << (uint8_t)JrkG2Error::NoPower))
{
// handle loss of power
}

It is possible to read this variable without clearing the bits in it using a getVariables().

Definition at line 454 of file JrkG2.h.

 uint16_t JrkG2Base::getErrorFlagsOccurred ( )
inlineinherited

Gets the errors that have occurred since the last time this function was called. Unlike getErrorFlagsHalting(), calling this function has no effect on the motor.

Note that the Jrk G2 Control Center constantly clears the bits in this register, so if you are running the Jrk G2 Control Center then you will not be able to reliably detect errors with this function.

Each bit in the returned register represents a different error. The bits are defined in the JrkG2Error enum.

Example usage:

uint32_t errors = jrk.getErrorsOccurred();
if (errors & (1 << (uint8_t)JrkG2Error::MotorDriver))
{
// handle a motor driver error
}

It is possible to read this variable without clearing the bits in it using getVariables().

Definition at line 483 of file JrkG2.h.

inlineinherited

Gets the raw pulse rate or pulse width measured on the Jrk's FBT (tachometer feedback) pin.

In pulse counting mode, this will be the number of pulses on the FBT pin seen in the last N PID periods, where N is the "Pulse samples" setting.

In pulse timing mode, this will be a measurement of the width of pulses on the FBT pin. This measurement is affected by several configurable settings.

Example usage:

Definition at line 581 of file JrkG2.h.

 uint16_t JrkG2Base::getFeedback ( )
inlineinherited

Gets the feedback variable.

The feedback variable is a raw, unscaled feedback value, representing a measurement taken by the Jrk of the output of the system. In analog feedback mode, the feedback is a measurement of the voltage on the FBA pin, where 0 is 0 V and 4092 is a voltage equal to the Jrk's 5V pin (approximately 4.8 V). In frequency feedback mode, the feedback is 2048 plus or minus a measurement of the frequency of pulses on the FBT pin. In feedback mode none (open-loop speed control mode), the feedback is always zero.

Definition at line 341 of file JrkG2.h.

 JrkG2ForceMode JrkG2Base::getForceMode ( )
inlineinherited

Returns an indication of whether the Jrk's duty cycle target or duty cycle are being overridden with a forced value.

Example usage:

if (jrk.getForceMode() == JrkG2ForceMode::DutyCycleTarget)
{
// The duty cycle target is being overridden with a forced value.
}

Definition at line 500 of file JrkG2.h.

 uint16_t JrkG2Base::getInput ( )
inlineinherited

Gets the input variable.

The input variable is a raw, unscaled value representing a measurement taken by the Jrk of the input to the system. In serial input mode, the input is equal to the target, which can be set to any value from 0 to 4095 using serial commands. In analog input mode, the input is a measurement of the voltage on the SDA pin, where 0 is 0 V and 4092 is a voltage equal to the Jrk's 5V pin (approximately 4.8 V). In RC input mode, the input is the duration of the last RC pulse measured, in units of 2/3 us.

Definition at line 312 of file JrkG2.h.

 int16_t JrkG2Base::getIntegral ( )
inlineinherited

Gets the integral variable.

In general, every PID period, the error (scaled feedback minus target) is added to the integral (also known as error sum). There are several settings to configure the behavior of this variable, and it is used in the PID calculation.

Definition at line 363 of file JrkG2.h.

 uint8_t JrkG2Base::getIntegralExponent ( )
inlineinherited

Gets the exponent part of the integral coefficient from the Jrk's RAM settings.

Definition at line 852 of file JrkG2.h.

 uint16_t JrkG2Base::getIntegralLimit ( )
inlineinherited

Gets the integral limit from the Jrk's RAM settings.

Definition at line 940 of file JrkG2.h.

 uint16_t JrkG2Base::getIntegralMultiplier ( )
inlineinherited

Gets the multiplier part of the integral coefficient from the Jrk's RAM settings.

Definition at line 843 of file JrkG2.h.

 int16_t JrkG2Base::getLastDutyCycle ( )
inlineinherited

Gets the duty cycle the Jrk drove the motor with in the last PID period.

This can be useful for converting the getRawCurrent() reading into milliamps.

Definition at line 664 of file JrkG2.h.

 uint8_t JrkG2Base::getLastError ( )
inlineinherited

Returns 0 if the last communication with the device was successful, and non-zero if there was an error.

Definition at line 128 of file JrkG2.h.

 uint16_t JrkG2Base::getMaxAccelerationForward ( )
inlineinherited

Gets the maximum acceleration in the forward direction from the Jrk's RAM settings.

Definition at line 985 of file JrkG2.h.

 uint16_t JrkG2Base::getMaxAccelerationReverse ( )
inlineinherited

Gets the maximum acceleration in the reverse direction from the Jrk's RAM settings.

Definition at line 1008 of file JrkG2.h.

 uint16_t JrkG2Base::getMaxDecelerationForward ( )
inlineinherited

Gets the maximum deceleration in the forward direction from the Jrk's RAM settings.

Definition at line 1045 of file JrkG2.h.

 uint16_t JrkG2Base::getMaxDecelerationReverse ( )
inlineinherited

Gets the maximum deceleration in the reverse direction from the Jrk's RAM settings.

Definition at line 1068 of file JrkG2.h.

 uint16_t JrkG2Base::getMaxDutyCycleForward ( )
inlineinherited

Gets the maximum duty cycle in the forward direction from the Jrk's RAM settings.

Definition at line 1104 of file JrkG2.h.

 uint16_t JrkG2Base::getMaxDutyCycleReverse ( )
inlineinherited

Gets the maximum duty cycle in the reverse direction from the Jrk's RAM settings.

Definition at line 1126 of file JrkG2.h.

 uint16_t JrkG2Base::getMaxDutyCycleWhileFeedbackOutOfRange ( )
inlineinherited

Gets the maximum duty cycle while feedback is out of range from the Jrk's RAM settings.

Definition at line 962 of file JrkG2.h.

 uint16_t JrkG2Base::getPIDPeriod ( )
inlineinherited

Gets the PID period from the Jrk's RAM settings, in milliseconds.

Definition at line 916 of file JrkG2.h.

 uint16_t JrkG2Base::getPIDPeriodCount ( )
inlineinherited

Get the "PID period count" variable, which is the number of PID periods that have elapsed. It resets to 0 after reaching 65535. The duration of the PID period can be configured.

Definition at line 428 of file JrkG2.h.

 bool JrkG2Base::getPIDPeriodExceeded ( )
inlineinherited

Returns true if the Jrk's most recent PID cycle took more time than the configured PID period. This indicates that the Jrk does not have time to perform all of its tasks at the desired rate. Most often, this is caused by the configured number of analog samples for input, feedback, or current sensing being too high for the configured PID period.

Definition at line 420 of file JrkG2.h.

 uint8_t JrkG2Base::getProportionalExponent ( )
inlineinherited

Gets the exponent part of the proportional coefficient from the Jrk's RAM settings.

Definition at line 813 of file JrkG2.h.

 uint16_t JrkG2Base::getProportionalMultiplier ( )
inlineinherited

Gets the multiplier part of the proportional coefficient from the Jrk's RAM settings.

Definition at line 804 of file JrkG2.h.

 void JrkG2Base::getRAMSettings ( uint8_t offset, uint8_t length, uint8_t * buffer )
inlineinherited

Gets a contiguous block of settings from the Jrk G2's RAM.

The maximum length that can be fetched is 15 bytes.

Example usage:

// Get the Jrk's feedback maximum setting.
uint8_t buffer[2];
jrk.getRAMSettings(0x1F, 2, buffer);
uint16_t feedbackMaximum = buffer[0] + (buffer[1] << 8);

Note that this library has several functions for reading and writing specific RAM settings, and they are easier to use than this function.

For information on how the settings are encoded, see the Jrk G2 user's guide.

Definition at line 1379 of file JrkG2.h.

 uint16_t JrkG2Base::getRawCurrent ( )
inlineinherited

Gets the Jrk's raw measurement of the current running through the motor.

This is an analog voltage reading from the Jrk's current sense pin. The units of the reading depend on what hard current limit is being used (getEncodedHardCurrentLimit()).

Definition at line 641 of file JrkG2.h.

 uint16_t JrkG2Base::getRCPulseWidth ( )
inlineinherited

Gets the raw RC pulse width measured on the Jrk's RC input, in units of twelfths of a microsecond.

Returns 0 if the RC input is missing or invalid.

Example usage:

uint16_t pulseWidth = jrk.getRCPulseWidth();
if (pulseWidth != 0 && pulseWidth < 18000)
{
// Input is valid and pulse width is less than 1500 microseconds.
}

Definition at line 562 of file JrkG2.h.

 bool JrkG2Base::getResetIntegral ( )
inlineinherited

Gets the "Reset integral" setting from the Jrk's RAM settings.

Definition at line 731 of file JrkG2.h.

 uint16_t JrkG2Base::getScaledFeedback ( )
inlineinherited

Gets the scaled feedback variable.

The scaled feedback is calculated from the feedback using the Jrk's configurable feedback scaling settings.

Definition at line 352 of file JrkG2.h.

 uint16_t JrkG2Base::getSoftCurrentLimitForward ( )
inlineinherited

Gets the soft current limit when driving in the forward direction from the Jrk's RAM settings, in units of mA.

Definition at line 1296 of file JrkG2.h.

 uint16_t JrkG2Base::getSoftCurrentLimitReverse ( )
inlineinherited

Gets the soft current limit when driving in the reverse direction from the Jrk's RAM settings, in units of mA.

Definition at line 1318 of file JrkG2.h.

 uint16_t JrkG2Base::getTarget ( )
inlineinherited

Gets the target variable.

In serial input mode, the target is set directly with serial commands. In the other input modes, the target is computed by scaling the input, using the configurable input scaling settings.

Definition at line 324 of file JrkG2.h.

 uint32_t JrkG2Base::getUpTime ( )
inlineinherited

Gets the time since the last full reset of the Jrk's microcontroller, in milliseconds.

Example usage:

uint32_t upTime = jrk.getUpTime();

Definition at line 544 of file JrkG2.h.

 void JrkG2Base::getVariables ( uint8_t offset, uint8_t length, uint8_t * buffer )
inlineinherited

Gets a contiguous block of variables from the Jrk G2.

Note that this library has convenient functions for reading every variable provided by the Jrk. The main reason to use this function is if you want to read multiple variables at once for extra efficiency or to ensure that the variables are in a consistent state.

The maximum length that can be fetched is 15 bytes.

Example usage:

// Get the Jrk's last device reset and its up time.
uint8_t buffer[5];
jrk.getVariables(0x1F, 5, buffer);

For information on how the variables are encoded, see the Jrk G2 user's guide.

Definition at line 1427 of file JrkG2.h.

 uint16_t JrkG2Base::getVinVoltage ( )
inlineinherited

Gets the measurement of the VIN voltage, in millivolts.

Example usage:

uint16_t vin = jrk.getVinVoltage();

Definition at line 511 of file JrkG2.h.

 void JrkG2Base::setBrakeDuration ( uint8_t duration )
inlineinherited

Sets the brake duration for both directions in the Jrk's RAM settings, in units of 5 ms.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1274 of file JrkG2.h.

 void JrkG2Base::setBrakeDurationForward ( uint8_t duration )
inlineinherited

Sets the brake duration when switching from forward to reverse in the Jrk's RAM settings, in units of 5 ms.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1230 of file JrkG2.h.

 void JrkG2Base::setBrakeDurationReverse ( uint8_t duration )
inlineinherited

Sets the brake duration when switching from reverse to forward in the Jrk's RAM settings, in units of 5 ms.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1252 of file JrkG2.h.

 void JrkG2Base::setCoastWhenOff ( bool coast )
inlineinherited

Sets or clears the "Coast when off" setting in the Jrk's RAM settings.

By default, the Jrk drives both motor outputs low when the motor is stopped (duty cycle is zero), causing it to brake. If enabled, this setting causes it to instead tri-state both outputs, making the motor coast.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 749 of file JrkG2.h.

 void JrkG2Base::setDerivativeCoefficient ( uint16_t multiplier, uint8_t exponent )
inlineinherited

Sets the derivative coefficient in the Jrk's RAM settings.

This coefficient is used in the Jrk's PID algorithm. The coefficient takes the form:

multiplier / (2 ^ exponent)

The multiplier can range from 0 to 1023, and the exponent can range from 0 to 18.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 873 of file JrkG2.h.

 void JrkG2Base::setEncodedHardCurrentLimit ( uint16_t encoded_limit )
inlineinherited

Sets the encoded hard current limit for both directions in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21. The Jrk G2 21v3 does not have a configurable hard current limit.

Definition at line 1216 of file JrkG2.h.

 void JrkG2Base::setEncodedHardCurrentLimitForward ( uint16_t encoded_limit )
inlineinherited

Sets the encoded hard current limit for driving in the forward direction in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21. The Jrk G2 21v3 does not have a configurable hard current limit.

Definition at line 1156 of file JrkG2.h.

 void JrkG2Base::setEncodedHardCurrentLimitReverse ( uint16_t encoded_limit )
inlineinherited

Sets the encoded hard current limit for driving in the reverse direction in the Jrk's RAM settings

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21. The Jrk G2 21v3 does not have a configurable hard current limit.

Definition at line 1186 of file JrkG2.h.

 void JrkG2Base::setIntegralCoefficient ( uint16_t multiplier, uint8_t exponent )
inlineinherited

Sets the integral coefficient in the Jrk's RAM settings.

This coefficient is used in the Jrk's PID algorithm. The coefficient takes the form:

multiplier / (2 ^ exponent)

The multiplier can range from 0 to 1023, and the exponent can range from 0 to 18.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 834 of file JrkG2.h.

 void JrkG2Base::setIntegralLimit ( uint16_t limit )
inlineinherited

Sets the integral limit in the Jrk's RAM settings.

The PID algorithm prevents the absolute value of the integral variable (also known as error sum) from exceeding this limit. This can help limit integral wind-up. The limit can range from 0 to 32767.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 932 of file JrkG2.h.

 void JrkG2Base::setMaxAcceleration ( uint16_t accel )
inlineinherited

Sets the maximum acceleration in both directions in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1022 of file JrkG2.h.

 void JrkG2Base::setMaxAccelerationForward ( uint16_t accel )
inlineinherited

Sets the maximum acceleration in the forward direction in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 976 of file JrkG2.h.

 void JrkG2Base::setMaxAccelerationReverse ( uint16_t accel )
inlineinherited

Sets the maximum acceleration in the reverse direction in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 999 of file JrkG2.h.

 void JrkG2Base::setMaxDeceleration ( uint16_t decel )
inlineinherited

Sets the maximum deceleration in both directions in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1082 of file JrkG2.h.

 void JrkG2Base::setMaxDecelerationForward ( uint16_t decel )
inlineinherited

Sets the maximum deceleration in the forward direction in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1036 of file JrkG2.h.

 void JrkG2Base::setMaxDecelerationReverse ( uint16_t decel )
inlineinherited

Sets the maximum deceleration in the reverse direction in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1059 of file JrkG2.h.

 void JrkG2Base::setMaxDutyCycle ( uint16_t duty )
inlineinherited

Sets the maximum duty cycle for both directions in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1139 of file JrkG2.h.

 void JrkG2Base::setMaxDutyCycleForward ( uint16_t duty )
inlineinherited

Sets the maximum duty cycle in the forward direction in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1095 of file JrkG2.h.

 void JrkG2Base::setMaxDutyCycleReverse ( uint16_t duty )
inlineinherited

Sets the maximum duty cycle in the reverse direction in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1117 of file JrkG2.h.

 void JrkG2Base::setMaxDutyCycleWhileFeedbackOutOfRange ( uint16_t duty )
inlineinherited

Sets the maximum duty cycle while feedback is out of range in the Jrk's RAM settings.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 953 of file JrkG2.h.

 void JrkG2Base::setPIDPeriod ( uint16_t period )
inlineinherited

Sets the PID period in the Jrk's RAM settings.

This is the rate at which the Jrk runs through all of its calculations, in milliseconds. Note that a higher PID period will result in a more slowly changing integral and a higher derivative, so the two corresponding PID coefficients might need to be adjusted whenever the PID period is changed.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 908 of file JrkG2.h.

 void JrkG2Base::setProportionalCoefficient ( uint16_t multiplier, uint8_t exponent )
inlineinherited

Sets the proportional coefficient in the Jrk's RAM settings.

This coefficient is used in the Jrk's PID algorithm. The coefficient takes the form:

multiplier / (2 ^ exponent)

The multiplier can range from 0 to 1023, and the exponent can range from 0 to 18.

Example usage:

// Set the proportional coefficient to 1.125 (9/(2^3)).
jrk.setProportionalCoefficient(9, 3);

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 795 of file JrkG2.h.

 void JrkG2Base::setRAMSettings ( uint8_t offset, uint8_t length, uint8_t * buffer )
inlineinherited

Sets a contiguous block of settings in the Jrk G2's RAM.

The maximum length that can be written in a single command is 7 bytes over Serial, 13 bytes over I2C.

Example usage:

// Set the Jrk's feedback maximum setting.
uint16_t feedbackMaximum = 1234;
uint8_t buffer[2];
buffer[0] = feedbackMaximum & 0xFF;
buffer[1] = feedbackMaximum >> 8 & 0xFF;
jrk.setRAMSettings(0x1F, 2, buffer);

Note that this library has several functions for reading and writing specific RAM settings, and they are easier to use than this function.

For information on how the settings are encoded, see the Jrk G2 user's guide.

Definition at line 1404 of file JrkG2.h.

 void JrkG2Base::setResetIntegral ( bool reset )
inlineinherited

Sets or clears the "Reset integral" setting in the Jrk's RAM settings.

If this setting is set to true, the PID algorithm will reset the integral variable (also known as error sum) when the absolute value of the proportional term exceeds 600.

When enabled, this can help limit integral wind-up, or the uncontrolled growth of the integral when the feedback system is temporarily unable to keep the error small. This might happen, for example, when the target is changing quickly.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 713 of file JrkG2.h.

 void JrkG2Base::setSoftCurrentLimit ( uint16_t current )
inlineinherited

Sets the soft current limit for driving in both directions in the Jrk's RAM settings, in units of mA.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1332 of file JrkG2.h.

 void JrkG2Base::setSoftCurrentLimitForward ( uint16_t current )
inlineinherited

Sets the soft current limit when driving in the forward direction in the Jrk's RAM settings, in units of mA.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1287 of file JrkG2.h.

 void JrkG2Base::setSoftCurrentLimitReverse ( uint16_t current )
inlineinherited

Sets the soft current limit when driving in the reverse direction in the Jrk's RAM settings, in units of mA.

You would normally configure this setting ahead of time using the Jrk G2 Configuration Utility, but this function allows you to change it temporarily on the fly.

Definition at line 1309 of file JrkG2.h.

 void JrkG2Base::setTarget ( uint16_t target )
inlineinherited

Sets the target of the Jrk to a value in the range 0 to 4095.

The target can represent a target duty cycle, speed, or position depending on the feedback mode.

Example usage:

jrkG2.setTarget(3000);

This functions sends a "Set target" command to the jrk, which clears the "Awaiting command" error bit and (if the input mode is serial) will set the jrk's input and target variables.

Definition at line 152 of file JrkG2.h.

 void JrkG2Base::setTargetLowResFwd ( uint8_t target )
inlineinherited

Sets the target of the Jrk based on a value in the range 0 to 127 that maps to a 12-bit target of 2048 or greater.

If the feedback mode is Analog or Tachometer, then the formula is Target = 2048 + 16 * value.

If the feedback mode is None (speed control mode), then the formula is Target = 2048 + (600 / 127) * value. This means that a value of 127 will set the duty cycle target to full-speed reverse (-600), while a value of zero will make the motor stop.

Example usage:

jrkG2.setTargetLowResFwd(100);

This function sends a "Set target low resolution forward" command to the Jrk G2, which clears the "Awaiting command" error bit and (if the input mode is serial) will set the jrk's input and target variables.

Definition at line 209 of file JrkG2.h.

 void JrkG2Base::setTargetLowResRev ( uint8_t target )
inlineinherited

Sets the target of the Jrk based on a value in the range 0 to 127.

If the value is zero, then this command is equivalent to the "Stop motor" command. Otherwise, the value maps to a 12-bit target less than 2048.

If the feedback mode is Analog or Tachometer, then the formula is Target = 2048 - 16 * value.

If the feedback mode is None (speed control mode), then the formula is Target = 2048 - (600 / 127) * value. This means that a value of 127 will set the duty cycle target to full-speed reverse (-600).

Example usage:

jrkG2.setTargetLowResRev(100);

This function sends a "Set target low resolution reverse" command to the Jrk G2, which clears the "Awaiting command" error bit and (if the input mode is serial) will set the jrk's input and target variables.

Definition at line 182 of file JrkG2.h.

 void JrkG2Base::stopMotor ( )
inlineinherited

Turns the motor off.

This function sends a "Stop motor" command to the Jrk, which sets the "Awaiting command" error bit. The Jrk will respect the configured deceleration limit while decelerating to a duty cycle of 0, unless the "Awaiting command" error has been configured as a hard error. Once the duty cycle reaches zero, the Jrk will either brake or coast.

Example usage:

jrkG2.stopMotor();

Definition at line 289 of file JrkG2.h.

## Member Data Documentation

 uint8_t JrkG2Base::_lastError = 0
protectedinherited

Zero if the last communication with the device was successful, non-zero otherwise.

Definition at line 1437 of file JrkG2.h.

The documentation for this class was generated from the following files: