hidaka sato / JrkG2
Embed: (wiki syntax)

« Back to documentation index

JrkG2I2C Class Reference

JrkG2I2C Class Reference

Represents an I2C connection to a Jrk G2. More...

#include <JrkG2.h>

Inherits JrkG2Base.

Public Member Functions

uint8_t getAddress ()
 Gets the I2C address this object is using.
uint8_t getLastError ()
 Returns 0 if the last communication with the device was successful, and non-zero if there was an error.
void setTarget (uint16_t target)
 Sets the target of the Jrk to a value in the range 0 to 4095.
void setTargetLowResRev (uint8_t target)
 Sets the target of the Jrk based on a value in the range 0 to 127.
void setTargetLowResFwd (uint8_t target)
 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.
void forceDutyCycleTarget (int16_t dutyCycle)
 Forces the duty cycle target of the Jrk to a value in the range -600 to +600.
void forceDutyCycle (int16_t dutyCycle)
 Forces the duty cycle of the Jrk to a value in the range -600 to +600.
void stopMotor ()
 Turns the motor off.
Variable reading commands
uint16_t getInput ()
 Gets the input variable.
uint16_t getTarget ()
 Gets the target variable.
uint16_t getFeedback ()
 Gets the feedback variable.
uint16_t getScaledFeedback ()
 Gets the scaled feedback variable.
int16_t getIntegral ()
 Gets the integral variable.
int16_t getDutyCycleTarget ()
 Gets the duty cycle target variable.
int16_t getDutyCycle ()
 Gets the duty cycle variable.
uint8_t getCurrentLowRes ()
 Gets the most-significant 8 bits of the "Current" variable.
bool getPIDPeriodExceeded ()
 Returns true if the Jrk's most recent PID cycle took more time than the configured PID period.
uint16_t getPIDPeriodCount ()
 Get the "PID period count" variable, which is the number of PID periods that have elapsed.
uint16_t getErrorFlagsHalting ()
 Gets the errors that are currently stopping the motor and clears any latched errors that are enabled.
uint16_t getErrorFlagsOccurred ()
 Gets the errors that have occurred since the last time this function was called.
JrkG2ForceMode getForceMode ()
 Returns an indication of whether the Jrk's duty cycle target or duty cycle are being overridden with a forced value.
uint16_t getVinVoltage ()
 Gets the measurement of the VIN voltage, in millivolts.
uint16_t getCurrent ()
 Gets the Jrk's measurement of the current running through the motor, in milliamps.
JrkG2Reset getDeviceReset ()
 Gets the cause of the Jrk's last full microcontroller reset.
uint32_t getUpTime ()
 Gets the time since the last full reset of the Jrk's microcontroller, in milliseconds.
uint16_t getRCPulseWidth ()
 Gets the raw RC pulse width measured on the Jrk's RC input, in units of twelfths of a microsecond.
uint16_t getFBTReading ()
 Gets the raw pulse rate or pulse width measured on the Jrk's FBT (tachometer feedback) pin.
uint16_t getAnalogReading (JrkG2Pin pin)
 Gets the analog reading from the specified pin.
bool getDigitalReading (JrkG2Pin pin)
 Gets a digital reading from the specified pin.
uint16_t getRawCurrent ()
 Gets the Jrk's raw measurement of the current running through the motor.
uint16_t getEncodedHardCurrentLimit ()
 Gets the encoded value representing the hardware current limit the jrk is currently using.
int16_t getLastDutyCycle ()
 Gets the duty cycle the Jrk drove the motor with in the last PID period.
uint8_t getCurrentChoppingConsecutiveCount ()
 Gets the number of consecutive PID periods during which current chopping due to the hard current limit has been active.
uint8_t getCurrentChoppingOccurrenceCount ()
 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.
RAM settings commands
void setResetIntegral (bool reset)
 Sets or clears the "Reset integral" setting in the Jrk's RAM settings.
bool getResetIntegral ()
 Gets the "Reset integral" setting from the Jrk's RAM settings.
void setCoastWhenOff (bool coast)
 Sets or clears the "Coast when off" setting in the Jrk's RAM settings.
bool getCoastWhenOff ()
 Gets the "Coast when off" setting from the Jrk's RAM settings.
void setProportionalCoefficient (uint16_t multiplier, uint8_t exponent)
 Sets the proportional coefficient in the Jrk's RAM settings.
uint16_t getProportionalMultiplier ()
 Gets the multiplier part of the proportional coefficient from the Jrk's RAM settings.
