Jrk G2 library for Arduino
Public Member Functions | Protected Attributes | List of all members
JrkG2Base Class Referenceabstract

#include <JrkG2.h>

Inheritance diagram for JrkG2Base:
Inheritance graph
[legend]

Public Member Functions

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 ()
 
Variable reading commands
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 getFBTReading ()
 
uint16_t getAnalogReading (JrkG2Pin pin)
 
bool getDigitalReading (JrkG2Pin pin)
 
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

This is a base class used to represent a connection to a Jrk G2. This class provides high-level functions for sending commands to the Jrk and reading data from it.

See the subclasses of this class, JrkG2Serial and JrkG2I2C.

Definition at line 123 of file JrkG2.h.

Member Function Documentation

void JrkG2Base::forceDutyCycle ( int16_t  dutyCycle)
inline

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().

See also getForceMode().

Definition at line 270 of file JrkG2.h.

void JrkG2Base::forceDutyCycleTarget ( int16_t  dutyCycle)
inline

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().

See also getForceMode().

Definition at line 238 of file JrkG2.h.

uint16_t JrkG2Base::getAnalogReading ( JrkG2Pin  pin)
inline

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:

uint16_t reading = getAnalogReading(JrkG2Pin::SDA);
if (reading != JrkG2InputNull && reading < 32768)
{
// The reading is less than about 2.4 V.
}

Definition at line 602 of file JrkG2.h.

uint8_t JrkG2Base::getBrakeDurationForward ( )
inline

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

See also setBrakeDurationForward().

Definition at line 1239 of file JrkG2.h.

uint8_t JrkG2Base::getBrakeDurationReverse ( )
inline

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

See also setBrakeDurationReverse().

Definition at line 1261 of file JrkG2.h.

bool JrkG2Base::getCoastWhenOff ( )
inline

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

See also setCoastWhenOff().

Definition at line 767 of file JrkG2.h.

uint16_t JrkG2Base::getCurrent ( )
inline

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 ( )
inline

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

See also getCurrentChoppingOccurrenceCount().

Definition at line 673 of file JrkG2.h.

uint8_t JrkG2Base::getCurrentChoppingOccurrenceCount ( )
inline

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.

See also getCurrentChoppingConsecutiveCount().

Definition at line 688 of file JrkG2.h.

uint8_t JrkG2Base::getCurrentLowRes ( )
inline

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 ( )
inline

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

See also getDerivativeMultiplier() and setDerivativeCoefficient().

Definition at line 891 of file JrkG2.h.

uint16_t JrkG2Base::getDerivativeMultiplier ( )
inline

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

See also getDerivativeExponent() and setDerivativeCoefficient().

Definition at line 882 of file JrkG2.h.

JrkG2Reset JrkG2Base::getDeviceReset ( )
inline

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)
inline

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:

if (jrk.getDigitalReading(JrkG2Pin::RC))
{
// Something is driving the RC pin high.
}

Definition at line 628 of file JrkG2.h.

int16_t JrkG2Base::getDutyCycle ( )
inline

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().

See also getLastDutyCycle(), getDutyCycleTarget(), and forceDutyCycle().

Definition at line 400 of file JrkG2.h.

int16_t JrkG2Base::getDutyCycleTarget ( )
inline

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.

See also getDutyCycle(), getLastDutyCycle(), and forceDutyCycleTarget().

Definition at line 384 of file JrkG2.h.

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

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 ( )
inline

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.

See also setEncodedHardCurrentLimit(), getCurrent().

Definition at line 653 of file JrkG2.h.

uint16_t JrkG2Base::getEncodedHardCurrentLimitForward ( )
inline

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.

See also setEncodedHardCurrentLimitForward().

Definition at line 1169 of file JrkG2.h.

uint16_t JrkG2Base::getEncodedHardCurrentLimitReverse ( )
inline

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.

See also setEncodedHardCurrentLimitReverse().

Definition at line 1198 of file JrkG2.h.

uint16_t JrkG2Base::getErrorFlagsHalting ( )
inline

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().

See also getErrorFlagsOccurred().

Definition at line 454 of file JrkG2.h.

uint16_t JrkG2Base::getErrorFlagsOccurred ( )
inline

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().

See also getErrorFlagsHalting().

Definition at line 483 of file JrkG2.h.

uint16_t JrkG2Base::getFBTReading ( )
inline

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:

uint16_t fbtReading = jrk.getFBTReading();

Definition at line 581 of file JrkG2.h.

uint16_t JrkG2Base::getFeedback ( )
inline

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.

See also getScaledFeedback().

Definition at line 341 of file JrkG2.h.

JrkG2ForceMode JrkG2Base::getForceMode ( )
inline

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.
}

See also forceDutyCycleTarget() and forceDutyCycle().

Definition at line 500 of file JrkG2.h.

uint16_t JrkG2Base::getInput ( )
inline

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.

See the Jrk G2 user's guide for more information about input modes.

See also getTarget() and setTarget().

Definition at line 312 of file JrkG2.h.

int16_t JrkG2Base::getIntegral ( )
inline

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 ( )
inline

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

