Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
JrkG2Serial Class Reference
Represents a serial connection to a Jrk G2. More...
#include <JrkG2.h>
Inherits JrkG2Base.
Public Member Functions | |
| uint8_t | getDeviceNumber () |
| Gets the serial device number 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 a serial connection to a Jrk G2.
For the high-level commands you can use on this object, see JrkG2Base.
Definition at line 1699 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().
| 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().
| 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. } ```
| 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().
| 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().
| bool getCoastWhenOff | ( | ) | [inherited] |
Gets the "Coast when off" setting from the Jrk's RAM settings.
See also setCoastWhenOff().
| uint16_t getCurrent | ( | ) | [inherited] |
| 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().
| 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().
| 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.
| uint8_t getDerivativeExponent | ( | ) | [inherited] |
Gets the exponent part of the derivative coefficient from the Jrk's RAM settings.
See also getDerivativeMultiplier() and setDerivativeCoefficient().
| uint16_t getDerivativeMultiplier | ( | ) | [inherited] |
Gets the multiplier part of the derivative coefficient from the Jrk's RAM settings.
See also getDerivativeExponent() and setDerivativeCoefficient().
| uint8_t getDeviceNumber | ( | ) |
| JrkG2Reset getDeviceReset | ( | ) | [inherited] |
| 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. } ```
| 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().
| 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().
| 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.
| 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().
| 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().
| 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().
| 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().
| 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().
| 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(); ```
| 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().
| 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().
| 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().
| 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.
| uint8_t getIntegralExponent | ( | ) | [inherited] |
Gets the exponent part of the integral coefficient from the Jrk's RAM settings.
See also getIntegralMultiplier() and setIntegralCoefficient().
| uint16_t getIntegralLimit | ( | ) | [inherited] |
Gets the integral limit from the Jrk's RAM settings.
See also setIntegralLimit().
| uint16_t getIntegralMultiplier | ( | ) | [inherited] |
Gets the multiplier part of the integral coefficient from the Jrk's RAM settings.
See also getIntegralExponent() and setIntegralCoefficient().
| 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().
| uint8_t getLastError | ( | ) | [inherited] |
| uint16_t getMaxAccelerationForward | ( | ) | [inherited] |
Gets the maximum acceleration in the forward direction from the Jrk's RAM settings.
See also setMaxAccelerationForward().
| uint16_t getMaxAccelerationReverse | ( | ) | [inherited] |
Gets the maximum acceleration in the reverse direction from the Jrk's RAM settings.
See also setMaxAccelerationReverse().
| uint16_t getMaxDecelerationForward | ( | ) | [inherited] |
Gets the maximum deceleration in the forward direction from the Jrk's RAM settings.
See also setMaxDecelerationForward().
| uint16_t getMaxDecelerationReverse | ( | ) | [inherited] |
Gets the maximum deceleration in the reverse direction from the Jrk's RAM settings.
See also setMaxDecelerationReverse().
| uint16_t getMaxDutyCycleForward | ( | ) | [inherited] |
Gets the maximum duty cycle in the forward direction from the Jrk's RAM settings.
See also setMaxDutyCycleForward().
| uint16_t getMaxDutyCycleReverse | ( | ) | [inherited] |
Gets the maximum duty cycle in the reverse direction from the Jrk's RAM settings.
See also setMaxDutyCycleReverse().
| uint16_t getMaxDutyCycleWhileFeedbackOutOfRange | ( | ) | [inherited] |
Gets the maximum duty cycle while feedback is out of range from the Jrk's RAM settings.
See also setMaxDutyCycleWhileFeedbackOutOfRange().
| uint16_t getPIDPeriod | ( | ) | [inherited] |
Gets the PID period from the Jrk's RAM settings, in milliseconds.
See also setPIDPeriod().
| uint16_t getPIDPeriodCount | ( | ) | [inherited] |
| 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.
| uint8_t getProportionalExponent | ( | ) | [inherited] |
Gets the exponent part of the proportional coefficient from the Jrk's RAM settings.
See also getProportionalMultiplier() and setProportionalCoefficient().
| uint16_t getProportionalMultiplier | ( | ) | [inherited] |
Gets the multiplier part of the proportional coefficient from the Jrk's RAM settings.
See also getProportionalExponent() and setProportionalCoefficient().
| 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.
| 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().
| 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. } ```
| bool getResetIntegral | ( | ) | [inherited] |
Gets the "Reset integral" setting from the Jrk's RAM settings.
See also setResetIntegral().
| 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().
| 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().
| 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().
| 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().
| uint32_t getUpTime | ( | ) | [inherited] |
| 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.
| uint16_t getVinVoltage | ( | ) | [inherited] |
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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.
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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(); ```
Field Documentation
uint8_t _lastError [protected, inherited] |
Generated on Fri Jul 15 2022 17:30:31 by
1.7.2