uint8_t getProportionalExponent ()
 Gets the exponent part of the proportional coefficient from the Jrk's RAM settings.
void setIntegralCoefficient (uint16_t multiplier, uint8_t exponent)
 Sets the integral coefficient in the Jrk's RAM settings.
uint16_t getIntegralMultiplier ()
 Gets the multiplier part of the integral coefficient from the Jrk's RAM settings.
uint8_t getIntegralExponent ()
 Gets the exponent part of the integral coefficient from the Jrk's RAM settings.
void setDerivativeCoefficient (uint16_t multiplier, uint8_t exponent)
 Sets the derivative coefficient in the Jrk's RAM settings.
uint16_t getDerivativeMultiplier ()
 Gets the multiplier part of the derivative coefficient from the Jrk's RAM settings.
uint8_t getDerivativeExponent ()
 Gets the exponent part of the derivative coefficient from the Jrk's RAM settings.
void setPIDPeriod (uint16_t period)
 Sets the PID period in the Jrk's RAM settings.
uint16_t getPIDPeriod ()
 Gets the PID period from the Jrk's RAM settings, in milliseconds.
void setIntegralLimit (uint16_t limit)
 Sets the integral limit in the Jrk's RAM settings.
uint16_t getIntegralLimit ()
 Gets the integral limit from the Jrk's RAM settings.
void setMaxDutyCycleWhileFeedbackOutOfRange (uint16_t duty)
 Sets the maximum duty cycle while feedback is out of range in the Jrk's RAM settings.
uint16_t getMaxDutyCycleWhileFeedbackOutOfRange ()
 Gets the maximum duty cycle while feedback is out of range from the Jrk's RAM settings.
void setMaxAccelerationForward (uint16_t accel)
 Sets the maximum acceleration in the forward direction in the Jrk's RAM settings.
uint16_t getMaxAccelerationForward ()
 Gets the maximum acceleration in the forward direction from the Jrk's RAM settings.
void setMaxAccelerationReverse (uint16_t accel)
 Sets the maximum acceleration in the reverse direction in the Jrk's RAM settings.
uint16_t getMaxAccelerationReverse ()
 Gets the maximum acceleration in the reverse direction from the Jrk's RAM settings.
void setMaxAcceleration (uint16_t accel)
 Sets the maximum acceleration in both directions in the Jrk's RAM settings.
void setMaxDecelerationForward (uint16_t decel)
 Sets the maximum deceleration in the forward direction in the Jrk's RAM settings.
uint16_t getMaxDecelerationForward ()
 Gets the maximum deceleration in the forward direction from the Jrk's RAM settings.
void setMaxDecelerationReverse (uint16_t decel)
 Sets the maximum deceleration in the reverse direction in the Jrk's RAM settings.
uint16_t getMaxDecelerationReverse ()
 Gets the maximum deceleration in the reverse direction from the Jrk's RAM settings.
void setMaxDeceleration (uint16_t decel)
 Sets the maximum deceleration in both directions in the Jrk's RAM settings.
void setMaxDutyCycleForward (uint16_t duty)
 Sets the maximum duty cycle in the forward direction in the Jrk's RAM settings.
uint16_t getMaxDutyCycleForward ()
 Gets the maximum duty cycle in the forward direction from the Jrk's RAM settings.
void setMaxDutyCycleReverse (uint16_t duty)
 Sets the maximum duty cycle in the reverse direction in the Jrk's RAM settings.
uint16_t getMaxDutyCycleReverse ()
 Gets the maximum duty cycle in the reverse direction from the Jrk's RAM settings.
void setMaxDutyCycle (uint16_t duty)
 Sets the maximum duty cycle for both directions in the Jrk's RAM settings.
void setEncodedHardCurrentLimitForward (uint16_t encoded_limit)
 Sets the encoded hard current limit for driving in the forward direction in the Jrk's RAM settings.
uint16_t getEncodedHardCurrentLimitForward ()
 Gets the encoded hard current limit for driving in the forward direction from the Jrk's RAM settings.
void setEncodedHardCurrentLimitReverse (uint16_t encoded_limit)
 Sets the encoded hard current limit for driving in the reverse direction in the Jrk's RAM settings.
uint16_t getEncodedHardCurrentLimitReverse ()
 Gets the encoded hard current limit for driving in the reverse direction from the Jrk's RAM settings.
void setEncodedHardCurrentLimit (uint16_t encoded_limit)
 Sets the encoded hard current limit for both directions in the Jrk's RAM settings.
void setBrakeDurationForward (uint8_t duration)
 Sets the brake duration when switching from forward to reverse in the Jrk's RAM settings, in units of 5 ms.
uint8_t getBrakeDurationForward ()
 Gets the brake duration when switching from forward to reverse from the Jrk's RAM settings, in units of 5 ms.
void setBrakeDurationReverse (uint8_t duration)
 Sets the brake duration when switching from reverse to forward in the Jrk's RAM settings, in units of 5 ms.
uint8_t getBrakeDurationReverse ()
 Gets the brake duration when switching from reverse to forward from the Jrk's RAM settings, in units of 5 ms.
void setBrakeDuration (uint8_t duration)
 Sets the brake duration for both directions in the Jrk's RAM settings, in units of 5 ms.
void setSoftCurrentLimitForward (uint16_t current)
 Sets the soft current limit when driving in the forward direction in the Jrk's RAM settings, in units of mA.
uint16_t getSoftCurrentLimitForward ()
 Gets the soft current limit when driving in the forward direction from the Jrk's RAM settings, in units of mA.
void setSoftCurrentLimitReverse (uint16_t current)
 Sets the soft current limit when driving in the reverse direction in the Jrk's RAM settings, in units of mA.
uint16_t getSoftCurrentLimitReverse ()
 Gets the soft current limit when driving in the reverse direction from the Jrk's RAM settings, in units of mA.
void setSoftCurrentLimit (uint16_t current)
 Sets the soft current limit for driving in both directions in the Jrk's RAM settings, in units of mA.
Low-level settings and variables commands
void getEEPROMSettings (uint8_t offset, uint8_t length, uint8_t *buffer)
 Gets a contiguous block of settings from the Jrk G2's EEPROM.
void getRAMSettings (uint8_t offset, uint8_t length, uint8_t *buffer)
 Gets a contiguous block of settings from the Jrk G2's RAM.
void setRAMSettings (uint8_t offset, uint8_t length, uint8_t *buffer)
 Sets a contiguous block of settings in the Jrk G2's RAM.
void getVariables (uint8_t offset, uint8_t length, uint8_t *buffer)
 Gets a contiguous block of variables from the Jrk G2.

Protected Attributes

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

Detailed Description

Represents an I2C connection to a Jrk G2.

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

Definition at line 1734 of file JrkG2.h.


Member Function Documentation

void forceDutyCycle ( int16_t  dutyCycle ) [inherited]

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 290 of file JrkG2.h.

void forceDutyCycleTarget ( int16_t  dutyCycle ) [inherited]

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 258 of file JrkG2.h.

uint8_t getAddress (  )

Gets the I2C address this object is using.

Definition at line 1743 of file JrkG2.h.

uint16_t getAnalogReading ( JrkG2Pin  pin ) [inherited]

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 622 of file JrkG2.h.

uint8_t getBrakeDurationForward (  ) [inherited]

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 1259 of file JrkG2.h.

uint8_t getBrakeDurationReverse (  ) [inherited]

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 1281 of file JrkG2.h.

bool getCoastWhenOff (  ) [inherited]

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

See also setCoastWhenOff().

Definition at line 787 of file JrkG2.h.

uint16_t getCurrent (  ) [inherited]

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

Definition at line 538 of file JrkG2.h.

uint8_t getCurrentChoppingConsecutiveCount (  ) [inherited]

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 693 of file JrkG2.h.

uint8_t getCurrentChoppingOccurrenceCount (  ) [inherited]

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 708 of file JrkG2.h.

uint8_t getCurrentLowRes (  ) [inherited]

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 430 of file JrkG2.h.

uint8_t getDerivativeExponent (  ) [inherited]

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

See also getDerivativeMultiplier() and setDerivativeCoefficient().

Definition at line 911 of file JrkG2.h.

uint16_t getDerivativeMultiplier (  ) [inherited]

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

See also getDerivativeExponent() and setDerivativeCoefficient().

Definition at line 902 of file JrkG2.h.

JrkG2Reset getDeviceReset (  ) [inherited]

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 552 of file JrkG2.h.

bool getDigitalReading ( JrkG2Pin  pin ) [inherited]

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 648 of file JrkG2.h.

int16_t getDutyCycle (  ) [inherited]

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 420 of file JrkG2.h.

int16_t getDutyCycleTarget (  ) [inherited]

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 404 of file JrkG2.h.

void getEEPROMSettings ( uint8_t  offset,
uint8_t  length,
uint8_t *  buffer 
) [inherited]

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 1377 of file JrkG2.h.

uint16_t getEncodedHardCurrentLimit (  ) [inherited]

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 673 of file JrkG2.h.

uint16_t getEncodedHardCurrentLimitForward (  ) [inherited]

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 1189 of file JrkG2.h.

uint16_t getEncodedHardCurrentLimitReverse (  ) [inherited]

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 1218 of file JrkG2.h.

uint16_t getErrorFlagsHalting (  ) [inherited]

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 474 of file JrkG2.h.

uint16_t getErrorFlagsOccurred (  ) [inherited]

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 503 of file JrkG2.h.

uint16_t getFBTReading (  ) [inherited]

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 601 of file JrkG2.h.

uint16_t getFeedback (  ) [inherited]

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 361 of file JrkG2.h.

JrkG2ForceMode getForceMode (  ) [inherited]

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 520 of file JrkG2.h.

uint16_t getInput (  ) [inherited]

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 332 of file JrkG2.h.

int16_t getIntegral (  ) [inherited]

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 383 of file JrkG2.h.

uint8_t getIntegralExponent (  ) [inherited]

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

See also getIntegralMultiplier() and setIntegralCoefficient().

Definition at line 872 of file JrkG2.h.

uint16_t getIntegralLimit (  ) [inherited]

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

See also setIntegralLimit().

Definition at line 960 of file JrkG2.h.

uint16_t getIntegralMultiplier (  ) [inherited]

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

See also getIntegralExponent() and setIntegralCoefficient().

Definition at line 863 of file JrkG2.h.

int16_t getLastDutyCycle (  ) [inherited]

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 684 of file JrkG2.h.

uint8_t getLastError (  ) [inherited]

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

Definition at line 151 of file JrkG2.h.

uint16_t getMaxAccelerationForward (  ) [inherited]

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

See also setMaxAccelerationForward().

Definition at line 1005 of file JrkG2.h.

uint16_t getMaxAccelerationReverse (  ) [inherited]

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

See also setMaxAccelerationReverse().

Definition at line 1028 of file JrkG2.h.

uint16_t getMaxDecelerationForward (  ) [inherited]

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

See also setMaxDecelerationForward().

Definition at line 1065 of file JrkG2.h.

uint16_t getMaxDecelerationReverse (  ) [inherited]

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

See also setMaxDecelerationReverse().

Definition at line 1088 of file JrkG2.h.

uint16_t getMaxDutyCycleForward (  ) [inherited]

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

See also setMaxDutyCycleForward().

Definition at line 1124 of file JrkG2.h.

uint16_t getMaxDutyCycleReverse (  ) [inherited]

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

See also setMaxDutyCycleReverse().

Definition at line 1146 of file JrkG2.h.

uint16_t getMaxDutyCycleWhileFeedbackOutOfRange (  ) [inherited]

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

See also setMaxDutyCycleWhileFeedbackOutOfRange().

Definition at line 982 of file JrkG2.h.

uint16_t getPIDPeriod (  ) [inherited]

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

See also setPIDPeriod().

Definition at line 936 of file JrkG2.h.

uint16_t getPIDPeriodCount (  ) [inherited]

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 448 of file JrkG2.h.

bool getPIDPeriodExceeded (  ) [inherited]

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 440 of file JrkG2.h.

uint8_t getProportionalExponent (  ) [inherited]

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

See also getProportionalMultiplier() and setProportionalCoefficient().

Definition at line 833 of file JrkG2.h.

uint16_t getProportionalMultiplier (  ) [inherited]

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

See also getProportionalExponent() and setProportionalCoefficient().

Definition at line 824 of file JrkG2.h.

void getRAMSettings ( uint8_t  offset,
uint8_t  length,
uint8_t *  buffer 
) [inherited]

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 1399 of file JrkG2.h.

uint16_t getRawCurrent (  ) [inherited]

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 661 of file JrkG2.h.

uint16_t getRCPulseWidth (  ) [inherited]

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 582 of file JrkG2.h.

bool getResetIntegral (  ) [inherited]

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

See also setResetIntegral().

Definition at line 751 of file JrkG2.h.

uint16_t getScaledFeedback (  ) [inherited]

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 372 of file JrkG2.h.

uint16_t getSoftCurrentLimitForward (  ) [inherited]

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 1316 of file JrkG2.h.

uint16_t getSoftCurrentLimitReverse (  ) [inherited]

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 1338 of file JrkG2.h.

uint16_t getTarget (  ) [inherited]

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 344 of file JrkG2.h.

uint32_t getUpTime (  ) [inherited]

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 564 of file JrkG2.h.

void getVariables ( uint8_t  offset,
uint8_t  length,
uint8_t *  buffer 
) [inherited]

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 1447 of file JrkG2.h.

uint16_t getVinVoltage (  ) [inherited]

Gets the measurement of the VIN voltage, in millivolts.

Example usage: ``` uint16_t vin = jrk.getVinVoltage(); ```

Definition at line 531 of file JrkG2.h.

void setBrakeDuration ( uint8_t  duration ) [inherited]

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 1294 of file JrkG2.h.

void setBrakeDurationForward ( uint8_t  duration ) [inherited]

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 1250 of file JrkG2.h.

void setBrakeDurationReverse ( uint8_t  duration ) [inherited]

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 1272 of file JrkG2.h.

void setCoastWhenOff ( bool  coast ) [inherited]

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 769 of file JrkG2.h.

void setDerivativeCoefficient ( uint16_t  multiplier,
uint8_t  exponent 
) [inherited]

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 893 of file JrkG2.h.

void setEncodedHardCurrentLimit ( uint16_t  encoded_limit ) [inherited]

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 1236 of file JrkG2.h.

void setEncodedHardCurrentLimitForward ( uint16_t  encoded_limit ) [inherited]

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 1176 of file JrkG2.h.

void setEncodedHardCurrentLimitReverse ( uint16_t  encoded_limit ) [inherited]

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 1206 of file JrkG2.h.

void setIntegralCoefficient ( uint16_t  multiplier,
uint8_t  exponent 
) [inherited]

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 854 of file JrkG2.h.

void setIntegralLimit ( uint16_t  limit ) [inherited]

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 952 of file JrkG2.h.

void setMaxAcceleration ( uint16_t  accel ) [inherited]

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 1042 of file JrkG2.h.

void setMaxAccelerationForward ( uint16_t  accel ) [inherited]

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 996 of file JrkG2.h.

void setMaxAccelerationReverse ( uint16_t  accel ) [inherited]

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 1019 of file JrkG2.h.

void setMaxDeceleration ( uint16_t  decel ) [inherited]

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 1102 of file JrkG2.h.

void setMaxDecelerationForward ( uint16_t  decel ) [inherited]

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 1056 of file JrkG2.h.

void setMaxDecelerationReverse ( uint16_t  decel ) [inherited]

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 1079 of file JrkG2.h.

void setMaxDutyCycle ( uint16_t  duty ) [inherited]

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 1159 of file JrkG2.h.

void setMaxDutyCycleForward ( uint16_t  duty ) [inherited]

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 1115 of file JrkG2.h.

void setMaxDutyCycleReverse ( uint16_t  duty ) [inherited]

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 1137 of file JrkG2.h.

void setMaxDutyCycleWhileFeedbackOutOfRange ( uint16_t  duty ) [inherited]

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 973 of file JrkG2.h.

void setPIDPeriod ( uint16_t  period ) [inherited]

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 928 of file JrkG2.h.

void setProportionalCoefficient ( uint16_t  multiplier,
uint8_t  exponent 
) [inherited]

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 815 of file JrkG2.h.

void setRAMSettings ( uint8_t  offset,
uint8_t  length,
uint8_t *  buffer 
) [inherited]

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 1424 of file JrkG2.h.

void setResetIntegral ( bool  reset ) [inherited]

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 733 of file JrkG2.h.

void setSoftCurrentLimit ( uint16_t  current ) [inherited]

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 1352 of file JrkG2.h.

void setSoftCurrentLimitForward ( uint16_t  current ) [inherited]

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 1307 of file JrkG2.h.

void setSoftCurrentLimitReverse ( uint16_t  current ) [inherited]

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 1329 of file JrkG2.h.

void setTarget ( uint16_t  target ) [inherited]

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 172 of file JrkG2.h.

void setTargetLowResFwd ( uint8_t  target ) [inherited]

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 229 of file JrkG2.h.

void setTargetLowResRev ( uint8_t  target ) [inherited]

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 202 of file JrkG2.h.

void stopMotor (  ) [inherited]

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 309 of file JrkG2.h.


Field Documentation

uint8_t _lastError [protected, inherited]

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

Definition at line 1457 of file JrkG2.h.