See also getIntegralMultiplier() and setIntegralCoefficient().

Definition at line 852 of file JrkG2.h.

uint16_t JrkG2Base::getIntegralLimit ( )
inline

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

See also setIntegralLimit().

Definition at line 940 of file JrkG2.h.

uint16_t JrkG2Base::getIntegralMultiplier ( )
inline

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

See also getIntegralExponent() and setIntegralCoefficient().

Definition at line 843 of file JrkG2.h.

int16_t JrkG2Base::getLastDutyCycle ( )
inline

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.

See also getDutyCycle(), getDutyCycleTarget(), and getCurrent().

Definition at line 664 of file JrkG2.h.

uint8_t JrkG2Base::getLastError ( )
inline

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 ( )
inline

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

See also setMaxAccelerationForward().

Definition at line 985 of file JrkG2.h.

uint16_t JrkG2Base::getMaxAccelerationReverse ( )
inline

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

See also setMaxAccelerationReverse().

Definition at line 1008 of file JrkG2.h.

uint16_t JrkG2Base::getMaxDecelerationForward ( )
inline

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

See also setMaxDecelerationForward().

Definition at line 1045 of file JrkG2.h.

uint16_t JrkG2Base::getMaxDecelerationReverse ( )
inline

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

See also setMaxDecelerationReverse().

Definition at line 1068 of file JrkG2.h.

uint16_t JrkG2Base::getMaxDutyCycleForward ( )
inline

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

See also setMaxDutyCycleForward().

Definition at line 1104 of file JrkG2.h.

uint16_t JrkG2Base::getMaxDutyCycleReverse ( )
inline

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

See also setMaxDutyCycleReverse().

Definition at line 1126 of file JrkG2.h.

uint16_t JrkG2Base::getMaxDutyCycleWhileFeedbackOutOfRange ( )
inline

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

See also setMaxDutyCycleWhileFeedbackOutOfRange().

Definition at line 962 of file JrkG2.h.

uint16_t JrkG2Base::getPIDPeriod ( )
inline

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

See also setPIDPeriod().

Definition at line 916 of file JrkG2.h.

uint16_t JrkG2Base::getPIDPeriodCount ( )
inline

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 ( )
inline

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 ( )
inline

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

See also getProportionalMultiplier() and setProportionalCoefficient().

Definition at line 813 of file JrkG2.h.

uint16_t JrkG2Base::getProportionalMultiplier ( )
inline

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

See also getProportionalExponent() and setProportionalCoefficient().

Definition at line 804 of file JrkG2.h.

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

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 ( )
inline

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()).

See also getCurrent().

Definition at line 641 of file JrkG2.h.

uint16_t JrkG2Base::getRCPulseWidth ( )
inline

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 ( )
inline

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

See also setResetIntegral().

Definition at line 731 of file JrkG2.h.

uint16_t JrkG2Base::getScaledFeedback ( )
inline

Gets the scaled feedback variable.

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

See also getFeedback().

Definition at line 352 of file JrkG2.h.

uint16_t JrkG2Base::getSoftCurrentLimitForward ( )
inline

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

See also setSoftCurrentLimitForward().

Definition at line 1296 of file JrkG2.h.

uint16_t JrkG2Base::getSoftCurrentLimitReverse ( )
inline

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

See also setSoftCurrentLimitReverse().

Definition at line 1318 of file JrkG2.h.

uint16_t JrkG2Base::getTarget ( )
inline

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.

See also setTarget() and getInput().

Definition at line 324 of file JrkG2.h.

uint32_t JrkG2Base::getUpTime ( )
inline

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 
)
inline

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 ( )
inline

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)
inline

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.

See also setBrakeDurationForward(), setBrakeDurationReverse().

Definition at line 1274 of file JrkG2.h.

void JrkG2Base::setBrakeDurationForward ( uint8_t  duration)
inline

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.

See also getBrakeDurationForward() and setBrakeDurationReverse().

Definition at line 1230 of file JrkG2.h.

void JrkG2Base::setBrakeDurationReverse ( uint8_t  duration)
inline

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.

See also getBrakeDurationReverse() and setBrakeDurationForward().

Definition at line 1252 of file JrkG2.h.

void JrkG2Base::setCoastWhenOff ( bool  coast)
inline

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.

See also getCoastWhenOff().

Definition at line 749 of file JrkG2.h.

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

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.

See also getDerivativeMultiplier() and getDerivativeExponent(), as well as setProportionalCoefficient() and setIntegralCoefficient().

Definition at line 873 of file JrkG2.h.

void JrkG2Base::setEncodedHardCurrentLimit ( uint16_t  encoded_limit)
inline

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.

See also setEncodedHardCurrentLimitForward(), setEncodedHardCurrentLimitReverse(), getEncodedHardCurrentLimit(), and setSoftCurrentLimit().

Definition at line 1216 of file JrkG2.h.

void JrkG2Base::setEncodedHardCurrentLimitForward ( uint16_t  encoded_limit)
inline

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.

See also getEncodedHardCurrentLimitForward() and setEncodedHardCurrentLimitReverse().

Definition at line 1156 of file JrkG2.h.

void JrkG2Base::setEncodedHardCurrentLimitReverse ( uint16_t  encoded_limit)
inline

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.

See also getEncodedHardCurrentLimitReverse() and setEncodedHardCurrentLimitForward().

Definition at line 1186 of file JrkG2.h.

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

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.

See also getIntegralMultiplier() and getIntegralExponent(), as well as setProportionalCoefficient() and setDerivativeCoefficient().

Definition at line 834 of file JrkG2.h.

void JrkG2Base::setIntegralLimit ( uint16_t  limit)
inline

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.

See also getIntegralLimit().

Definition at line 932 of file JrkG2.h.

void JrkG2Base::setMaxAcceleration ( uint16_t  accel)
inline

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.

See also setMaxAccelerationForward(), setMaxAccelerationReverse(), setMaxDeceleration().

Definition at line 1022 of file JrkG2.h.

void JrkG2Base::setMaxAccelerationForward ( uint16_t  accel)
inline

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.

See also getMaxAccelerationForward(), setMaxAccelerationReverse(), setMaxAcceleration(), and setMaxDecelerationForward().

Definition at line 976 of file JrkG2.h.

void JrkG2Base::setMaxAccelerationReverse ( uint16_t  accel)
inline

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.

See also getMaxAccelerationReverse(), setMaxAccelerationForward(), setMaxAcceleration(), and setMaxDecelerationReverse().

Definition at line 999 of file JrkG2.h.

void JrkG2Base::setMaxDeceleration ( uint16_t  decel)
inline

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.

See also setMaxDecelerationForward(), setMaxDecelerationReverse(), setMaxAcceleration().

Definition at line 1082 of file JrkG2.h.

void JrkG2Base::setMaxDecelerationForward ( uint16_t  decel)
inline

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.

See also getMaxDecelerationForward(), setMaxDecelerationReverse(), setMaxDeceleration(), and setMaxAccelerationForward().

Definition at line 1036 of file JrkG2.h.

void JrkG2Base::setMaxDecelerationReverse ( uint16_t  decel)
inline

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.

See also getMaxDecelerationReverse(), setMaxDecelerationForward(), setMaxDeceleration(), and setMaxAccelerationReverse().

Definition at line 1059 of file JrkG2.h.

void JrkG2Base::setMaxDutyCycle ( uint16_t  duty)
inline

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.

See also setMaxDutyCycleForward(), setMaxDutyCycleReverse().

Definition at line 1139 of file JrkG2.h.

void JrkG2Base::setMaxDutyCycleForward ( uint16_t  duty)
inline

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.

See also getMaxDutyCycleForward(), setMaxDutyCycleReverse().

Definition at line 1095 of file JrkG2.h.

void JrkG2Base::setMaxDutyCycleReverse ( uint16_t  duty)
inline

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.

See also getMaxDutyCycleReverse(), setMaxDutyCycleForard().

Definition at line 1117 of file JrkG2.h.

void JrkG2Base::setMaxDutyCycleWhileFeedbackOutOfRange ( uint16_t  duty)
inline

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.

See also getMaxDutyCycleWhileFeedbackOutOfRange().

Definition at line 953 of file JrkG2.h.

void JrkG2Base::setPIDPeriod ( uint16_t  period)
inline

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.

See also getPIDPeriod().

Definition at line 908 of file JrkG2.h.

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

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.

See also getProportionalMultiplier() and getProportionalExponent(), as well as setIntegralCoefficient() and setDerivativeCoefficient().

Definition at line 795 of file JrkG2.h.

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

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)
inline

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.

See also getResetIntegral().

Definition at line 713 of file JrkG2.h.

void JrkG2Base::setSoftCurrentLimit ( uint16_t  current)
inline

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.

See also setSoftCurrentLimitForward() and setSoftCurrentLimitReverse(), setEncodedHardCurrentLimit().

Definition at line 1332 of file JrkG2.h.

void JrkG2Base::setSoftCurrentLimitForward ( uint16_t  current)
inline

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.

See also getSoftCurrentLimitForward() and setSoftCurrentLimitReverse().

Definition at line 1287 of file JrkG2.h.

void JrkG2Base::setSoftCurrentLimitReverse ( uint16_t  current)
inline

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.

See also getSoftCurrentLimitReverse() and setSoftCurrentLimitForward().

Definition at line 1309 of file JrkG2.h.

void JrkG2Base::setTarget ( uint16_t  target)
inline

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.

See also setTargetLowResRev(), setTargetLowResFwd(), getTarget(), forceDutyCycleTarget(), forceDutyCycle().

Definition at line 152 of file JrkG2.h.

void JrkG2Base::setTargetLowResFwd ( uint8_t  target)
inline

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.

See also setTargetLowResRev(), setTarget(), and getTarget().

Definition at line 209 of file JrkG2.h.

void JrkG2Base::setTargetLowResRev ( uint8_t  target)
inline

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.

See also setTargetLowResFwd(), setTarget(), getTarget(), and stopMotor().

Definition at line 182 of file JrkG2.h.

void JrkG2Base::stopMotor ( )
inline

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
protected

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 file: