Library for JrkG2. this bases on Arduino Library (https://github.com/pololu/jrk-g2-arduino)

Committer:
sgrsn
Date:
Sun Aug 26 08:42:11 2018 +0000
Revision:
2:e78c0ddcf337
Parent:
1:d611aa1f9f70
Use AsyncSerial for Serial require.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sgrsn 0:33bfb28b0ffc 1 #pragma once
sgrsn 0:33bfb28b0ffc 2
sgrsn 0:33bfb28b0ffc 3 #include "mbed.h"
sgrsn 2:e78c0ddcf337 4 #include "AsyncSerial.hpp"
sgrsn 0:33bfb28b0ffc 5
sgrsn 0:33bfb28b0ffc 6 /*example**********************************
sgrsn 0:33bfb28b0ffc 7
sgrsn 0:33bfb28b0ffc 8 #include "mbed.h"
sgrsn 0:33bfb28b0ffc 9 #include "JrkG2.h"
sgrsn 0:33bfb28b0ffc 10
sgrsn 0:33bfb28b0ffc 11 int main()
sgrsn 0:33bfb28b0ffc 12 {
sgrsn 0:33bfb28b0ffc 13 //on the other or both
sgrsn 0:33bfb28b0ffc 14
sgrsn 0:33bfb28b0ffc 15 //on Serial
sgrsn 2:e78c0ddcf337 16 AsyncSerial device(p9, p10);
sgrsn 0:33bfb28b0ffc 17 JrkG2Serial jrk(&device);
sgrsn 0:33bfb28b0ffc 18
sgrsn 0:33bfb28b0ffc 19 //on I2C
sgrsn 0:33bfb28b0ffc 20 I2C device(p28, p27);
sgrsn 0:33bfb28b0ffc 21 JrkG2I2C jrk(&device);
sgrsn 0:33bfb28b0ffc 22
sgrsn 0:33bfb28b0ffc 23 while(1)
sgrsn 0:33bfb28b0ffc 24 {
sgrsn 0:33bfb28b0ffc 25 wait_ms(1500);
sgrsn 0:33bfb28b0ffc 26 jrk.setTarget(2500);
sgrsn 0:33bfb28b0ffc 27 wait_ms(1500);
sgrsn 0:33bfb28b0ffc 28 jrk.setTarget(1500);
sgrsn 0:33bfb28b0ffc 29 }
sgrsn 0:33bfb28b0ffc 30 }
sgrsn 0:33bfb28b0ffc 31
sgrsn 0:33bfb28b0ffc 32 ***********************************************/
sgrsn 0:33bfb28b0ffc 33
sgrsn 0:33bfb28b0ffc 34 /// This is used to represent a null or missing value for some of the Jrk G2's
sgrsn 0:33bfb28b0ffc 35 /// 16-bit input variables.
sgrsn 0:33bfb28b0ffc 36 const uint16_t JrkG2InputNull = 0xFFFF;
sgrsn 0:33bfb28b0ffc 37
sgrsn 0:33bfb28b0ffc 38 /// This value is returned by getLastError() if the last communication with the
sgrsn 0:33bfb28b0ffc 39 /// device resulted in an unsuccessful read (e.g. timeout or NACK).
sgrsn 0:33bfb28b0ffc 40 const uint8_t JrkG2CommReadError = 50;
sgrsn 0:33bfb28b0ffc 41
sgrsn 0:33bfb28b0ffc 42 /// This enum defines the Jrk's error bits. See the "Error handling" section of
sgrsn 0:33bfb28b0ffc 43 /// the Jrk G2 user's guide for more information about what these errors mean.
sgrsn 0:33bfb28b0ffc 44 ///
sgrsn 0:33bfb28b0ffc 45 /// See JrkG2Base::getErrorFlagsHalting() and JrkG2Base::getErrorFlagsOccurred().
sgrsn 0:33bfb28b0ffc 46 enum JrkG2Error
sgrsn 0:33bfb28b0ffc 47 {
sgrsn 0:33bfb28b0ffc 48 AwaitingCommand = 0,
sgrsn 0:33bfb28b0ffc 49 NoPower = 1,
sgrsn 0:33bfb28b0ffc 50 MotorDriver = 2,
sgrsn 0:33bfb28b0ffc 51 InputInvalid = 3,
sgrsn 0:33bfb28b0ffc 52 InputDisconnect = 4,
sgrsn 0:33bfb28b0ffc 53 FeedbackDisconnect = 5,
sgrsn 0:33bfb28b0ffc 54 SoftOvercurrent = 6,
sgrsn 0:33bfb28b0ffc 55 SerialSignal = 7,
sgrsn 0:33bfb28b0ffc 56 SerialOverrun = 8,
sgrsn 0:33bfb28b0ffc 57 SerialBufferFull = 9,
sgrsn 0:33bfb28b0ffc 58 SerialCrc = 10,
sgrsn 0:33bfb28b0ffc 59 SerialProtocol = 11,
sgrsn 0:33bfb28b0ffc 60 SerialTimeout = 12,
sgrsn 0:33bfb28b0ffc 61 HardOvercurrent = 13,
sgrsn 0:33bfb28b0ffc 62 };
sgrsn 0:33bfb28b0ffc 63
sgrsn 0:33bfb28b0ffc 64 /// This enum defines the Jrk G2 command bytes which are used for its serial and
sgrsn 0:33bfb28b0ffc 65 /// I2C interfaces. These bytes are used by the library and you should not need
sgrsn 0:33bfb28b0ffc 66 /// to use them.
sgrsn 0:33bfb28b0ffc 67 enum JrkG2Command
sgrsn 0:33bfb28b0ffc 68 {
sgrsn 0:33bfb28b0ffc 69 SetTarget = 0xC0,
sgrsn 0:33bfb28b0ffc 70 SetTargetLowResRev = 0xE0,
sgrsn 0:33bfb28b0ffc 71 SetTargetLowResFwd = 0xE1,
sgrsn 0:33bfb28b0ffc 72 ForceDutyCycleTarget = 0xF2,
sgrsn 0:33bfb28b0ffc 73 ForceDutyCycle = 0xF4,
sgrsn 0:33bfb28b0ffc 74 MotorOff = 0xFF,
sgrsn 0:33bfb28b0ffc 75 GetVariable8 = 0x80,
sgrsn 0:33bfb28b0ffc 76 GetVariable16 = 0xA0,
sgrsn 0:33bfb28b0ffc 77 GetEEPROMSettings = 0xE3,
sgrsn 0:33bfb28b0ffc 78 GetVariables = 0xE5,
sgrsn 0:33bfb28b0ffc 79 SetRAMSettings = 0xE6,
sgrsn 0:33bfb28b0ffc 80 GetRAMSettings = 0xEA,
sgrsn 0:33bfb28b0ffc 81 GetCurrentChoppingOccurrenceCount = 0xEC,
sgrsn 0:33bfb28b0ffc 82 };
sgrsn 0:33bfb28b0ffc 83
sgrsn 0:33bfb28b0ffc 84 /// This enum defines the modes in which the Jrk G2's duty cycle target or duty
sgrsn 0:33bfb28b0ffc 85 /// cycle, normally derived from the output of its PID algorithm, can be
sgrsn 0:33bfb28b0ffc 86 /// overridden with a forced value.
sgrsn 0:33bfb28b0ffc 87 ///
sgrsn 0:33bfb28b0ffc 88 /// See JrkG2Base::getForceMode(), JrkG2Base::forceDutyCycleTarget(), and
sgrsn 0:33bfb28b0ffc 89 /// JrkG2Base::forceDutyCycle().
sgrsn 0:33bfb28b0ffc 90 enum JrkG2ForceMode
sgrsn 0:33bfb28b0ffc 91 {
sgrsn 0:33bfb28b0ffc 92 None = 0,
sgrsn 0:33bfb28b0ffc 93 DutyCycleTarget = 1,
sgrsn 0:33bfb28b0ffc 94 DutyCycle = 2,
sgrsn 0:33bfb28b0ffc 95 };
sgrsn 0:33bfb28b0ffc 96
sgrsn 0:33bfb28b0ffc 97 /// This enum defines the possible causes of a full microcontroller reset for
sgrsn 0:33bfb28b0ffc 98 /// the Jrk G2.
sgrsn 0:33bfb28b0ffc 99 ///
sgrsn 0:33bfb28b0ffc 100 /// See JrkG2Base::getDeviceReset().
sgrsn 0:33bfb28b0ffc 101 enum JrkG2Reset
sgrsn 0:33bfb28b0ffc 102 {
sgrsn 0:33bfb28b0ffc 103 PowerUp = 0,
sgrsn 0:33bfb28b0ffc 104 Brownout = 1,
sgrsn 0:33bfb28b0ffc 105 ResetLine = 2,
sgrsn 0:33bfb28b0ffc 106 Watchdog = 4,
sgrsn 0:33bfb28b0ffc 107 Software = 8,
sgrsn 0:33bfb28b0ffc 108 StackOverflow = 16,
sgrsn 0:33bfb28b0ffc 109 StackUnderflow = 32,
sgrsn 0:33bfb28b0ffc 110 };
sgrsn 0:33bfb28b0ffc 111
sgrsn 0:33bfb28b0ffc 112 /// This enum defines the Jrk G2's control and feedback pins
sgrsn 0:33bfb28b0ffc 113 enum JrkG2Pin
sgrsn 0:33bfb28b0ffc 114 {
sgrsn 0:33bfb28b0ffc 115 SCL = 0,
sgrsn 0:33bfb28b0ffc 116 SDA = 1,
sgrsn 0:33bfb28b0ffc 117 TX = 2,
sgrsn 0:33bfb28b0ffc 118 RX = 3,
sgrsn 0:33bfb28b0ffc 119 RC = 4,
sgrsn 0:33bfb28b0ffc 120 AUX = 5,
sgrsn 0:33bfb28b0ffc 121 FBA = 6,
sgrsn 0:33bfb28b0ffc 122 FBT = 7,
sgrsn 0:33bfb28b0ffc 123 };
sgrsn 0:33bfb28b0ffc 124
sgrsn 0:33bfb28b0ffc 125 /// This enum defines the bits in the Jrk G2's Options Byte 3 register. You
sgrsn 0:33bfb28b0ffc 126 /// should not need to use this directly. See JrkG2Base::setResetIntegral(),
sgrsn 0:33bfb28b0ffc 127 /// JrkG2Base::getResetIntegral(), JrkG2Base::setCoastWhenOff(), and
sgrsn 0:33bfb28b0ffc 128 /// JrkG2Base::getCoastWhenOff().
sgrsn 0:33bfb28b0ffc 129 enum JrkG2OptionsByte3
sgrsn 0:33bfb28b0ffc 130 {
sgrsn 0:33bfb28b0ffc 131 ResetIntegral = 0,
sgrsn 0:33bfb28b0ffc 132 CoastWhenOff = 1,
sgrsn 0:33bfb28b0ffc 133 };
sgrsn 0:33bfb28b0ffc 134
sgrsn 0:33bfb28b0ffc 135 /// This is a base class used to represent a connection to a Jrk G2. This class
sgrsn 0:33bfb28b0ffc 136 /// provides high-level functions for sending commands to the Jrk and reading
sgrsn 0:33bfb28b0ffc 137 /// data from it.
sgrsn 0:33bfb28b0ffc 138 ///
sgrsn 0:33bfb28b0ffc 139 /// See the subclasses of this class, JrkG2Serial and JrkG2I2C.
sgrsn 0:33bfb28b0ffc 140 class JrkG2Base
sgrsn 0:33bfb28b0ffc 141 {
sgrsn 0:33bfb28b0ffc 142 public:
sgrsn 0:33bfb28b0ffc 143
sgrsn 0:33bfb28b0ffc 144 JrkG2Base()
sgrsn 0:33bfb28b0ffc 145 {
sgrsn 0:33bfb28b0ffc 146 _lastError = 0;
sgrsn 0:33bfb28b0ffc 147 }
sgrsn 0:33bfb28b0ffc 148
sgrsn 0:33bfb28b0ffc 149 /// Returns 0 if the last communication with the device was successful, and
sgrsn 0:33bfb28b0ffc 150 /// non-zero if there was an error.
sgrsn 0:33bfb28b0ffc 151 uint8_t getLastError()
sgrsn 0:33bfb28b0ffc 152 {
sgrsn 0:33bfb28b0ffc 153 return _lastError;
sgrsn 0:33bfb28b0ffc 154 }
sgrsn 0:33bfb28b0ffc 155 /// Sets the target of the Jrk to a value in the range 0 to 4095.
sgrsn 0:33bfb28b0ffc 156 ///
sgrsn 0:33bfb28b0ffc 157 /// The target can represent a target duty cycle, speed, or position depending
sgrsn 0:33bfb28b0ffc 158 /// on the feedback mode.
sgrsn 0:33bfb28b0ffc 159 ///
sgrsn 0:33bfb28b0ffc 160 /// Example usage:
sgrsn 0:33bfb28b0ffc 161 /// ```
sgrsn 0:33bfb28b0ffc 162 /// jrkG2.setTarget(3000);
sgrsn 0:33bfb28b0ffc 163 /// ```
sgrsn 0:33bfb28b0ffc 164 ///
sgrsn 0:33bfb28b0ffc 165 /// This functions sends a "Set target" command to the jrk, which clears the
sgrsn 0:33bfb28b0ffc 166 /// "Awaiting command" error bit and (if the input mode is serial) will set
sgrsn 0:33bfb28b0ffc 167 /// the jrk's input and target variables.
sgrsn 0:33bfb28b0ffc 168 ///
sgrsn 0:33bfb28b0ffc 169 /// See also setTargetLowResRev(), setTargetLowResFwd(), getTarget(),
sgrsn 0:33bfb28b0ffc 170 /// forceDutyCycleTarget(), forceDutyCycle().
sgrsn 0:33bfb28b0ffc 171
sgrsn 0:33bfb28b0ffc 172 void setTarget(uint16_t target)
sgrsn 0:33bfb28b0ffc 173 {
sgrsn 0:33bfb28b0ffc 174 // lower 5 bits in command byte
sgrsn 0:33bfb28b0ffc 175 // upper 7 bits in data byte
sgrsn 0:33bfb28b0ffc 176 if (target > 4095) { target = 4095; }
sgrsn 0:33bfb28b0ffc 177 commandW7((uint8_t)SetTarget | (target & 0x1F), target >> 5);
sgrsn 0:33bfb28b0ffc 178 }
sgrsn 0:33bfb28b0ffc 179
sgrsn 0:33bfb28b0ffc 180 /// Sets the target of the Jrk based on a value in the range 0 to 127.
sgrsn 0:33bfb28b0ffc 181 ///
sgrsn 0:33bfb28b0ffc 182 /// If the value is zero, then this command is equivalent to the "Stop motor"
sgrsn 0:33bfb28b0ffc 183 /// command. Otherwise, the value maps to a 12-bit target less than 2048.
sgrsn 0:33bfb28b0ffc 184 ///
sgrsn 0:33bfb28b0ffc 185 /// If the feedback mode is Analog or Tachometer, then the formula is
sgrsn 0:33bfb28b0ffc 186 /// Target = 2048 - 16 * value.
sgrsn 0:33bfb28b0ffc 187 ///
sgrsn 0:33bfb28b0ffc 188 /// If the feedback mode is None (speed control mode), then the formula is
sgrsn 0:33bfb28b0ffc 189 /// Target = 2048 - (600 / 127) * value. This means that a value of
sgrsn 0:33bfb28b0ffc 190 /// 127 will set the duty cycle target to full-speed reverse (-600).
sgrsn 0:33bfb28b0ffc 191 ///
sgrsn 0:33bfb28b0ffc 192 /// Example usage:
sgrsn 0:33bfb28b0ffc 193 /// ```
sgrsn 0:33bfb28b0ffc 194 /// jrkG2.setTargetLowResRev(100);
sgrsn 0:33bfb28b0ffc 195 /// ```
sgrsn 0:33bfb28b0ffc 196 ///
sgrsn 0:33bfb28b0ffc 197 /// This function sends a "Set target low resolution reverse" command to the
sgrsn 0:33bfb28b0ffc 198 /// Jrk G2, which clears the "Awaiting command" error bit and (if the input
sgrsn 0:33bfb28b0ffc 199 /// mode is serial) will set the jrk's input and target variables.
sgrsn 0:33bfb28b0ffc 200 ///
sgrsn 0:33bfb28b0ffc 201 /// See also setTargetLowResFwd(), setTarget(), getTarget(), and stopMotor().
sgrsn 0:33bfb28b0ffc 202 void setTargetLowResRev(uint8_t target)
sgrsn 0:33bfb28b0ffc 203 {
sgrsn 0:33bfb28b0ffc 204 if (target > 127) { target = 127; }
sgrsn 0:33bfb28b0ffc 205 commandW7(SetTargetLowResRev, target);
sgrsn 0:33bfb28b0ffc 206 }
sgrsn 0:33bfb28b0ffc 207
sgrsn 0:33bfb28b0ffc 208 /// Sets the target of the Jrk based on a value in the range 0 to 127 that
sgrsn 0:33bfb28b0ffc 209 /// maps to a 12-bit target of 2048 or greater.
sgrsn 0:33bfb28b0ffc 210 ///
sgrsn 0:33bfb28b0ffc 211 /// If the feedback mode is Analog or Tachometer, then the formula is
sgrsn 0:33bfb28b0ffc 212 /// Target = 2048 + 16 * value.
sgrsn 0:33bfb28b0ffc 213 ///
sgrsn 0:33bfb28b0ffc 214 /// If the feedback mode is None (speed control mode), then the formula is
sgrsn 0:33bfb28b0ffc 215 /// Target = 2048 + (600 / 127) * value. This means that a value of 127 will
sgrsn 0:33bfb28b0ffc 216 /// set the duty cycle target to full-speed reverse (-600), while a value of
sgrsn 0:33bfb28b0ffc 217 /// zero will make the motor stop.
sgrsn 0:33bfb28b0ffc 218 ///
sgrsn 0:33bfb28b0ffc 219 /// Example usage:
sgrsn 0:33bfb28b0ffc 220 /// ```
sgrsn 0:33bfb28b0ffc 221 /// jrkG2.setTargetLowResFwd(100);
sgrsn 0:33bfb28b0ffc 222 /// ```
sgrsn 0:33bfb28b0ffc 223 ///
sgrsn 0:33bfb28b0ffc 224 /// This function sends a "Set target low resolution forward" command to the
sgrsn 0:33bfb28b0ffc 225 /// Jrk G2, which clears the "Awaiting command" error bit and (if the input
sgrsn 0:33bfb28b0ffc 226 /// mode is serial) will set the jrk's input and target variables.
sgrsn 0:33bfb28b0ffc 227 ///
sgrsn 0:33bfb28b0ffc 228 /// See also setTargetLowResRev(), setTarget(), and getTarget().
sgrsn 0:33bfb28b0ffc 229 void setTargetLowResFwd(uint8_t target)
sgrsn 0:33bfb28b0ffc 230 {
sgrsn 0:33bfb28b0ffc 231 if (target > 127) { target = 127; }
sgrsn 0:33bfb28b0ffc 232 commandW7(SetTargetLowResFwd, target);
sgrsn 0:33bfb28b0ffc 233 }
sgrsn 0:33bfb28b0ffc 234
sgrsn 0:33bfb28b0ffc 235 /// Forces the duty cycle target of the Jrk to a value in the range
sgrsn 0:33bfb28b0ffc 236 /// -600 to +600.
sgrsn 0:33bfb28b0ffc 237 ///
sgrsn 0:33bfb28b0ffc 238 /// The Jrk will ignore the results of the usual algorithm for choosing the duty
sgrsn 0:33bfb28b0ffc 239 /// cycle target, and instead set it to be equal to the target specified by this
sgrsn 0:33bfb28b0ffc 240 /// command. The Jrk will set its 'Integral' variable to 0 while in this mode.
sgrsn 0:33bfb28b0ffc 241 ///
sgrsn 0:33bfb28b0ffc 242 /// This is useful if the Jrk is configured to use feedback but you want to take
sgrsn 0:33bfb28b0ffc 243 /// control of the motor for some time, while still respecting errors and motor
sgrsn 0:33bfb28b0ffc 244 /// limits as usual.
sgrsn 0:33bfb28b0ffc 245 ///
sgrsn 0:33bfb28b0ffc 246 /// Example usage:
sgrsn 0:33bfb28b0ffc 247 /// ```
sgrsn 0:33bfb28b0ffc 248 /// jrkG2.forceDutyCycleTarget(250);
sgrsn 0:33bfb28b0ffc 249 /// ```
sgrsn 0:33bfb28b0ffc 250 ///
sgrsn 0:33bfb28b0ffc 251 /// This function sends a "Force duty cycle target" command to the Jrk G2, which
sgrsn 0:33bfb28b0ffc 252 /// clears the "Awaiting command" error bit.
sgrsn 0:33bfb28b0ffc 253 ///
sgrsn 0:33bfb28b0ffc 254 /// To get out of this mode, use setTarget(), setTargetLowResFwd(),
sgrsn 0:33bfb28b0ffc 255 /// setTargetLowResRev(), forceDutyCycle(), or stopMotor().
sgrsn 0:33bfb28b0ffc 256 ///
sgrsn 0:33bfb28b0ffc 257 /// See also getForceMode().
sgrsn 0:33bfb28b0ffc 258 void forceDutyCycleTarget(int16_t dutyCycle)
sgrsn 0:33bfb28b0ffc 259 {
sgrsn 0:33bfb28b0ffc 260 if (dutyCycle > 600) { dutyCycle = 600; }
sgrsn 0:33bfb28b0ffc 261 if (dutyCycle < -600) { dutyCycle = -600; }
sgrsn 0:33bfb28b0ffc 262 commandWs14(ForceDutyCycleTarget, dutyCycle);
sgrsn 0:33bfb28b0ffc 263 }
sgrsn 0:33bfb28b0ffc 264
sgrsn 0:33bfb28b0ffc 265 /// Forces the duty cycle of the Jrk to a value in the range -600 to +600.
sgrsn 0:33bfb28b0ffc 266 ///
sgrsn 0:33bfb28b0ffc 267 /// The jrk will ignore the results of the usual algorithm for choosing the
sgrsn 0:33bfb28b0ffc 268 /// duty cycle, and instead set it to be equal to the value specified by this
sgrsn 0:33bfb28b0ffc 269 /// command, ignoring all motor limits except the maximum duty cycle
sgrsn 0:33bfb28b0ffc 270 /// parameters, and ignoring the 'Input invalid', 'Input disconnect', and
sgrsn 0:33bfb28b0ffc 271 /// 'Feedback disconnect' errors. This command will have an immediate effect,
sgrsn 0:33bfb28b0ffc 272 /// regardless of the PID period. The jrk will set its 'Integral' variable to
sgrsn 0:33bfb28b0ffc 273 /// 0 while in this mode.
sgrsn 0:33bfb28b0ffc 274 ///
sgrsn 0:33bfb28b0ffc 275 /// This is useful if the jrk is configured to use feedback but you want to take
sgrsn 0:33bfb28b0ffc 276 /// control of the motor for some time, without respecting most motor limits.
sgrsn 0:33bfb28b0ffc 277 ///
sgrsn 0:33bfb28b0ffc 278 /// Example usage:
sgrsn 0:33bfb28b0ffc 279 /// ```
sgrsn 0:33bfb28b0ffc 280 /// jrkG2.forceDutyCycle(250);
sgrsn 0:33bfb28b0ffc 281 /// ```
sgrsn 0:33bfb28b0ffc 282 ///
sgrsn 0:33bfb28b0ffc 283 /// This function sends a "Force duty cycle" command to the Jrk G2, which
sgrsn 0:33bfb28b0ffc 284 /// clears the "Awaiting command" error bit.
sgrsn 0:33bfb28b0ffc 285 ///
sgrsn 0:33bfb28b0ffc 286 /// To get out of this mode, use setTarget(), setTargetLowResFwd(),
sgrsn 0:33bfb28b0ffc 287 /// setTargetLowResRev(), forceDutyCycleTarget(), or stopMotor().
sgrsn 0:33bfb28b0ffc 288 ///
sgrsn 0:33bfb28b0ffc 289 /// See also getForceMode().
sgrsn 0:33bfb28b0ffc 290 void forceDutyCycle(int16_t dutyCycle)
sgrsn 0:33bfb28b0ffc 291 {
sgrsn 0:33bfb28b0ffc 292 if (dutyCycle > 600) { dutyCycle = 600; }
sgrsn 0:33bfb28b0ffc 293 if (dutyCycle < -600) { dutyCycle = -600; }
sgrsn 0:33bfb28b0ffc 294 commandWs14(ForceDutyCycle, dutyCycle);
sgrsn 0:33bfb28b0ffc 295 }
sgrsn 0:33bfb28b0ffc 296
sgrsn 0:33bfb28b0ffc 297 /// Turns the motor off.
sgrsn 0:33bfb28b0ffc 298 ///
sgrsn 0:33bfb28b0ffc 299 /// This function sends a "Stop motor" command to the Jrk, which sets the
sgrsn 0:33bfb28b0ffc 300 /// "Awaiting command" error bit. The Jrk will respect the configured
sgrsn 0:33bfb28b0ffc 301 /// deceleration limit while decelerating to a duty cycle of 0, unless the
sgrsn 0:33bfb28b0ffc 302 /// "Awaiting command" error has been configured as a hard error. Once the duty
sgrsn 0:33bfb28b0ffc 303 /// cycle reaches zero, the Jrk will either brake or coast.
sgrsn 0:33bfb28b0ffc 304 ///
sgrsn 0:33bfb28b0ffc 305 /// Example usage:
sgrsn 0:33bfb28b0ffc 306 /// ```
sgrsn 0:33bfb28b0ffc 307 /// jrkG2.stopMotor();
sgrsn 0:33bfb28b0ffc 308 /// ```
sgrsn 0:33bfb28b0ffc 309 void stopMotor()
sgrsn 0:33bfb28b0ffc 310 {
sgrsn 0:33bfb28b0ffc 311 commandQuick(MotorOff);
sgrsn 0:33bfb28b0ffc 312 }
sgrsn 0:33bfb28b0ffc 313
sgrsn 0:33bfb28b0ffc 314 ///@}
sgrsn 0:33bfb28b0ffc 315
sgrsn 0:33bfb28b0ffc 316 ///\name Variable reading commands
sgrsn 0:33bfb28b0ffc 317 ///@{
sgrsn 0:33bfb28b0ffc 318
sgrsn 0:33bfb28b0ffc 319 /// Gets the input variable.
sgrsn 0:33bfb28b0ffc 320 ///
sgrsn 0:33bfb28b0ffc 321 /// The input variable is a raw, unscaled value representing a measurement
sgrsn 0:33bfb28b0ffc 322 /// taken by the Jrk of the input to the system. In serial input mode, the
sgrsn 0:33bfb28b0ffc 323 /// input is equal to the target, which can be set to any value from 0 to 4095
sgrsn 0:33bfb28b0ffc 324 /// using serial commands. In analog input mode, the input is a measurement
sgrsn 0:33bfb28b0ffc 325 /// of the voltage on the SDA pin, where 0 is 0 V and 4092 is a voltage equal
sgrsn 0:33bfb28b0ffc 326 /// to the Jrk's 5V pin (approximately 4.8 V). In RC input mode, the input is
sgrsn 0:33bfb28b0ffc 327 /// the duration of the last RC pulse measured, in units of 2/3 us.
sgrsn 0:33bfb28b0ffc 328 ///
sgrsn 0:33bfb28b0ffc 329 /// See the Jrk G2 user's guide for more information about input modes.
sgrsn 0:33bfb28b0ffc 330 ///
sgrsn 0:33bfb28b0ffc 331 /// See also getTarget() and setTarget().
sgrsn 0:33bfb28b0ffc 332 uint16_t getInput()
sgrsn 0:33bfb28b0ffc 333 {
sgrsn 0:33bfb28b0ffc 334 return getVar16SingleByte(Input);
sgrsn 0:33bfb28b0ffc 335 }
sgrsn 0:33bfb28b0ffc 336
sgrsn 0:33bfb28b0ffc 337 /// Gets the target variable.
sgrsn 0:33bfb28b0ffc 338 ///
sgrsn 0:33bfb28b0ffc 339 /// In serial input mode, the target is set directly with serial commands. In
sgrsn 0:33bfb28b0ffc 340 /// the other input modes, the target is computed by scaling the input, using
sgrsn 0:33bfb28b0ffc 341 /// the configurable input scaling settings.
sgrsn 0:33bfb28b0ffc 342 ///
sgrsn 0:33bfb28b0ffc 343 /// See also setTarget() and getInput().
sgrsn 0:33bfb28b0ffc 344 uint16_t getTarget()
sgrsn 0:33bfb28b0ffc 345 {
sgrsn 0:33bfb28b0ffc 346 return getVar16SingleByte(Target);
sgrsn 0:33bfb28b0ffc 347 }
sgrsn 0:33bfb28b0ffc 348
sgrsn 0:33bfb28b0ffc 349 /// Gets the feedback variable.
sgrsn 0:33bfb28b0ffc 350 ///
sgrsn 0:33bfb28b0ffc 351 /// The feedback variable is a raw, unscaled feedback value, representing a
sgrsn 0:33bfb28b0ffc 352 /// measurement taken by the Jrk of the output of the system. In analog
sgrsn 0:33bfb28b0ffc 353 /// feedback mode, the feedback is a measurement of the voltage on the FBA
sgrsn 0:33bfb28b0ffc 354 /// pin, where 0 is 0 V and 4092 is a voltage equal to the Jrk's 5V pin
sgrsn 0:33bfb28b0ffc 355 /// (approximately 4.8 V). In frequency feedback mode, the feedback is 2048
sgrsn 0:33bfb28b0ffc 356 /// plus or minus a measurement of the frequency of pulses on the FBT pin. In
sgrsn 0:33bfb28b0ffc 357 /// feedback mode none (open-loop speed control mode), the feedback is always
sgrsn 0:33bfb28b0ffc 358 /// zero.
sgrsn 0:33bfb28b0ffc 359 ///
sgrsn 0:33bfb28b0ffc 360 /// See also getScaledFeedback().
sgrsn 0:33bfb28b0ffc 361 uint16_t getFeedback()
sgrsn 0:33bfb28b0ffc 362 {
sgrsn 0:33bfb28b0ffc 363 return getVar16SingleByte(Feedback);
sgrsn 0:33bfb28b0ffc 364 }
sgrsn 0:33bfb28b0ffc 365
sgrsn 0:33bfb28b0ffc 366 /// Gets the scaled feedback variable.
sgrsn 0:33bfb28b0ffc 367 ///
sgrsn 0:33bfb28b0ffc 368 /// The scaled feedback is calculated from the feedback using the Jrk's
sgrsn 0:33bfb28b0ffc 369 /// configurable feedback scaling settings.
sgrsn 0:33bfb28b0ffc 370 ///
sgrsn 0:33bfb28b0ffc 371 /// See also getFeedback().
sgrsn 0:33bfb28b0ffc 372 uint16_t getScaledFeedback()
sgrsn 0:33bfb28b0ffc 373 {
sgrsn 0:33bfb28b0ffc 374 return getVar16SingleByte(ScaledFeedback);
sgrsn 0:33bfb28b0ffc 375 }
sgrsn 0:33bfb28b0ffc 376
sgrsn 0:33bfb28b0ffc 377 /// Gets the integral variable.
sgrsn 0:33bfb28b0ffc 378 ///
sgrsn 0:33bfb28b0ffc 379 /// In general, every PID period, the error (scaled feedback minus target) is
sgrsn 0:33bfb28b0ffc 380 /// added to the integral (also known as error sum). There are several
sgrsn 0:33bfb28b0ffc 381 /// settings to configure the behavior of this variable, and it is used in the
sgrsn 0:33bfb28b0ffc 382 /// PID calculation.
sgrsn 0:33bfb28b0ffc 383 int16_t getIntegral()
sgrsn 0:33bfb28b0ffc 384 {
sgrsn 0:33bfb28b0ffc 385 return getVar16SingleByte(Integral);
sgrsn 0:33bfb28b0ffc 386 }
sgrsn 0:33bfb28b0ffc 387
sgrsn 0:33bfb28b0ffc 388 /// Gets the duty cycle target variable.
sgrsn 0:33bfb28b0ffc 389 ///
sgrsn 0:33bfb28b0ffc 390 /// In general, this is the duty cycle that the Jrk is trying to achieve. A
sgrsn 0:33bfb28b0ffc 391 /// value of -600 or less means full speed reverse, while a value of 600 or
sgrsn 0:33bfb28b0ffc 392 /// more means full speed forward. A value of 0 means stopped (braking or
sgrsn 0:33bfb28b0ffc 393 /// coasting). In no feedback mode (open-loop speed control mode), the duty
sgrsn 0:33bfb28b0ffc 394 /// cycle target is normally the target minus 2048. In other feedback modes,
sgrsn 0:33bfb28b0ffc 395 /// the duty cycle target is normally the sum of the proportional, integral,
sgrsn 0:33bfb28b0ffc 396 /// and derivative terms of the PID algorithm. In any mode, the duty cycle
sgrsn 0:33bfb28b0ffc 397 /// target can be overridden with forceDutyCycleTarget().
sgrsn 0:33bfb28b0ffc 398 ///
sgrsn 0:33bfb28b0ffc 399 /// If an error is stopping the motor, the duty cycle target variable will not
sgrsn 0:33bfb28b0ffc 400 /// be directly affected, but the duty cycle variable will change/decelerate
sgrsn 0:33bfb28b0ffc 401 /// to zero.
sgrsn 0:33bfb28b0ffc 402 ///
sgrsn 0:33bfb28b0ffc 403 /// See also getDutyCycle(), getLastDutyCycle(), and forceDutyCycleTarget().
sgrsn 0:33bfb28b0ffc 404 int16_t getDutyCycleTarget()
sgrsn 0:33bfb28b0ffc 405 {
sgrsn 0:33bfb28b0ffc 406 return getVar16SingleByte(DutyCycleTarget);
sgrsn 0:33bfb28b0ffc 407 }
sgrsn 0:33bfb28b0ffc 408
sgrsn 0:33bfb28b0ffc 409 /// Gets the duty cycle variable.
sgrsn 0:33bfb28b0ffc 410 ///
sgrsn 0:33bfb28b0ffc 411 /// The duty cycle variable is the duty cycle at which the jrk is currently
sgrsn 0:33bfb28b0ffc 412 /// driving the motor. A value of -600 means full speed reverse, while a
sgrsn 0:33bfb28b0ffc 413 /// value of 600 means full speed forward. A value of 0 means stopped
sgrsn 0:33bfb28b0ffc 414 /// (braking or coasting). The duty cycle could be different from the duty
sgrsn 0:33bfb28b0ffc 415 /// cycle target because it normally takes into account the Jrk's configurable
sgrsn 0:33bfb28b0ffc 416 /// motor limits and errors. The duty cycle can be overridden with
sgrsn 0:33bfb28b0ffc 417 /// forceDutyCycle().
sgrsn 0:33bfb28b0ffc 418 ///
sgrsn 0:33bfb28b0ffc 419 /// See also getLastDutyCycle(), getDutyCycleTarget(), and forceDutyCycle().
sgrsn 0:33bfb28b0ffc 420 int16_t getDutyCycle()
sgrsn 0:33bfb28b0ffc 421 {
sgrsn 0:33bfb28b0ffc 422 return getVar16SingleByte(DutyCycle);
sgrsn 0:33bfb28b0ffc 423 }
sgrsn 0:33bfb28b0ffc 424
sgrsn 0:33bfb28b0ffc 425 /// Gets the most-significant 8 bits of the "Current" variable.
sgrsn 0:33bfb28b0ffc 426 ///
sgrsn 0:33bfb28b0ffc 427 /// The Jrk G2 supports this command mainly to be compatible with older Jrk
sgrsn 0:33bfb28b0ffc 428 /// models. In new applications, we recommend using getCurrent(), which
sgrsn 0:33bfb28b0ffc 429 /// provides a higher-resolution measurement.
sgrsn 0:33bfb28b0ffc 430 uint8_t getCurrentLowRes()
sgrsn 0:33bfb28b0ffc 431 {
sgrsn 0:33bfb28b0ffc 432 return getVar8SingleByte(CurrentLowRes);
sgrsn 0:33bfb28b0ffc 433 }
sgrsn 0:33bfb28b0ffc 434
sgrsn 0:33bfb28b0ffc 435 /// Returns true if the Jrk's most recent PID cycle took more time than the
sgrsn 0:33bfb28b0ffc 436 /// configured PID period. This indicates that the Jrk does not have time to
sgrsn 0:33bfb28b0ffc 437 /// perform all of its tasks at the desired rate. Most often, this is caused
sgrsn 0:33bfb28b0ffc 438 /// by the configured number of analog samples for input, feedback, or current
sgrsn 0:33bfb28b0ffc 439 /// sensing being too high for the configured PID period.
sgrsn 0:33bfb28b0ffc 440 bool getPIDPeriodExceeded()
sgrsn 0:33bfb28b0ffc 441 {
sgrsn 0:33bfb28b0ffc 442 return getVar8SingleByte(PIDPeriodExceeded);
sgrsn 0:33bfb28b0ffc 443 }
sgrsn 0:33bfb28b0ffc 444
sgrsn 0:33bfb28b0ffc 445 /// Get the "PID period count" variable, which is the number of PID periods
sgrsn 0:33bfb28b0ffc 446 /// that have elapsed. It resets to 0 after reaching 65535. The duration of
sgrsn 0:33bfb28b0ffc 447 /// the PID period can be configured.
sgrsn 0:33bfb28b0ffc 448 uint16_t getPIDPeriodCount()
sgrsn 0:33bfb28b0ffc 449 {
sgrsn 0:33bfb28b0ffc 450 return getVar16SingleByte(PIDPeriodCount);
sgrsn 0:33bfb28b0ffc 451 }
sgrsn 0:33bfb28b0ffc 452
sgrsn 0:33bfb28b0ffc 453 /// Gets the errors that are currently stopping the motor and clears any
sgrsn 0:33bfb28b0ffc 454 /// latched errors that are enabled. Calling this function is equivalent to
sgrsn 0:33bfb28b0ffc 455 /// reading the "Currently stopping motor?" column in the Errors tab of the
sgrsn 0:33bfb28b0ffc 456 /// configuration utility, and then clicking the "Clear Errors" button.
sgrsn 0:33bfb28b0ffc 457 ///
sgrsn 0:33bfb28b0ffc 458 /// Each bit in the returned register represents a different error. The bits
sgrsn 0:33bfb28b0ffc 459 /// are defined in the ::JrkG2Error enum.
sgrsn 0:33bfb28b0ffc 460 ///
sgrsn 0:33bfb28b0ffc 461 /// Example usage:
sgrsn 0:33bfb28b0ffc 462 /// ```
sgrsn 0:33bfb28b0ffc 463 /// uint16_t errors = jrk.getErrorFlagsHalting();
sgrsn 0:33bfb28b0ffc 464 /// if (errors & (1 << (uint8_t)JrkG2Error::NoPower))
sgrsn 0:33bfb28b0ffc 465 /// {
sgrsn 0:33bfb28b0ffc 466 /// // handle loss of power
sgrsn 0:33bfb28b0ffc 467 /// }
sgrsn 0:33bfb28b0ffc 468 /// ```
sgrsn 0:33bfb28b0ffc 469 ///
sgrsn 0:33bfb28b0ffc 470 /// It is possible to read this variable without clearing the bits in it using
sgrsn 0:33bfb28b0ffc 471 /// a getVariables().
sgrsn 0:33bfb28b0ffc 472 ///
sgrsn 0:33bfb28b0ffc 473 /// See also getErrorFlagsOccurred().
sgrsn 0:33bfb28b0ffc 474 uint16_t getErrorFlagsHalting()
sgrsn 0:33bfb28b0ffc 475 {
sgrsn 0:33bfb28b0ffc 476 return getVar16SingleByte(ErrorFlagsHalting);
sgrsn 0:33bfb28b0ffc 477 }
sgrsn 0:33bfb28b0ffc 478
sgrsn 0:33bfb28b0ffc 479 /// Gets the errors that have occurred since the last time this function was
sgrsn 0:33bfb28b0ffc 480 /// called. Unlike getErrorFlagsHalting(), calling this function has no
sgrsn 0:33bfb28b0ffc 481 /// effect on the motor.
sgrsn 0:33bfb28b0ffc 482 ///
sgrsn 0:33bfb28b0ffc 483 /// Note that the Jrk G2 Control Center constantly clears the bits in this
sgrsn 0:33bfb28b0ffc 484 /// register, so if you are running the Jrk G2 Control Center then you will
sgrsn 0:33bfb28b0ffc 485 /// not be able to reliably detect errors with this function.
sgrsn 0:33bfb28b0ffc 486 ///
sgrsn 0:33bfb28b0ffc 487 /// Each bit in the returned register represents a different error. The bits
sgrsn 0:33bfb28b0ffc 488 /// are defined in the ::JrkG2Error enum.
sgrsn 0:33bfb28b0ffc 489 ///
sgrsn 0:33bfb28b0ffc 490 /// Example usage:
sgrsn 0:33bfb28b0ffc 491 /// ```
sgrsn 0:33bfb28b0ffc 492 /// uint32_t errors = jrk.getErrorsOccurred();
sgrsn 0:33bfb28b0ffc 493 /// if (errors & (1 << (uint8_t)JrkG2Error::MotorDriver))
sgrsn 0:33bfb28b0ffc 494 /// {
sgrsn 0:33bfb28b0ffc 495 /// // handle a motor driver error
sgrsn 0:33bfb28b0ffc 496 /// }
sgrsn 0:33bfb28b0ffc 497 /// ```
sgrsn 0:33bfb28b0ffc 498 ///
sgrsn 0:33bfb28b0ffc 499 /// It is possible to read this variable without clearing the bits in it using
sgrsn 0:33bfb28b0ffc 500 /// getVariables().
sgrsn 0:33bfb28b0ffc 501 ///
sgrsn 0:33bfb28b0ffc 502 /// See also getErrorFlagsHalting().
sgrsn 0:33bfb28b0ffc 503 uint16_t getErrorFlagsOccurred()
sgrsn 0:33bfb28b0ffc 504 {
sgrsn 0:33bfb28b0ffc 505 return getVar16SingleByte(ErrorFlagsOccurred);
sgrsn 0:33bfb28b0ffc 506 }
sgrsn 0:33bfb28b0ffc 507
sgrsn 0:33bfb28b0ffc 508 /// Returns an indication of whether the Jrk's duty cycle target or duty cycle
sgrsn 0:33bfb28b0ffc 509 /// are being overridden with a forced value.
sgrsn 0:33bfb28b0ffc 510 ///
sgrsn 0:33bfb28b0ffc 511 /// Example usage:
sgrsn 0:33bfb28b0ffc 512 /// ```
sgrsn 0:33bfb28b0ffc 513 /// if (jrk.getForceMode() == JrkG2ForceMode::DutyCycleTarget)
sgrsn 0:33bfb28b0ffc 514 /// {
sgrsn 0:33bfb28b0ffc 515 /// // The duty cycle target is being overridden with a forced value.
sgrsn 0:33bfb28b0ffc 516 /// }
sgrsn 0:33bfb28b0ffc 517 /// ```
sgrsn 0:33bfb28b0ffc 518 ///
sgrsn 0:33bfb28b0ffc 519 /// See also forceDutyCycleTarget() and forceDutyCycle().
sgrsn 0:33bfb28b0ffc 520 JrkG2ForceMode getForceMode()
sgrsn 0:33bfb28b0ffc 521 {
sgrsn 0:33bfb28b0ffc 522 return (JrkG2ForceMode)(getVar8SingleByte(FlagByte1) & 0x03);
sgrsn 0:33bfb28b0ffc 523 }
sgrsn 0:33bfb28b0ffc 524
sgrsn 0:33bfb28b0ffc 525 /// Gets the measurement of the VIN voltage, in millivolts.
sgrsn 0:33bfb28b0ffc 526 ///
sgrsn 0:33bfb28b0ffc 527 /// Example usage:
sgrsn 0:33bfb28b0ffc 528 /// ```
sgrsn 0:33bfb28b0ffc 529 /// uint16_t vin = jrk.getVinVoltage();
sgrsn 0:33bfb28b0ffc 530 /// ```
sgrsn 0:33bfb28b0ffc 531 uint16_t getVinVoltage()
sgrsn 0:33bfb28b0ffc 532 {
sgrsn 0:33bfb28b0ffc 533 return getVar16SingleByte(VinVoltage);
sgrsn 0:33bfb28b0ffc 534 }
sgrsn 0:33bfb28b0ffc 535
sgrsn 0:33bfb28b0ffc 536 /// Gets the Jrk's measurement of the current running through the motor, in
sgrsn 0:33bfb28b0ffc 537 /// milliamps.
sgrsn 0:33bfb28b0ffc 538 uint16_t getCurrent()
sgrsn 0:33bfb28b0ffc 539 {
sgrsn 0:33bfb28b0ffc 540 return getVar16SingleByte(Current);
sgrsn 0:33bfb28b0ffc 541 }
sgrsn 0:33bfb28b0ffc 542
sgrsn 0:33bfb28b0ffc 543 /// Gets the cause of the Jrk's last full microcontroller reset.
sgrsn 0:33bfb28b0ffc 544 ///
sgrsn 0:33bfb28b0ffc 545 /// Example usage:
sgrsn 0:33bfb28b0ffc 546 /// ```
sgrsn 0:33bfb28b0ffc 547 /// if (jrk.getDeviceReset() == JrkG2Reset::Brownout)
sgrsn 0:33bfb28b0ffc 548 /// {
sgrsn 0:33bfb28b0ffc 549 /// // There was a brownout reset; the power supply could not keep up.
sgrsn 0:33bfb28b0ffc 550 /// }
sgrsn 0:33bfb28b0ffc 551 /// ```
sgrsn 0:33bfb28b0ffc 552 JrkG2Reset getDeviceReset()
sgrsn 0:33bfb28b0ffc 553 {
sgrsn 0:33bfb28b0ffc 554 return (JrkG2Reset)getVar8(DeviceReset);
sgrsn 0:33bfb28b0ffc 555 }
sgrsn 0:33bfb28b0ffc 556
sgrsn 0:33bfb28b0ffc 557 /// Gets the time since the last full reset of the Jrk's microcontroller, in
sgrsn 0:33bfb28b0ffc 558 /// milliseconds.
sgrsn 0:33bfb28b0ffc 559 ///
sgrsn 0:33bfb28b0ffc 560 /// Example usage:
sgrsn 0:33bfb28b0ffc 561 /// ```
sgrsn 0:33bfb28b0ffc 562 /// uint32_t upTime = jrk.getUpTime();
sgrsn 0:33bfb28b0ffc 563 /// ```
sgrsn 0:33bfb28b0ffc 564 uint32_t getUpTime()
sgrsn 0:33bfb28b0ffc 565 {
sgrsn 0:33bfb28b0ffc 566 return getVar32(UpTime);
sgrsn 0:33bfb28b0ffc 567 }
sgrsn 0:33bfb28b0ffc 568
sgrsn 0:33bfb28b0ffc 569 /// Gets the raw RC pulse width measured on the Jrk's RC input, in units of
sgrsn 0:33bfb28b0ffc 570 /// twelfths of a microsecond.
sgrsn 0:33bfb28b0ffc 571 ///
sgrsn 0:33bfb28b0ffc 572 /// Returns 0 if the RC input is missing or invalid.
sgrsn 0:33bfb28b0ffc 573 ///
sgrsn 0:33bfb28b0ffc 574 /// Example usage:
sgrsn 0:33bfb28b0ffc 575 /// ```
sgrsn 0:33bfb28b0ffc 576 /// uint16_t pulseWidth = jrk.getRCPulseWidth();
sgrsn 0:33bfb28b0ffc 577 /// if (pulseWidth != 0 && pulseWidth < 18000)
sgrsn 0:33bfb28b0ffc 578 /// {
sgrsn 0:33bfb28b0ffc 579 /// // Input is valid and pulse width is less than 1500 microseconds.
sgrsn 0:33bfb28b0ffc 580 /// }
sgrsn 0:33bfb28b0ffc 581 /// ```
sgrsn 0:33bfb28b0ffc 582 uint16_t getRCPulseWidth()
sgrsn 0:33bfb28b0ffc 583 {
sgrsn 0:33bfb28b0ffc 584 return getVar16(RCPulseWidth);
sgrsn 0:33bfb28b0ffc 585 }
sgrsn 0:33bfb28b0ffc 586
sgrsn 0:33bfb28b0ffc 587 /// Gets the raw pulse rate or pulse width measured on the Jrk's FBT
sgrsn 0:33bfb28b0ffc 588 /// (tachometer feedback) pin.
sgrsn 0:33bfb28b0ffc 589 ///
sgrsn 0:33bfb28b0ffc 590 /// In pulse counting mode, this will be the number of pulses on the FBT pin
sgrsn 0:33bfb28b0ffc 591 /// seen in the last N PID periods, where N is the "Pulse samples" setting.
sgrsn 0:33bfb28b0ffc 592 ///
sgrsn 0:33bfb28b0ffc 593 /// In pulse timing mode, this will be a measurement of the width of pulses on
sgrsn 0:33bfb28b0ffc 594 /// the FBT pin. This measurement is affected by several configurable
sgrsn 0:33bfb28b0ffc 595 /// settings.
sgrsn 0:33bfb28b0ffc 596 ///
sgrsn 0:33bfb28b0ffc 597 /// Example usage:
sgrsn 0:33bfb28b0ffc 598 /// ```
sgrsn 0:33bfb28b0ffc 599 /// uint16_t fbtReading = jrk.getFBTReading();
sgrsn 0:33bfb28b0ffc 600 /// ```
sgrsn 0:33bfb28b0ffc 601 uint16_t getFBTReading()
sgrsn 0:33bfb28b0ffc 602 {
sgrsn 0:33bfb28b0ffc 603 return getVar16(FBTReading);
sgrsn 0:33bfb28b0ffc 604 }
sgrsn 0:33bfb28b0ffc 605
sgrsn 0:33bfb28b0ffc 606 /// Gets the analog reading from the specified pin.
sgrsn 0:33bfb28b0ffc 607 ///
sgrsn 0:33bfb28b0ffc 608 /// The reading is left-justified, so 0xFFFE represents a voltage equal to the
sgrsn 0:33bfb28b0ffc 609 /// Jrk's 5V pin (approximately 4.8 V).
sgrsn 0:33bfb28b0ffc 610 ///
sgrsn 0:33bfb28b0ffc 611 /// Returns JrkG2InputNull if the analog reading is disabled or not ready or
sgrsn 0:33bfb28b0ffc 612 /// the pin is invalid.
sgrsn 0:33bfb28b0ffc 613 ///
sgrsn 0:33bfb28b0ffc 614 /// Example usage:
sgrsn 0:33bfb28b0ffc 615 /// ```
sgrsn 0:33bfb28b0ffc 616 /// uint16_t reading = getAnalogReading(JrkG2Pin::SDA);
sgrsn 0:33bfb28b0ffc 617 /// if (reading != JrkG2InputNull && reading < 32768)
sgrsn 0:33bfb28b0ffc 618 /// {
sgrsn 0:33bfb28b0ffc 619 /// // The reading is less than about 2.4 V.
sgrsn 0:33bfb28b0ffc 620 /// }
sgrsn 0:33bfb28b0ffc 621 /// ```
sgrsn 0:33bfb28b0ffc 622 uint16_t getAnalogReading(JrkG2Pin pin)
sgrsn 0:33bfb28b0ffc 623 {
sgrsn 0:33bfb28b0ffc 624 switch (pin)
sgrsn 0:33bfb28b0ffc 625 {
sgrsn 0:33bfb28b0ffc 626 case SDA:
sgrsn 0:33bfb28b0ffc 627 return getVar16(AnalogReadingSDA);
sgrsn 0:33bfb28b0ffc 628 case FBA:
sgrsn 0:33bfb28b0ffc 629 return getVar16(AnalogReadingFBA);
sgrsn 0:33bfb28b0ffc 630 default:
sgrsn 0:33bfb28b0ffc 631 return JrkG2InputNull;
sgrsn 0:33bfb28b0ffc 632 }
sgrsn 0:33bfb28b0ffc 633 }
sgrsn 0:33bfb28b0ffc 634
sgrsn 0:33bfb28b0ffc 635 /// Gets a digital reading from the specified pin.
sgrsn 0:33bfb28b0ffc 636 ///
sgrsn 0:33bfb28b0ffc 637 /// A return value of 0 means low while 1 means high. In most cases, pins
sgrsn 0:33bfb28b0ffc 638 /// configured as analog inputs cannot be read as digital inputs, so their
sgrsn 0:33bfb28b0ffc 639 /// values will be 0. See getAnalogReading() for those pins.
sgrsn 0:33bfb28b0ffc 640 ///
sgrsn 0:33bfb28b0ffc 641 /// Example usage:
sgrsn 0:33bfb28b0ffc 642 /// ```
sgrsn 0:33bfb28b0ffc 643 /// if (jrk.getDigitalReading(JrkG2Pin::RC))
sgrsn 0:33bfb28b0ffc 644 /// {
sgrsn 0:33bfb28b0ffc 645 /// // Something is driving the RC pin high.
sgrsn 0:33bfb28b0ffc 646 /// }
sgrsn 0:33bfb28b0ffc 647 /// ```
sgrsn 0:33bfb28b0ffc 648 bool getDigitalReading(JrkG2Pin pin)
sgrsn 0:33bfb28b0ffc 649 {
sgrsn 0:33bfb28b0ffc 650 uint8_t readings = getVar8(DigitalReadings);
sgrsn 0:33bfb28b0ffc 651 return (readings >> (uint8_t)pin) & 1;
sgrsn 0:33bfb28b0ffc 652 }
sgrsn 0:33bfb28b0ffc 653
sgrsn 0:33bfb28b0ffc 654 /// Gets the Jrk's raw measurement of the current running through the motor.
sgrsn 0:33bfb28b0ffc 655 ///
sgrsn 0:33bfb28b0ffc 656 /// This is an analog voltage reading from the Jrk's current sense
sgrsn 0:33bfb28b0ffc 657 /// pin. The units of the reading depend on what hard current limit is being
sgrsn 0:33bfb28b0ffc 658 /// used (getEncodedHardCurrentLimit()).
sgrsn 0:33bfb28b0ffc 659 ///
sgrsn 0:33bfb28b0ffc 660 /// See also getCurrent().
sgrsn 0:33bfb28b0ffc 661 uint16_t getRawCurrent()
sgrsn 0:33bfb28b0ffc 662 {
sgrsn 0:33bfb28b0ffc 663 return getVar16(RawCurrent);
sgrsn 0:33bfb28b0ffc 664 }
sgrsn 0:33bfb28b0ffc 665
sgrsn 0:33bfb28b0ffc 666 /// Gets the encoded value representing the hardware current limit the jrk is
sgrsn 0:33bfb28b0ffc 667 /// currently using.
sgrsn 0:33bfb28b0ffc 668 ///
sgrsn 0:33bfb28b0ffc 669 /// This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21.
sgrsn 0:33bfb28b0ffc 670 /// The Jrk G2 21v3 does not have a configurable hard current limit.
sgrsn 0:33bfb28b0ffc 671 ///
sgrsn 0:33bfb28b0ffc 672 /// See also setEncodedHardCurrentLimit(), getCurrent().
sgrsn 0:33bfb28b0ffc 673 uint16_t getEncodedHardCurrentLimit()
sgrsn 0:33bfb28b0ffc 674 {
sgrsn 0:33bfb28b0ffc 675 return getVar16(EncodedHardCurrentLimit);
sgrsn 0:33bfb28b0ffc 676 }
sgrsn 0:33bfb28b0ffc 677
sgrsn 0:33bfb28b0ffc 678 /// Gets the duty cycle the Jrk drove the motor with in the last PID period.
sgrsn 0:33bfb28b0ffc 679 ///
sgrsn 0:33bfb28b0ffc 680 /// This can be useful for converting the getRawCurrent() reading into
sgrsn 0:33bfb28b0ffc 681 /// milliamps.
sgrsn 0:33bfb28b0ffc 682 ///
sgrsn 0:33bfb28b0ffc 683 /// See also getDutyCycle(), getDutyCycleTarget(), and getCurrent().
sgrsn 0:33bfb28b0ffc 684 int16_t getLastDutyCycle()
sgrsn 0:33bfb28b0ffc 685 {
sgrsn 0:33bfb28b0ffc 686 return getVar16(LastDutyCycle);
sgrsn 0:33bfb28b0ffc 687 }
sgrsn 0:33bfb28b0ffc 688
sgrsn 0:33bfb28b0ffc 689 /// Gets the number of consecutive PID periods during which current chopping
sgrsn 0:33bfb28b0ffc 690 /// due to the hard current limit has been active.
sgrsn 0:33bfb28b0ffc 691 ///
sgrsn 0:33bfb28b0ffc 692 /// See also getCurrentChoppingOccurrenceCount().
sgrsn 0:33bfb28b0ffc 693 uint8_t getCurrentChoppingConsecutiveCount()
sgrsn 0:33bfb28b0ffc 694 {
sgrsn 0:33bfb28b0ffc 695 return getVar8(CurrentChoppingConsecutiveCount);
sgrsn 0:33bfb28b0ffc 696 }
sgrsn 0:33bfb28b0ffc 697
sgrsn 0:33bfb28b0ffc 698 /// Gets and clears the "Current chopping occurrence count" variable, which is
sgrsn 0:33bfb28b0ffc 699 /// the number of PID periods during which current chopping due to the hard
sgrsn 0:33bfb28b0ffc 700 /// current limit has been active, since the last time the variable was
sgrsn 0:33bfb28b0ffc 701 /// cleared.
sgrsn 0:33bfb28b0ffc 702 ///
sgrsn 0:33bfb28b0ffc 703 /// This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21.
sgrsn 0:33bfb28b0ffc 704 /// The Jrk G2 21v3 cannot sense when current chopping occurs so this command
sgrsn 0:33bfb28b0ffc 705 /// will always return 0.
sgrsn 0:33bfb28b0ffc 706 ///
sgrsn 0:33bfb28b0ffc 707 /// See also getCurrentChoppingConsecutiveCount().
sgrsn 0:33bfb28b0ffc 708 uint8_t getCurrentChoppingOccurrenceCount()
sgrsn 0:33bfb28b0ffc 709 {
sgrsn 0:33bfb28b0ffc 710 return commandR8(GetCurrentChoppingOccurrenceCount);
sgrsn 0:33bfb28b0ffc 711 }
sgrsn 0:33bfb28b0ffc 712 ///@}
sgrsn 0:33bfb28b0ffc 713
sgrsn 0:33bfb28b0ffc 714 ///\name RAM settings commands
sgrsn 0:33bfb28b0ffc 715 ///@{
sgrsn 0:33bfb28b0ffc 716
sgrsn 0:33bfb28b0ffc 717 /// Sets or clears the "Reset integral" setting in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 718 ///
sgrsn 0:33bfb28b0ffc 719 /// If this setting is set to true, the PID algorithm will reset the integral
sgrsn 0:33bfb28b0ffc 720 /// variable (also known as error sum) when the absolute value of the
sgrsn 0:33bfb28b0ffc 721 /// proportional term exceeds 600.
sgrsn 0:33bfb28b0ffc 722 ///
sgrsn 0:33bfb28b0ffc 723 /// When enabled, this can help limit integral wind-up, or the uncontrolled
sgrsn 0:33bfb28b0ffc 724 /// growth of the integral when the feedback system is temporarily unable to
sgrsn 0:33bfb28b0ffc 725 /// keep the error small. This might happen, for example, when the target is
sgrsn 0:33bfb28b0ffc 726 /// changing quickly.
sgrsn 0:33bfb28b0ffc 727 ///
sgrsn 0:33bfb28b0ffc 728 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 729 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 730 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 731 ///
sgrsn 0:33bfb28b0ffc 732 /// See also getResetIntegral().
sgrsn 0:33bfb28b0ffc 733 void setResetIntegral(bool reset)
sgrsn 0:33bfb28b0ffc 734 {
sgrsn 0:33bfb28b0ffc 735 uint8_t tmp = getRAMSetting8(OptionsByte3);
sgrsn 0:33bfb28b0ffc 736 if (getLastError()) { return; }
sgrsn 0:33bfb28b0ffc 737 if (reset)
sgrsn 0:33bfb28b0ffc 738 {
sgrsn 0:33bfb28b0ffc 739 tmp |= 1 << (uint8_t)ResetIntegral;
sgrsn 0:33bfb28b0ffc 740 }
sgrsn 0:33bfb28b0ffc 741 else
sgrsn 0:33bfb28b0ffc 742 {
sgrsn 0:33bfb28b0ffc 743 tmp &= ~(1 << (uint8_t)ResetIntegral);
sgrsn 0:33bfb28b0ffc 744 }
sgrsn 0:33bfb28b0ffc 745 setRAMSetting8(OptionsByte3, tmp);
sgrsn 0:33bfb28b0ffc 746 }
sgrsn 0:33bfb28b0ffc 747
sgrsn 0:33bfb28b0ffc 748 /// Gets the "Reset integral" setting from the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 749 ///
sgrsn 0:33bfb28b0ffc 750 /// See also setResetIntegral().
sgrsn 0:33bfb28b0ffc 751 bool getResetIntegral()
sgrsn 0:33bfb28b0ffc 752 {
sgrsn 0:33bfb28b0ffc 753 return getRAMSetting8(OptionsByte3) >>
sgrsn 0:33bfb28b0ffc 754 (uint8_t)ResetIntegral & 1;
sgrsn 0:33bfb28b0ffc 755 }
sgrsn 0:33bfb28b0ffc 756
sgrsn 0:33bfb28b0ffc 757 /// Sets or clears the "Coast when off" setting in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 758 ///
sgrsn 0:33bfb28b0ffc 759 /// By default, the Jrk drives both motor outputs low when the motor is
sgrsn 0:33bfb28b0ffc 760 /// stopped (duty cycle is zero), causing it to brake. If enabled, this
sgrsn 0:33bfb28b0ffc 761 /// setting causes it to instead tri-state both outputs, making the motor
sgrsn 0:33bfb28b0ffc 762 /// coast.
sgrsn 0:33bfb28b0ffc 763 ///
sgrsn 0:33bfb28b0ffc 764 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 765 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 766 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 767 ///
sgrsn 0:33bfb28b0ffc 768 /// See also getCoastWhenOff().
sgrsn 0:33bfb28b0ffc 769 void setCoastWhenOff(bool coast)
sgrsn 0:33bfb28b0ffc 770 {
sgrsn 0:33bfb28b0ffc 771 uint8_t tmp = getRAMSetting8(OptionsByte3);
sgrsn 0:33bfb28b0ffc 772 if (getLastError()) { return; }
sgrsn 0:33bfb28b0ffc 773 if (coast)
sgrsn 0:33bfb28b0ffc 774 {
sgrsn 0:33bfb28b0ffc 775 tmp |= 1 << (uint8_t)CoastWhenOff;
sgrsn 0:33bfb28b0ffc 776 }
sgrsn 0:33bfb28b0ffc 777 else
sgrsn 0:33bfb28b0ffc 778 {
sgrsn 0:33bfb28b0ffc 779 tmp &= ~(1 << (uint8_t)CoastWhenOff);
sgrsn 0:33bfb28b0ffc 780 }
sgrsn 0:33bfb28b0ffc 781 setRAMSetting8(OptionsByte3, tmp);
sgrsn 0:33bfb28b0ffc 782 }
sgrsn 0:33bfb28b0ffc 783
sgrsn 0:33bfb28b0ffc 784 /// Gets the "Coast when off" setting from the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 785 ///
sgrsn 0:33bfb28b0ffc 786 /// See also setCoastWhenOff().
sgrsn 0:33bfb28b0ffc 787 bool getCoastWhenOff()
sgrsn 0:33bfb28b0ffc 788 {
sgrsn 0:33bfb28b0ffc 789 return getRAMSetting8(OptionsByte3) >>
sgrsn 0:33bfb28b0ffc 790 (uint8_t)CoastWhenOff & 1;
sgrsn 0:33bfb28b0ffc 791 }
sgrsn 0:33bfb28b0ffc 792
sgrsn 0:33bfb28b0ffc 793 /// Sets the proportional coefficient in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 794 ///
sgrsn 0:33bfb28b0ffc 795 /// This coefficient is used in the Jrk's PID algorithm. The coefficient
sgrsn 0:33bfb28b0ffc 796 /// takes the form:
sgrsn 0:33bfb28b0ffc 797 ///
sgrsn 0:33bfb28b0ffc 798 /// multiplier / (2 ^ exponent)
sgrsn 0:33bfb28b0ffc 799 ///
sgrsn 0:33bfb28b0ffc 800 /// The multiplier can range from 0 to 1023, and the exponent can range
sgrsn 0:33bfb28b0ffc 801 /// from 0 to 18.
sgrsn 0:33bfb28b0ffc 802 ///
sgrsn 0:33bfb28b0ffc 803 /// Example usage:
sgrsn 0:33bfb28b0ffc 804 /// ```
sgrsn 0:33bfb28b0ffc 805 /// // Set the proportional coefficient to 1.125 (9/(2^3)).
sgrsn 0:33bfb28b0ffc 806 /// jrk.setProportionalCoefficient(9, 3);
sgrsn 0:33bfb28b0ffc 807 /// ```
sgrsn 0:33bfb28b0ffc 808 ///
sgrsn 0:33bfb28b0ffc 809 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 810 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 811 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 812 ///
sgrsn 0:33bfb28b0ffc 813 /// See also getProportionalMultiplier() and getProportionalExponent(), as
sgrsn 0:33bfb28b0ffc 814 /// well as setIntegralCoefficient() and setDerivativeCoefficient().
sgrsn 0:33bfb28b0ffc 815 void setProportionalCoefficient(uint16_t multiplier, uint8_t exponent)
sgrsn 0:33bfb28b0ffc 816 {
sgrsn 0:33bfb28b0ffc 817 setPIDCoefficient(ProportionalMultiplier, multiplier, exponent);
sgrsn 0:33bfb28b0ffc 818 }
sgrsn 0:33bfb28b0ffc 819
sgrsn 0:33bfb28b0ffc 820 /// Gets the multiplier part of the proportional coefficient from the Jrk's
sgrsn 0:33bfb28b0ffc 821 /// RAM settings.
sgrsn 0:33bfb28b0ffc 822 ///
sgrsn 0:33bfb28b0ffc 823 /// See also getProportionalExponent() and setProportionalCoefficient().
sgrsn 0:33bfb28b0ffc 824 uint16_t getProportionalMultiplier()
sgrsn 0:33bfb28b0ffc 825 {
sgrsn 0:33bfb28b0ffc 826 return getRAMSetting16(ProportionalMultiplier);
sgrsn 0:33bfb28b0ffc 827 }
sgrsn 0:33bfb28b0ffc 828
sgrsn 0:33bfb28b0ffc 829 /// Gets the exponent part of the proportional coefficient from the Jrk's RAM
sgrsn 0:33bfb28b0ffc 830 /// settings.
sgrsn 0:33bfb28b0ffc 831 ///
sgrsn 0:33bfb28b0ffc 832 /// See also getProportionalMultiplier() and setProportionalCoefficient().
sgrsn 0:33bfb28b0ffc 833 uint8_t getProportionalExponent()
sgrsn 0:33bfb28b0ffc 834 {
sgrsn 0:33bfb28b0ffc 835 return getRAMSetting8(ProportionalExponent);
sgrsn 0:33bfb28b0ffc 836 }
sgrsn 0:33bfb28b0ffc 837
sgrsn 0:33bfb28b0ffc 838 /// Sets the integral coefficient in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 839 ///
sgrsn 0:33bfb28b0ffc 840 /// This coefficient is used in the Jrk's PID algorithm. The coefficient
sgrsn 0:33bfb28b0ffc 841 /// takes the form:
sgrsn 0:33bfb28b0ffc 842 ///
sgrsn 0:33bfb28b0ffc 843 /// multiplier / (2 ^ exponent)
sgrsn 0:33bfb28b0ffc 844 ///
sgrsn 0:33bfb28b0ffc 845 /// The multiplier can range from 0 to 1023, and the exponent can range
sgrsn 0:33bfb28b0ffc 846 /// from 0 to 18.
sgrsn 0:33bfb28b0ffc 847 ///
sgrsn 0:33bfb28b0ffc 848 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 849 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 850 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 851 ///
sgrsn 0:33bfb28b0ffc 852 /// See also getIntegralMultiplier() and getIntegralExponent(), as
sgrsn 0:33bfb28b0ffc 853 /// well as setProportionalCoefficient() and setDerivativeCoefficient().
sgrsn 0:33bfb28b0ffc 854 void setIntegralCoefficient(uint16_t multiplier, uint8_t exponent)
sgrsn 0:33bfb28b0ffc 855 {
sgrsn 0:33bfb28b0ffc 856 setPIDCoefficient(IntegralMultiplier, multiplier, exponent);
sgrsn 0:33bfb28b0ffc 857 }
sgrsn 0:33bfb28b0ffc 858
sgrsn 0:33bfb28b0ffc 859 /// Gets the multiplier part of the integral coefficient from the Jrk's
sgrsn 0:33bfb28b0ffc 860 /// RAM settings.
sgrsn 0:33bfb28b0ffc 861 ///
sgrsn 0:33bfb28b0ffc 862 /// See also getIntegralExponent() and setIntegralCoefficient().
sgrsn 0:33bfb28b0ffc 863 uint16_t getIntegralMultiplier()
sgrsn 0:33bfb28b0ffc 864 {
sgrsn 0:33bfb28b0ffc 865 return getRAMSetting16(IntegralMultiplier);
sgrsn 0:33bfb28b0ffc 866 }
sgrsn 0:33bfb28b0ffc 867
sgrsn 0:33bfb28b0ffc 868 /// Gets the exponent part of the integral coefficient from the Jrk's
sgrsn 0:33bfb28b0ffc 869 /// RAM settings.
sgrsn 0:33bfb28b0ffc 870 ///
sgrsn 0:33bfb28b0ffc 871 /// See also getIntegralMultiplier() and setIntegralCoefficient().
sgrsn 0:33bfb28b0ffc 872 uint8_t getIntegralExponent()
sgrsn 0:33bfb28b0ffc 873 {
sgrsn 0:33bfb28b0ffc 874 return getRAMSetting8(IntegralExponent);
sgrsn 0:33bfb28b0ffc 875 }
sgrsn 0:33bfb28b0ffc 876
sgrsn 0:33bfb28b0ffc 877 /// Sets the derivative coefficient in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 878 ///
sgrsn 0:33bfb28b0ffc 879 /// This coefficient is used in the Jrk's PID algorithm. The coefficient
sgrsn 0:33bfb28b0ffc 880 /// takes the form:
sgrsn 0:33bfb28b0ffc 881 ///
sgrsn 0:33bfb28b0ffc 882 /// multiplier / (2 ^ exponent)
sgrsn 0:33bfb28b0ffc 883 ///
sgrsn 0:33bfb28b0ffc 884 /// The multiplier can range from 0 to 1023, and the exponent can range
sgrsn 0:33bfb28b0ffc 885 /// from 0 to 18.
sgrsn 0:33bfb28b0ffc 886 ///
sgrsn 0:33bfb28b0ffc 887 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 888 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 889 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 890 ///
sgrsn 0:33bfb28b0ffc 891 /// See also getDerivativeMultiplier() and getDerivativeExponent(), as
sgrsn 0:33bfb28b0ffc 892 /// well as setProportionalCoefficient() and setIntegralCoefficient().
sgrsn 0:33bfb28b0ffc 893 void setDerivativeCoefficient(uint16_t multiplier, uint8_t exponent)
sgrsn 0:33bfb28b0ffc 894 {
sgrsn 0:33bfb28b0ffc 895 setPIDCoefficient(DerivativeMultiplier, multiplier, exponent);
sgrsn 0:33bfb28b0ffc 896 }
sgrsn 0:33bfb28b0ffc 897
sgrsn 0:33bfb28b0ffc 898 /// Gets the multiplier part of the derivative coefficient from the
sgrsn 0:33bfb28b0ffc 899 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 900 ///
sgrsn 0:33bfb28b0ffc 901 /// See also getDerivativeExponent() and setDerivativeCoefficient().
sgrsn 0:33bfb28b0ffc 902 uint16_t getDerivativeMultiplier()
sgrsn 0:33bfb28b0ffc 903 {
sgrsn 0:33bfb28b0ffc 904 return getRAMSetting16(DerivativeMultiplier);
sgrsn 0:33bfb28b0ffc 905 }
sgrsn 0:33bfb28b0ffc 906
sgrsn 0:33bfb28b0ffc 907 /// Gets the exponent part of the derivative coefficient from the
sgrsn 0:33bfb28b0ffc 908 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 909 ///
sgrsn 0:33bfb28b0ffc 910 /// See also getDerivativeMultiplier() and setDerivativeCoefficient().
sgrsn 0:33bfb28b0ffc 911 uint8_t getDerivativeExponent()
sgrsn 0:33bfb28b0ffc 912 {
sgrsn 0:33bfb28b0ffc 913 return getRAMSetting8(DerivativeExponent);
sgrsn 0:33bfb28b0ffc 914 }
sgrsn 0:33bfb28b0ffc 915
sgrsn 0:33bfb28b0ffc 916 /// Sets the PID period in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 917 ///
sgrsn 0:33bfb28b0ffc 918 /// This is the rate at which the Jrk runs through all of its calculations, in
sgrsn 0:33bfb28b0ffc 919 /// milliseconds. Note that a higher PID period will result in a more slowly
sgrsn 0:33bfb28b0ffc 920 /// changing integral and a higher derivative, so the two corresponding PID
sgrsn 0:33bfb28b0ffc 921 /// coefficients might need to be adjusted whenever the PID period is changed.
sgrsn 0:33bfb28b0ffc 922 ///
sgrsn 0:33bfb28b0ffc 923 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 924 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 925 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 926 ///
sgrsn 0:33bfb28b0ffc 927 /// See also getPIDPeriod().
sgrsn 0:33bfb28b0ffc 928 void setPIDPeriod(uint16_t period)
sgrsn 0:33bfb28b0ffc 929 {
sgrsn 0:33bfb28b0ffc 930 setRAMSetting16(PIDPeriod, period);
sgrsn 0:33bfb28b0ffc 931 }
sgrsn 0:33bfb28b0ffc 932
sgrsn 0:33bfb28b0ffc 933 /// Gets the PID period from the Jrk's RAM settings, in milliseconds.
sgrsn 0:33bfb28b0ffc 934 ///
sgrsn 0:33bfb28b0ffc 935 /// See also setPIDPeriod().
sgrsn 0:33bfb28b0ffc 936 uint16_t getPIDPeriod()
sgrsn 0:33bfb28b0ffc 937 {
sgrsn 0:33bfb28b0ffc 938 return getRAMSetting16(PIDPeriod);
sgrsn 0:33bfb28b0ffc 939 }
sgrsn 0:33bfb28b0ffc 940
sgrsn 0:33bfb28b0ffc 941 /// Sets the integral limit in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 942 ///
sgrsn 0:33bfb28b0ffc 943 /// The PID algorithm prevents the absolute value of the integral variable
sgrsn 0:33bfb28b0ffc 944 /// (also known as error sum) from exceeding this limit. This can help limit
sgrsn 0:33bfb28b0ffc 945 /// integral wind-up. The limit can range from 0 to 32767.
sgrsn 0:33bfb28b0ffc 946 ///
sgrsn 0:33bfb28b0ffc 947 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 948 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 949 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 950 ///
sgrsn 0:33bfb28b0ffc 951 /// See also getIntegralLimit().
sgrsn 0:33bfb28b0ffc 952 void setIntegralLimit(uint16_t limit)
sgrsn 0:33bfb28b0ffc 953 {
sgrsn 0:33bfb28b0ffc 954 setRAMSetting16(IntegralLimit, limit);
sgrsn 0:33bfb28b0ffc 955 }
sgrsn 0:33bfb28b0ffc 956
sgrsn 0:33bfb28b0ffc 957 /// Gets the integral limit from the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 958 ///
sgrsn 0:33bfb28b0ffc 959 /// See also setIntegralLimit().
sgrsn 0:33bfb28b0ffc 960 uint16_t getIntegralLimit()
sgrsn 0:33bfb28b0ffc 961 {
sgrsn 0:33bfb28b0ffc 962 return getRAMSetting16(IntegralLimit);
sgrsn 0:33bfb28b0ffc 963 }
sgrsn 0:33bfb28b0ffc 964
sgrsn 0:33bfb28b0ffc 965 /// Sets the maximum duty cycle while feedback is out of range in the Jrk's
sgrsn 0:33bfb28b0ffc 966 /// RAM settings.
sgrsn 0:33bfb28b0ffc 967 ///
sgrsn 0:33bfb28b0ffc 968 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 969 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 970 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 971 ///
sgrsn 0:33bfb28b0ffc 972 /// See also getMaxDutyCycleWhileFeedbackOutOfRange().
sgrsn 0:33bfb28b0ffc 973 void setMaxDutyCycleWhileFeedbackOutOfRange(uint16_t duty)
sgrsn 0:33bfb28b0ffc 974 {
sgrsn 0:33bfb28b0ffc 975 setRAMSetting16(MaxDutyCycleWhileFeedbackOutOfRange, duty);
sgrsn 0:33bfb28b0ffc 976 }
sgrsn 0:33bfb28b0ffc 977
sgrsn 0:33bfb28b0ffc 978 /// Gets the maximum duty cycle while feedback is out of range from the Jrk's RAM
sgrsn 0:33bfb28b0ffc 979 /// settings.
sgrsn 0:33bfb28b0ffc 980 ///
sgrsn 0:33bfb28b0ffc 981 /// See also setMaxDutyCycleWhileFeedbackOutOfRange().
sgrsn 0:33bfb28b0ffc 982 uint16_t getMaxDutyCycleWhileFeedbackOutOfRange()
sgrsn 0:33bfb28b0ffc 983 {
sgrsn 0:33bfb28b0ffc 984 return getRAMSetting16(MaxDutyCycleWhileFeedbackOutOfRange);
sgrsn 0:33bfb28b0ffc 985 }
sgrsn 0:33bfb28b0ffc 986
sgrsn 0:33bfb28b0ffc 987 /// Sets the maximum acceleration in the forward direction in the
sgrsn 0:33bfb28b0ffc 988 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 989 ///
sgrsn 0:33bfb28b0ffc 990 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 991 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 992 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 993 ///
sgrsn 0:33bfb28b0ffc 994 /// See also getMaxAccelerationForward(), setMaxAccelerationReverse(),
sgrsn 0:33bfb28b0ffc 995 /// setMaxAcceleration(), and setMaxDecelerationForward().
sgrsn 0:33bfb28b0ffc 996 void setMaxAccelerationForward(uint16_t accel)
sgrsn 0:33bfb28b0ffc 997 {
sgrsn 0:33bfb28b0ffc 998 setRAMSetting16(MaxAccelerationForward, accel);
sgrsn 0:33bfb28b0ffc 999 }
sgrsn 0:33bfb28b0ffc 1000
sgrsn 0:33bfb28b0ffc 1001 /// Gets the maximum acceleration in the forward direction from the
sgrsn 0:33bfb28b0ffc 1002 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1003 ///
sgrsn 0:33bfb28b0ffc 1004 /// See also setMaxAccelerationForward().
sgrsn 0:33bfb28b0ffc 1005 uint16_t getMaxAccelerationForward()
sgrsn 0:33bfb28b0ffc 1006 {
sgrsn 0:33bfb28b0ffc 1007 return getRAMSetting16(MaxAccelerationForward);
sgrsn 0:33bfb28b0ffc 1008 }
sgrsn 0:33bfb28b0ffc 1009
sgrsn 0:33bfb28b0ffc 1010 /// Sets the maximum acceleration in the reverse direction in the
sgrsn 0:33bfb28b0ffc 1011 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1012 ///
sgrsn 0:33bfb28b0ffc 1013 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1014 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1015 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1016 ///
sgrsn 0:33bfb28b0ffc 1017 /// See also getMaxAccelerationReverse(), setMaxAccelerationForward(),
sgrsn 0:33bfb28b0ffc 1018 /// setMaxAcceleration(), and setMaxDecelerationReverse().
sgrsn 0:33bfb28b0ffc 1019 void setMaxAccelerationReverse(uint16_t accel)
sgrsn 0:33bfb28b0ffc 1020 {
sgrsn 0:33bfb28b0ffc 1021 setRAMSetting16(MaxAccelerationReverse, accel);
sgrsn 0:33bfb28b0ffc 1022 }
sgrsn 0:33bfb28b0ffc 1023
sgrsn 0:33bfb28b0ffc 1024 /// Gets the maximum acceleration in the reverse direction from the
sgrsn 0:33bfb28b0ffc 1025 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1026 ///
sgrsn 0:33bfb28b0ffc 1027 /// See also setMaxAccelerationReverse().
sgrsn 0:33bfb28b0ffc 1028 uint16_t getMaxAccelerationReverse()
sgrsn 0:33bfb28b0ffc 1029 {
sgrsn 0:33bfb28b0ffc 1030 return getRAMSetting16(MaxAccelerationReverse);
sgrsn 0:33bfb28b0ffc 1031 }
sgrsn 0:33bfb28b0ffc 1032
sgrsn 0:33bfb28b0ffc 1033 /// Sets the maximum acceleration in both directions in the
sgrsn 0:33bfb28b0ffc 1034 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1035 ///
sgrsn 0:33bfb28b0ffc 1036 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1037 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1038 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1039 ///
sgrsn 0:33bfb28b0ffc 1040 /// See also setMaxAccelerationForward(), setMaxAccelerationReverse(),
sgrsn 0:33bfb28b0ffc 1041 /// setMaxDeceleration().
sgrsn 0:33bfb28b0ffc 1042 void setMaxAcceleration(uint16_t accel)
sgrsn 0:33bfb28b0ffc 1043 {
sgrsn 0:33bfb28b0ffc 1044 setRAMSetting16x2(MaxAccelerationForward, accel, accel);
sgrsn 0:33bfb28b0ffc 1045 }
sgrsn 0:33bfb28b0ffc 1046
sgrsn 0:33bfb28b0ffc 1047 /// Sets the maximum deceleration in the forward direction in the Jrk's RAM
sgrsn 0:33bfb28b0ffc 1048 /// settings.
sgrsn 0:33bfb28b0ffc 1049 ///
sgrsn 0:33bfb28b0ffc 1050 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1051 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1052 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1053 ///
sgrsn 0:33bfb28b0ffc 1054 /// See also getMaxDecelerationForward(), setMaxDecelerationReverse(),
sgrsn 0:33bfb28b0ffc 1055 /// setMaxDeceleration(), and setMaxAccelerationForward().
sgrsn 0:33bfb28b0ffc 1056 void setMaxDecelerationForward(uint16_t decel)
sgrsn 0:33bfb28b0ffc 1057 {
sgrsn 0:33bfb28b0ffc 1058 setRAMSetting16(MaxDecelerationForward, decel);
sgrsn 0:33bfb28b0ffc 1059 }
sgrsn 0:33bfb28b0ffc 1060
sgrsn 0:33bfb28b0ffc 1061 /// Gets the maximum deceleration in the forward direction from the Jrk's RAM
sgrsn 0:33bfb28b0ffc 1062 /// settings.
sgrsn 0:33bfb28b0ffc 1063 ///
sgrsn 0:33bfb28b0ffc 1064 /// See also setMaxDecelerationForward().
sgrsn 0:33bfb28b0ffc 1065 uint16_t getMaxDecelerationForward()
sgrsn 0:33bfb28b0ffc 1066 {
sgrsn 0:33bfb28b0ffc 1067 return getRAMSetting16(MaxDecelerationForward);
sgrsn 0:33bfb28b0ffc 1068 }
sgrsn 0:33bfb28b0ffc 1069
sgrsn 0:33bfb28b0ffc 1070 /// Sets the maximum deceleration in the reverse direction in the
sgrsn 0:33bfb28b0ffc 1071 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1072 ///
sgrsn 0:33bfb28b0ffc 1073 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1074 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1075 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1076 ///
sgrsn 0:33bfb28b0ffc 1077 /// See also getMaxDecelerationReverse(), setMaxDecelerationForward(),
sgrsn 0:33bfb28b0ffc 1078 /// setMaxDeceleration(), and setMaxAccelerationReverse().
sgrsn 0:33bfb28b0ffc 1079 void setMaxDecelerationReverse(uint16_t decel)
sgrsn 0:33bfb28b0ffc 1080 {
sgrsn 0:33bfb28b0ffc 1081 setRAMSetting16(MaxDecelerationReverse, decel);
sgrsn 0:33bfb28b0ffc 1082 }
sgrsn 0:33bfb28b0ffc 1083
sgrsn 0:33bfb28b0ffc 1084 /// Gets the maximum deceleration in the reverse direction from the Jrk's RAM
sgrsn 0:33bfb28b0ffc 1085 /// settings.
sgrsn 0:33bfb28b0ffc 1086 ///
sgrsn 0:33bfb28b0ffc 1087 /// See also setMaxDecelerationReverse().
sgrsn 0:33bfb28b0ffc 1088 uint16_t getMaxDecelerationReverse()
sgrsn 0:33bfb28b0ffc 1089 {
sgrsn 0:33bfb28b0ffc 1090 return getRAMSetting16(MaxDecelerationReverse);
sgrsn 0:33bfb28b0ffc 1091 }
sgrsn 0:33bfb28b0ffc 1092
sgrsn 0:33bfb28b0ffc 1093 /// Sets the maximum deceleration in both directions in the
sgrsn 0:33bfb28b0ffc 1094 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1095 ///
sgrsn 0:33bfb28b0ffc 1096 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1097 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1098 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1099 ///
sgrsn 0:33bfb28b0ffc 1100 /// See also setMaxDecelerationForward(), setMaxDecelerationReverse(),
sgrsn 0:33bfb28b0ffc 1101 /// setMaxAcceleration().
sgrsn 0:33bfb28b0ffc 1102 void setMaxDeceleration(uint16_t decel)
sgrsn 0:33bfb28b0ffc 1103 {
sgrsn 0:33bfb28b0ffc 1104 setRAMSetting16x2(MaxDecelerationForward, decel, decel);
sgrsn 0:33bfb28b0ffc 1105 }
sgrsn 0:33bfb28b0ffc 1106
sgrsn 0:33bfb28b0ffc 1107 /// Sets the maximum duty cycle in the forward direction in the
sgrsn 0:33bfb28b0ffc 1108 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1109 ///
sgrsn 0:33bfb28b0ffc 1110 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1111 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1112 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1113 ///
sgrsn 0:33bfb28b0ffc 1114 /// See also getMaxDutyCycleForward(), setMaxDutyCycleReverse().
sgrsn 0:33bfb28b0ffc 1115 void setMaxDutyCycleForward(uint16_t duty)
sgrsn 0:33bfb28b0ffc 1116 {
sgrsn 0:33bfb28b0ffc 1117 setRAMSetting16(MaxDutyCycleForward, duty);
sgrsn 0:33bfb28b0ffc 1118 }
sgrsn 0:33bfb28b0ffc 1119
sgrsn 0:33bfb28b0ffc 1120 /// Gets the maximum duty cycle in the forward direction from the Jrk's RAM
sgrsn 0:33bfb28b0ffc 1121 /// settings.
sgrsn 0:33bfb28b0ffc 1122 ///
sgrsn 0:33bfb28b0ffc 1123 /// See also setMaxDutyCycleForward().
sgrsn 0:33bfb28b0ffc 1124 uint16_t getMaxDutyCycleForward()
sgrsn 0:33bfb28b0ffc 1125 {
sgrsn 0:33bfb28b0ffc 1126 return getRAMSetting16(MaxDutyCycleForward);
sgrsn 0:33bfb28b0ffc 1127 }
sgrsn 0:33bfb28b0ffc 1128
sgrsn 0:33bfb28b0ffc 1129 /// Sets the maximum duty cycle in the reverse direction in the
sgrsn 0:33bfb28b0ffc 1130 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1131 ///
sgrsn 0:33bfb28b0ffc 1132 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1133 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1134 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1135 ///
sgrsn 0:33bfb28b0ffc 1136 /// See also getMaxDutyCycleReverse(), setMaxDutyCycleForard().
sgrsn 0:33bfb28b0ffc 1137 void setMaxDutyCycleReverse(uint16_t duty)
sgrsn 0:33bfb28b0ffc 1138 {
sgrsn 0:33bfb28b0ffc 1139 setRAMSetting16(MaxDutyCycleReverse, duty);
sgrsn 0:33bfb28b0ffc 1140 }
sgrsn 0:33bfb28b0ffc 1141
sgrsn 0:33bfb28b0ffc 1142 /// Gets the maximum duty cycle in the reverse direction from the
sgrsn 0:33bfb28b0ffc 1143 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1144 ///
sgrsn 0:33bfb28b0ffc 1145 /// See also setMaxDutyCycleReverse().
sgrsn 0:33bfb28b0ffc 1146 uint16_t getMaxDutyCycleReverse()
sgrsn 0:33bfb28b0ffc 1147 {
sgrsn 0:33bfb28b0ffc 1148 return getRAMSetting16(MaxDutyCycleReverse);
sgrsn 0:33bfb28b0ffc 1149 }
sgrsn 0:33bfb28b0ffc 1150
sgrsn 0:33bfb28b0ffc 1151 /// Sets the maximum duty cycle for both directions in the
sgrsn 0:33bfb28b0ffc 1152 /// Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1153 ///
sgrsn 0:33bfb28b0ffc 1154 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1155 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1156 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1157 ///
sgrsn 0:33bfb28b0ffc 1158 /// See also setMaxDutyCycleForward(), setMaxDutyCycleReverse().
sgrsn 0:33bfb28b0ffc 1159 void setMaxDutyCycle(uint16_t duty)
sgrsn 0:33bfb28b0ffc 1160 {
sgrsn 0:33bfb28b0ffc 1161 setRAMSetting16x2(MaxDutyCycleForward, duty, duty);
sgrsn 0:33bfb28b0ffc 1162 }
sgrsn 0:33bfb28b0ffc 1163
sgrsn 0:33bfb28b0ffc 1164 /// Sets the encoded hard current limit for driving in the forward direction
sgrsn 0:33bfb28b0ffc 1165 /// in the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1166 ///
sgrsn 0:33bfb28b0ffc 1167 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1168 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1169 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1170 ///
sgrsn 0:33bfb28b0ffc 1171 /// This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21.
sgrsn 0:33bfb28b0ffc 1172 /// The Jrk G2 21v3 does not have a configurable hard current limit.
sgrsn 0:33bfb28b0ffc 1173 ///
sgrsn 0:33bfb28b0ffc 1174 /// See also getEncodedHardCurrentLimitForward() and
sgrsn 0:33bfb28b0ffc 1175 /// setEncodedHardCurrentLimitReverse().
sgrsn 0:33bfb28b0ffc 1176 void setEncodedHardCurrentLimitForward(uint16_t encoded_limit)
sgrsn 0:33bfb28b0ffc 1177 {
sgrsn 0:33bfb28b0ffc 1178 setRAMSetting16(EncodedHardCurrentLimitForward,
sgrsn 0:33bfb28b0ffc 1179 encoded_limit);
sgrsn 0:33bfb28b0ffc 1180 }
sgrsn 0:33bfb28b0ffc 1181
sgrsn 0:33bfb28b0ffc 1182 /// Gets the encoded hard current limit for driving in the forward direction
sgrsn 0:33bfb28b0ffc 1183 /// from the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1184 ///
sgrsn 0:33bfb28b0ffc 1185 /// This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21.
sgrsn 0:33bfb28b0ffc 1186 /// The Jrk G2 21v3 does not have a configurable hard current limit.
sgrsn 0:33bfb28b0ffc 1187 ///
sgrsn 0:33bfb28b0ffc 1188 /// See also setEncodedHardCurrentLimitForward().
sgrsn 0:33bfb28b0ffc 1189 uint16_t getEncodedHardCurrentLimitForward()
sgrsn 0:33bfb28b0ffc 1190 {
sgrsn 0:33bfb28b0ffc 1191 return getRAMSetting16(EncodedHardCurrentLimitForward);
sgrsn 0:33bfb28b0ffc 1192 }
sgrsn 0:33bfb28b0ffc 1193
sgrsn 0:33bfb28b0ffc 1194 /// Sets the encoded hard current limit for driving in the reverse direction
sgrsn 0:33bfb28b0ffc 1195 /// in the Jrk's RAM settings
sgrsn 0:33bfb28b0ffc 1196 ///
sgrsn 0:33bfb28b0ffc 1197 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1198 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1199 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1200 ///
sgrsn 0:33bfb28b0ffc 1201 /// This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21.
sgrsn 0:33bfb28b0ffc 1202 /// The Jrk G2 21v3 does not have a configurable hard current limit.
sgrsn 0:33bfb28b0ffc 1203 ///
sgrsn 0:33bfb28b0ffc 1204 /// See also getEncodedHardCurrentLimitReverse() and
sgrsn 0:33bfb28b0ffc 1205 /// setEncodedHardCurrentLimitForward().
sgrsn 0:33bfb28b0ffc 1206 void setEncodedHardCurrentLimitReverse(uint16_t encoded_limit)
sgrsn 0:33bfb28b0ffc 1207 {
sgrsn 0:33bfb28b0ffc 1208 setRAMSetting16(EncodedHardCurrentLimitReverse, encoded_limit);
sgrsn 0:33bfb28b0ffc 1209 }
sgrsn 0:33bfb28b0ffc 1210
sgrsn 0:33bfb28b0ffc 1211 /// Gets the encoded hard current limit for driving in the reverse direction
sgrsn 0:33bfb28b0ffc 1212 /// from the Jrk's RAM settings.
sgrsn 0:33bfb28b0ffc 1213 ///
sgrsn 0:33bfb28b0ffc 1214 /// This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21.
sgrsn 0:33bfb28b0ffc 1215 /// The Jrk G2 21v3 does not have a configurable hard current limit.
sgrsn 0:33bfb28b0ffc 1216 ///
sgrsn 0:33bfb28b0ffc 1217 /// See also setEncodedHardCurrentLimitReverse().
sgrsn 0:33bfb28b0ffc 1218 uint16_t getEncodedHardCurrentLimitReverse()
sgrsn 0:33bfb28b0ffc 1219 {
sgrsn 0:33bfb28b0ffc 1220 return getRAMSetting16(EncodedHardCurrentLimitReverse);
sgrsn 0:33bfb28b0ffc 1221 }
sgrsn 0:33bfb28b0ffc 1222
sgrsn 0:33bfb28b0ffc 1223 /// Sets the encoded hard current limit for both directions in the Jrk's RAM
sgrsn 0:33bfb28b0ffc 1224 /// settings.
sgrsn 0:33bfb28b0ffc 1225 ///
sgrsn 0:33bfb28b0ffc 1226 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1227 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1228 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1229 ///
sgrsn 0:33bfb28b0ffc 1230 /// This command is only valid for the Jrk G2 18v19, 24v13, 18v27, and 24v21.
sgrsn 0:33bfb28b0ffc 1231 /// The Jrk G2 21v3 does not have a configurable hard current limit.
sgrsn 0:33bfb28b0ffc 1232 ///
sgrsn 0:33bfb28b0ffc 1233 /// See also setEncodedHardCurrentLimitForward(),
sgrsn 0:33bfb28b0ffc 1234 /// setEncodedHardCurrentLimitReverse(), getEncodedHardCurrentLimit(), and
sgrsn 0:33bfb28b0ffc 1235 /// setSoftCurrentLimit().
sgrsn 0:33bfb28b0ffc 1236 void setEncodedHardCurrentLimit(uint16_t encoded_limit)
sgrsn 0:33bfb28b0ffc 1237 {
sgrsn 0:33bfb28b0ffc 1238 setRAMSetting16x2(EncodedHardCurrentLimitForward,
sgrsn 0:33bfb28b0ffc 1239 encoded_limit, encoded_limit);
sgrsn 0:33bfb28b0ffc 1240 }
sgrsn 0:33bfb28b0ffc 1241
sgrsn 0:33bfb28b0ffc 1242 /// Sets the brake duration when switching from forward to reverse in the
sgrsn 0:33bfb28b0ffc 1243 /// Jrk's RAM settings, in units of 5 ms.
sgrsn 0:33bfb28b0ffc 1244 ///
sgrsn 0:33bfb28b0ffc 1245 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1246 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1247 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1248 ///
sgrsn 0:33bfb28b0ffc 1249 /// See also getBrakeDurationForward() and setBrakeDurationReverse().
sgrsn 0:33bfb28b0ffc 1250 void setBrakeDurationForward(uint8_t duration)
sgrsn 0:33bfb28b0ffc 1251 {
sgrsn 0:33bfb28b0ffc 1252 setRAMSetting8(BrakeDurationForward, duration);
sgrsn 0:33bfb28b0ffc 1253 }
sgrsn 0:33bfb28b0ffc 1254
sgrsn 0:33bfb28b0ffc 1255 /// Gets the brake duration when switching from forward to reverse from the
sgrsn 0:33bfb28b0ffc 1256 /// Jrk's RAM settings, in units of 5 ms.
sgrsn 0:33bfb28b0ffc 1257 ///
sgrsn 0:33bfb28b0ffc 1258 /// See also setBrakeDurationForward().
sgrsn 0:33bfb28b0ffc 1259 uint8_t getBrakeDurationForward()
sgrsn 0:33bfb28b0ffc 1260 {
sgrsn 0:33bfb28b0ffc 1261 return getRAMSetting8(BrakeDurationForward);
sgrsn 0:33bfb28b0ffc 1262 }
sgrsn 0:33bfb28b0ffc 1263
sgrsn 0:33bfb28b0ffc 1264 /// Sets the brake duration when switching from reverse to forward in the
sgrsn 0:33bfb28b0ffc 1265 /// Jrk's RAM settings, in units of 5 ms.
sgrsn 0:33bfb28b0ffc 1266 ///
sgrsn 0:33bfb28b0ffc 1267 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1268 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1269 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1270 ///
sgrsn 0:33bfb28b0ffc 1271 /// See also getBrakeDurationReverse() and setBrakeDurationForward().
sgrsn 0:33bfb28b0ffc 1272 void setBrakeDurationReverse(uint8_t duration)
sgrsn 0:33bfb28b0ffc 1273 {
sgrsn 0:33bfb28b0ffc 1274 setRAMSetting8(BrakeDurationReverse, duration);
sgrsn 0:33bfb28b0ffc 1275 }
sgrsn 0:33bfb28b0ffc 1276
sgrsn 0:33bfb28b0ffc 1277 /// Gets the brake duration when switching from reverse to forward from the
sgrsn 0:33bfb28b0ffc 1278 /// Jrk's RAM settings, in units of 5 ms.
sgrsn 0:33bfb28b0ffc 1279 ///
sgrsn 0:33bfb28b0ffc 1280 /// See also setBrakeDurationReverse().
sgrsn 0:33bfb28b0ffc 1281 uint8_t getBrakeDurationReverse()
sgrsn 0:33bfb28b0ffc 1282 {
sgrsn 0:33bfb28b0ffc 1283 return getRAMSetting8(BrakeDurationReverse);
sgrsn 0:33bfb28b0ffc 1284 }
sgrsn 0:33bfb28b0ffc 1285
sgrsn 0:33bfb28b0ffc 1286 /// Sets the brake duration for both directions in the Jrk's RAM settings, in
sgrsn 0:33bfb28b0ffc 1287 /// units of 5 ms.
sgrsn 0:33bfb28b0ffc 1288 ///
sgrsn 0:33bfb28b0ffc 1289 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1290 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1291 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1292 ///
sgrsn 0:33bfb28b0ffc 1293 /// See also setBrakeDurationForward(), setBrakeDurationReverse().
sgrsn 0:33bfb28b0ffc 1294 void setBrakeDuration(uint8_t duration)
sgrsn 0:33bfb28b0ffc 1295 {
sgrsn 0:33bfb28b0ffc 1296 setRAMSetting8x2(BrakeDurationForward, duration, duration);
sgrsn 0:33bfb28b0ffc 1297 }
sgrsn 0:33bfb28b0ffc 1298
sgrsn 0:33bfb28b0ffc 1299 /// Sets the soft current limit when driving in the forward direction in the
sgrsn 0:33bfb28b0ffc 1300 /// Jrk's RAM settings, in units of mA.
sgrsn 0:33bfb28b0ffc 1301 ///
sgrsn 0:33bfb28b0ffc 1302 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1303 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1304 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1305 ///
sgrsn 0:33bfb28b0ffc 1306 /// See also getSoftCurrentLimitForward() and setSoftCurrentLimitReverse().
sgrsn 0:33bfb28b0ffc 1307 void setSoftCurrentLimitForward(uint16_t current)
sgrsn 0:33bfb28b0ffc 1308 {
sgrsn 0:33bfb28b0ffc 1309 setRAMSetting16(SoftCurrentLimitForward, current);
sgrsn 0:33bfb28b0ffc 1310 }
sgrsn 0:33bfb28b0ffc 1311
sgrsn 0:33bfb28b0ffc 1312 /// Gets the soft current limit when driving in the forward direction from the
sgrsn 0:33bfb28b0ffc 1313 /// Jrk's RAM settings, in units of mA.
sgrsn 0:33bfb28b0ffc 1314 ///
sgrsn 0:33bfb28b0ffc 1315 /// See also setSoftCurrentLimitForward().
sgrsn 0:33bfb28b0ffc 1316 uint16_t getSoftCurrentLimitForward()
sgrsn 0:33bfb28b0ffc 1317 {
sgrsn 0:33bfb28b0ffc 1318 return getRAMSetting16(SoftCurrentLimitForward);
sgrsn 0:33bfb28b0ffc 1319 }
sgrsn 0:33bfb28b0ffc 1320
sgrsn 0:33bfb28b0ffc 1321 /// Sets the soft current limit when driving in the reverse direction in the
sgrsn 0:33bfb28b0ffc 1322 /// Jrk's RAM settings, in units of mA.
sgrsn 0:33bfb28b0ffc 1323 ///
sgrsn 0:33bfb28b0ffc 1324 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1325 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1326 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1327 ///
sgrsn 0:33bfb28b0ffc 1328 /// See also getSoftCurrentLimitReverse() and setSoftCurrentLimitForward().
sgrsn 0:33bfb28b0ffc 1329 void setSoftCurrentLimitReverse(uint16_t current)
sgrsn 0:33bfb28b0ffc 1330 {
sgrsn 0:33bfb28b0ffc 1331 setRAMSetting16(SoftCurrentLimitReverse, current);
sgrsn 0:33bfb28b0ffc 1332 }
sgrsn 0:33bfb28b0ffc 1333
sgrsn 0:33bfb28b0ffc 1334 /// Gets the soft current limit when driving in the reverse direction from the
sgrsn 0:33bfb28b0ffc 1335 /// Jrk's RAM settings, in units of mA.
sgrsn 0:33bfb28b0ffc 1336 ///
sgrsn 0:33bfb28b0ffc 1337 /// See also setSoftCurrentLimitReverse().
sgrsn 0:33bfb28b0ffc 1338 uint16_t getSoftCurrentLimitReverse()
sgrsn 0:33bfb28b0ffc 1339 {
sgrsn 0:33bfb28b0ffc 1340 return getRAMSetting16(SoftCurrentLimitReverse);
sgrsn 0:33bfb28b0ffc 1341 }
sgrsn 0:33bfb28b0ffc 1342
sgrsn 0:33bfb28b0ffc 1343 /// Sets the soft current limit for driving in both directions in the Jrk's
sgrsn 0:33bfb28b0ffc 1344 /// RAM settings, in units of mA.
sgrsn 0:33bfb28b0ffc 1345 ///
sgrsn 0:33bfb28b0ffc 1346 /// You would normally configure this setting ahead of time using the Jrk G2
sgrsn 0:33bfb28b0ffc 1347 /// Configuration Utility, but this function allows you to change it
sgrsn 0:33bfb28b0ffc 1348 /// temporarily on the fly.
sgrsn 0:33bfb28b0ffc 1349 ///
sgrsn 0:33bfb28b0ffc 1350 /// See also setSoftCurrentLimitForward() and setSoftCurrentLimitReverse(),
sgrsn 0:33bfb28b0ffc 1351 /// setEncodedHardCurrentLimit().
sgrsn 0:33bfb28b0ffc 1352 void setSoftCurrentLimit(uint16_t current)
sgrsn 0:33bfb28b0ffc 1353 {
sgrsn 0:33bfb28b0ffc 1354 setRAMSetting16x2(SoftCurrentLimitForward, current, current);
sgrsn 0:33bfb28b0ffc 1355 }
sgrsn 0:33bfb28b0ffc 1356
sgrsn 0:33bfb28b0ffc 1357 // TODO: add functions to get and set the soft current regulation level
sgrsn 0:33bfb28b0ffc 1358
sgrsn 0:33bfb28b0ffc 1359 ///@}
sgrsn 0:33bfb28b0ffc 1360
sgrsn 0:33bfb28b0ffc 1361 ///\name Low-level settings and variables commands
sgrsn 0:33bfb28b0ffc 1362 ///@{
sgrsn 0:33bfb28b0ffc 1363
sgrsn 0:33bfb28b0ffc 1364 /// Gets a contiguous block of settings from the Jrk G2's EEPROM.
sgrsn 0:33bfb28b0ffc 1365 ///
sgrsn 0:33bfb28b0ffc 1366 /// The maximum length that can be fetched is 15 bytes.
sgrsn 0:33bfb28b0ffc 1367 ///
sgrsn 0:33bfb28b0ffc 1368 /// Example usage:
sgrsn 0:33bfb28b0ffc 1369 /// ```
sgrsn 0:33bfb28b0ffc 1370 /// // Get the Jrk's serial device number.
sgrsn 0:33bfb28b0ffc 1371 /// uint8_t deviceNumber;
sgrsn 0:33bfb28b0ffc 1372 /// jrk.getEEPROMSettings(0x28, 1, &deviceNumber);
sgrsn 0:33bfb28b0ffc 1373 /// ```
sgrsn 0:33bfb28b0ffc 1374 ///
sgrsn 0:33bfb28b0ffc 1375 /// For information on how the settings are encoded,
sgrsn 0:33bfb28b0ffc 1376 /// see the Jrk G2 user's guide.
sgrsn 0:33bfb28b0ffc 1377 void getEEPROMSettings(uint8_t offset, uint8_t length, uint8_t * buffer)
sgrsn 0:33bfb28b0ffc 1378 {
sgrsn 0:33bfb28b0ffc 1379 segmentRead(GetEEPROMSettings, offset, length, buffer);
sgrsn 0:33bfb28b0ffc 1380 }
sgrsn 0:33bfb28b0ffc 1381
sgrsn 0:33bfb28b0ffc 1382 /// Gets a contiguous block of settings from the Jrk G2's RAM.
sgrsn 0:33bfb28b0ffc 1383 ///
sgrsn 0:33bfb28b0ffc 1384 /// The maximum length that can be fetched is 15 bytes.
sgrsn 0:33bfb28b0ffc 1385 ///
sgrsn 0:33bfb28b0ffc 1386 /// Example usage:
sgrsn 0:33bfb28b0ffc 1387 /// ```
sgrsn 0:33bfb28b0ffc 1388 /// // Get the Jrk's feedback maximum setting.
sgrsn 0:33bfb28b0ffc 1389 /// uint8_t buffer[2];
sgrsn 0:33bfb28b0ffc 1390 /// jrk.getRAMSettings(0x1F, 2, buffer);
sgrsn 0:33bfb28b0ffc 1391 /// uint16_t feedbackMaximum = buffer[0] + (buffer[1] << 8);
sgrsn 0:33bfb28b0ffc 1392 /// ```
sgrsn 0:33bfb28b0ffc 1393 ///
sgrsn 0:33bfb28b0ffc 1394 /// Note that this library has several functions for reading and writing
sgrsn 0:33bfb28b0ffc 1395 /// specific RAM settings, and they are easier to use than this function.
sgrsn 0:33bfb28b0ffc 1396 ///
sgrsn 0:33bfb28b0ffc 1397 /// For information on how the settings are encoded,
sgrsn 0:33bfb28b0ffc 1398 /// see the Jrk G2 user's guide.
sgrsn 0:33bfb28b0ffc 1399 void getRAMSettings(uint8_t offset, uint8_t length, uint8_t * buffer)
sgrsn 0:33bfb28b0ffc 1400 {
sgrsn 0:33bfb28b0ffc 1401 segmentRead(GetRAMSettings, offset, length, buffer);
sgrsn 0:33bfb28b0ffc 1402 }
sgrsn 0:33bfb28b0ffc 1403
sgrsn 0:33bfb28b0ffc 1404 /// Sets a contiguous block of settings in the Jrk G2's RAM.
sgrsn 0:33bfb28b0ffc 1405 ///
sgrsn 0:33bfb28b0ffc 1406 /// The maximum length that can be written in a single command
sgrsn 0:33bfb28b0ffc 1407 /// is 7 bytes over Serial, 13 bytes over I2C.
sgrsn 0:33bfb28b0ffc 1408 ///
sgrsn 0:33bfb28b0ffc 1409 /// Example usage:
sgrsn 0:33bfb28b0ffc 1410 /// ```
sgrsn 0:33bfb28b0ffc 1411 /// // Set the Jrk's feedback maximum setting.
sgrsn 0:33bfb28b0ffc 1412 /// uint16_t feedbackMaximum = 1234;
sgrsn 0:33bfb28b0ffc 1413 /// uint8_t buffer[2];
sgrsn 0:33bfb28b0ffc 1414 /// buffer[0] = feedbackMaximum & 0xFF;
sgrsn 0:33bfb28b0ffc 1415 /// buffer[1] = feedbackMaximum >> 8 & 0xFF;
sgrsn 0:33bfb28b0ffc 1416 /// jrk.setRAMSettings(0x1F, 2, buffer);
sgrsn 0:33bfb28b0ffc 1417 /// ```
sgrsn 0:33bfb28b0ffc 1418 ///
sgrsn 0:33bfb28b0ffc 1419 /// Note that this library has several functions for reading and writing
sgrsn 0:33bfb28b0ffc 1420 /// specific RAM settings, and they are easier to use than this function.
sgrsn 0:33bfb28b0ffc 1421 ///
sgrsn 0:33bfb28b0ffc 1422 /// For information on how the settings are encoded,
sgrsn 0:33bfb28b0ffc 1423 /// see the Jrk G2 user's guide.
sgrsn 0:33bfb28b0ffc 1424 void setRAMSettings(uint8_t offset, uint8_t length, uint8_t * buffer)
sgrsn 0:33bfb28b0ffc 1425 {
sgrsn 0:33bfb28b0ffc 1426 segmentWrite(SetRAMSettings, offset, length, buffer);
sgrsn 0:33bfb28b0ffc 1427 }
sgrsn 0:33bfb28b0ffc 1428
sgrsn 0:33bfb28b0ffc 1429 /// Gets a contiguous block of variables from the Jrk G2.
sgrsn 0:33bfb28b0ffc 1430 ///
sgrsn 0:33bfb28b0ffc 1431 /// Note that this library has convenient functions for reading every variable
sgrsn 0:33bfb28b0ffc 1432 /// provided by the Jrk. The main reason to use this function is if you want
sgrsn 0:33bfb28b0ffc 1433 /// to read multiple variables at once for extra efficiency or to ensure that
sgrsn 0:33bfb28b0ffc 1434 /// the variables are in a consistent state.
sgrsn 0:33bfb28b0ffc 1435 ///
sgrsn 0:33bfb28b0ffc 1436 /// The maximum length that can be fetched is 15 bytes.
sgrsn 0:33bfb28b0ffc 1437 ///
sgrsn 0:33bfb28b0ffc 1438 /// Example usage:
sgrsn 0:33bfb28b0ffc 1439 /// ```
sgrsn 0:33bfb28b0ffc 1440 /// // Get the Jrk's last device reset and its up time.
sgrsn 0:33bfb28b0ffc 1441 /// uint8_t buffer[5];
sgrsn 0:33bfb28b0ffc 1442 /// jrk.getVariables(0x1F, 5, buffer);
sgrsn 0:33bfb28b0ffc 1443 /// ```
sgrsn 0:33bfb28b0ffc 1444 ///
sgrsn 0:33bfb28b0ffc 1445 /// For information on how the variables are encoded,
sgrsn 0:33bfb28b0ffc 1446 /// see the Jrk G2 user's guide.
sgrsn 0:33bfb28b0ffc 1447 void getVariables(uint8_t offset, uint8_t length, uint8_t * buffer)
sgrsn 0:33bfb28b0ffc 1448 {
sgrsn 0:33bfb28b0ffc 1449 segmentRead(GetVariables, offset, length, buffer);
sgrsn 0:33bfb28b0ffc 1450 }
sgrsn 0:33bfb28b0ffc 1451
sgrsn 0:33bfb28b0ffc 1452 ///@}
sgrsn 0:33bfb28b0ffc 1453
sgrsn 0:33bfb28b0ffc 1454 protected:
sgrsn 0:33bfb28b0ffc 1455 /// Zero if the last communication with the device was successful, non-zero
sgrsn 0:33bfb28b0ffc 1456 /// otherwise.
sgrsn 0:33bfb28b0ffc 1457 uint8_t _lastError;
sgrsn 0:33bfb28b0ffc 1458
sgrsn 0:33bfb28b0ffc 1459 private:
sgrsn 0:33bfb28b0ffc 1460 enum VarOffset
sgrsn 0:33bfb28b0ffc 1461 {
sgrsn 0:33bfb28b0ffc 1462 Input = 0x00, // uint16_t
sgrsn 0:33bfb28b0ffc 1463 Target = 0x02, // uint16_t
sgrsn 0:33bfb28b0ffc 1464 Feedback = 0x04, // uint16_t
sgrsn 0:33bfb28b0ffc 1465 ScaledFeedback = 0x06, // uint16_t
sgrsn 0:33bfb28b0ffc 1466 Integral = 0x08, // int16_t
sgrsn 0:33bfb28b0ffc 1467 DutyCycleTarget = 0x0A, // int16_t
sgrsn 0:33bfb28b0ffc 1468 DutyCycle = 0x0C, // int16_t
sgrsn 0:33bfb28b0ffc 1469 CurrentLowRes = 0x0E, // uint8_t
sgrsn 0:33bfb28b0ffc 1470 PIDPeriodExceeded = 0x0F, // uint8_t
sgrsn 0:33bfb28b0ffc 1471 PIDPeriodCount = 0x10, // uint16_t
sgrsn 0:33bfb28b0ffc 1472 ErrorFlagsHalting = 0x12, // uint16_t
sgrsn 0:33bfb28b0ffc 1473 ErrorFlagsOccurred = 0x14, // uint16_t
sgrsn 0:33bfb28b0ffc 1474
sgrsn 0:33bfb28b0ffc 1475 FlagByte1 = 0x16, // uint8_t
sgrsn 0:33bfb28b0ffc 1476 VinVoltage = 0x17, // uint16_t
sgrsn 0:33bfb28b0ffc 1477 Current = 0x19, // uint16_t
sgrsn 0:33bfb28b0ffc 1478
sgrsn 0:33bfb28b0ffc 1479 // variables above can be read with single-byte commands (GetVariable)
sgrsn 0:33bfb28b0ffc 1480 // variables below must be read with segment read (GetVariables)
sgrsn 0:33bfb28b0ffc 1481
sgrsn 0:33bfb28b0ffc 1482 DeviceReset = 0x1F, // uint8_t
sgrsn 0:33bfb28b0ffc 1483 UpTime = 0x20, // uint32_t
sgrsn 0:33bfb28b0ffc 1484 RCPulseWidth = 0x24, // uint16_t
sgrsn 0:33bfb28b0ffc 1485 FBTReading = 0x26, // uint16_t
sgrsn 0:33bfb28b0ffc 1486 AnalogReadingSDA = 0x28, // uint16_t
sgrsn 0:33bfb28b0ffc 1487 AnalogReadingFBA = 0x2A, // uint16_t
sgrsn 0:33bfb28b0ffc 1488 DigitalReadings = 0x2C, // uint8_t
sgrsn 0:33bfb28b0ffc 1489 RawCurrent = 0x2D, // uint16_t
sgrsn 0:33bfb28b0ffc 1490 EncodedHardCurrentLimit = 0x2F, // uint16_t
sgrsn 0:33bfb28b0ffc 1491 LastDutyCycle = 0x31, // int16_t
sgrsn 0:33bfb28b0ffc 1492 CurrentChoppingConsecutiveCount = 0x33, // uint8_t
sgrsn 0:33bfb28b0ffc 1493 CurrentChoppingOccurrenceCount = 0x34, // uint8_t; read with dedicated command
sgrsn 0:33bfb28b0ffc 1494 };
sgrsn 0:33bfb28b0ffc 1495
sgrsn 0:33bfb28b0ffc 1496 enum SettingOffset
sgrsn 0:33bfb28b0ffc 1497 {
sgrsn 0:33bfb28b0ffc 1498 OptionsByte1 = 0x01, // uint8_t
sgrsn 0:33bfb28b0ffc 1499 OptionsByte2 = 0x02, // uint8_t
sgrsn 0:33bfb28b0ffc 1500 InputMode = 0x03, // uint8_t
sgrsn 0:33bfb28b0ffc 1501 InputErrorMinimum = 0x04, // uint16_t,
sgrsn 0:33bfb28b0ffc 1502 InputErrorMaximum = 0x06, // uint16_t,
sgrsn 0:33bfb28b0ffc 1503 InputMinimum = 0x08, // uint16_t,
sgrsn 0:33bfb28b0ffc 1504 InputMaximum = 0x0A, // uint16_t,
sgrsn 0:33bfb28b0ffc 1505 InputNeutralMinimum = 0x0C, // uint16_t,
sgrsn 0:33bfb28b0ffc 1506 InputNeutralMaximum = 0x0E, // uint16_t,
sgrsn 0:33bfb28b0ffc 1507 OutputMinimum = 0x10, // uint16_t,
sgrsn 0:33bfb28b0ffc 1508 OutputNeutral = 0x12, // uint16_t,
sgrsn 0:33bfb28b0ffc 1509 OutputMaximum = 0x14, // uint16_t,
sgrsn 0:33bfb28b0ffc 1510 InputScalingDegree = 0x16, // uint8_t,
sgrsn 0:33bfb28b0ffc 1511 InputAnalogSamplesExponent = 0x17, // uint8_t,
sgrsn 0:33bfb28b0ffc 1512 FeedbackMode = 0x18, // uint8_t,
sgrsn 0:33bfb28b0ffc 1513 FeedbackErrorMinimum = 0x19, // uint16_t,
sgrsn 0:33bfb28b0ffc 1514 FeedbackErrorMaximum = 0x1B, // uint16_t,
sgrsn 0:33bfb28b0ffc 1515 FeedbackMinimum = 0x1D, // uint16_t,
sgrsn 0:33bfb28b0ffc 1516 FeedbackMaximum = 0x1F, // uint16_t,
sgrsn 0:33bfb28b0ffc 1517 FeedbackDeadZone = 0x21, // uint8_t,
sgrsn 0:33bfb28b0ffc 1518 FeedbackAnalogSamplesExponent = 0x22, // uint8_t,
sgrsn 0:33bfb28b0ffc 1519 SerialMode = 0x23, // uint8_t,
sgrsn 0:33bfb28b0ffc 1520 SerialBaudRateGenerator = 0x24, // uint16_t,
sgrsn 0:33bfb28b0ffc 1521 SerialTimeout = 0x26, // uint16_t,
sgrsn 0:33bfb28b0ffc 1522 SerialDeviceNumber = 0x28, // uint16_t,
sgrsn 0:33bfb28b0ffc 1523 ErrorEnable = 0x2A, // uint16_t
sgrsn 0:33bfb28b0ffc 1524 ErrorLatch = 0x2C, // uint16_t
sgrsn 0:33bfb28b0ffc 1525 ErrorHard = 0x2E, // uint16_t
sgrsn 0:33bfb28b0ffc 1526 VinCalibration = 0x30, // uint16_t
sgrsn 0:33bfb28b0ffc 1527 PwmFrequency = 0x32, // uint8_t
sgrsn 0:33bfb28b0ffc 1528 CurrentSamplesExponent = 0x33, // uint8_t
sgrsn 0:33bfb28b0ffc 1529 HardOvercurrentThreshold = 0x34, // uint8_t
sgrsn 0:33bfb28b0ffc 1530 CurrentOffsetCalibration = 0x35, // uint16_t
sgrsn 0:33bfb28b0ffc 1531 CurrentScaleCalibration = 0x37, // uint16_t
sgrsn 0:33bfb28b0ffc 1532 FBTMethod = 0x39, // uint8_t
sgrsn 0:33bfb28b0ffc 1533 FBTOptions = 0x3A, // uint8_t
sgrsn 0:33bfb28b0ffc 1534 FBTTimingTimeout = 0x3B, // uint16_t
sgrsn 0:33bfb28b0ffc 1535 FBTSamples = 0x3D, // uint8_t
sgrsn 0:33bfb28b0ffc 1536 FBTDividerExponent = 0x3E, // uint8_t
sgrsn 0:33bfb28b0ffc 1537 IntegralDividerExponent = 0x3F, // uint8_t
sgrsn 0:33bfb28b0ffc 1538 SoftCurrentRegulationLevelForward = 0x40, // uint16_t
sgrsn 0:33bfb28b0ffc 1539 SoftCurrentRegulationLevelReverse = 0x42, // uint16_t
sgrsn 0:33bfb28b0ffc 1540 OptionsByte3 = 0x50, // uint8_t
sgrsn 0:33bfb28b0ffc 1541 ProportionalMultiplier = 0x51, // uint16_t
sgrsn 0:33bfb28b0ffc 1542 ProportionalExponent = 0x53, // uint8_t
sgrsn 0:33bfb28b0ffc 1543 IntegralMultiplier = 0x54, // uint16_t
sgrsn 0:33bfb28b0ffc 1544 IntegralExponent = 0x56, // uint8_t
sgrsn 0:33bfb28b0ffc 1545 DerivativeMultiplier = 0x57, // uint16_t
sgrsn 0:33bfb28b0ffc 1546 DerivativeExponent = 0x59, // uint8_t
sgrsn 0:33bfb28b0ffc 1547 PIDPeriod = 0x5A, // uint16_t
sgrsn 0:33bfb28b0ffc 1548 IntegralLimit = 0x5C, // uint16_t
sgrsn 0:33bfb28b0ffc 1549 MaxDutyCycleWhileFeedbackOutOfRange = 0x5E, // uint16_t
sgrsn 0:33bfb28b0ffc 1550 MaxAccelerationForward = 0x60, // uint16_t
sgrsn 0:33bfb28b0ffc 1551 MaxAccelerationReverse = 0x62, // uint16_t
sgrsn 0:33bfb28b0ffc 1552 MaxDecelerationForward = 0x64, // uint16_t
sgrsn 0:33bfb28b0ffc 1553 MaxDecelerationReverse = 0x66, // uint16_t
sgrsn 0:33bfb28b0ffc 1554 MaxDutyCycleForward = 0x68, // uint16_t
sgrsn 0:33bfb28b0ffc 1555 MaxDutyCycleReverse = 0x6A, // uint16_t
sgrsn 0:33bfb28b0ffc 1556 EncodedHardCurrentLimitForward = 0x6C, // uint16_t
sgrsn 0:33bfb28b0ffc 1557 EncodedHardCurrentLimitReverse = 0x6E, // uint16_t
sgrsn 0:33bfb28b0ffc 1558 BrakeDurationForward = 0x70, // uint8_t
sgrsn 0:33bfb28b0ffc 1559 BrakeDurationReverse = 0x71, // uint8_t
sgrsn 0:33bfb28b0ffc 1560 SoftCurrentLimitForward = 0x72, // uint16_t
sgrsn 0:33bfb28b0ffc 1561 SoftCurrentLimitReverse = 0x74, // uint16_t
sgrsn 0:33bfb28b0ffc 1562 };
sgrsn 0:33bfb28b0ffc 1563
sgrsn 0:33bfb28b0ffc 1564 uint8_t getVar8SingleByte(uint8_t offset)
sgrsn 0:33bfb28b0ffc 1565 {
sgrsn 0:33bfb28b0ffc 1566 return commandR8((uint8_t)GetVariable8 | (offset + 1));
sgrsn 0:33bfb28b0ffc 1567 }
sgrsn 0:33bfb28b0ffc 1568
sgrsn 0:33bfb28b0ffc 1569 uint16_t getVar16SingleByte(uint8_t offset)
sgrsn 0:33bfb28b0ffc 1570 {
sgrsn 0:33bfb28b0ffc 1571 return commandR16((uint8_t)GetVariable16 | (offset + 1));
sgrsn 0:33bfb28b0ffc 1572 }
sgrsn 0:33bfb28b0ffc 1573
sgrsn 0:33bfb28b0ffc 1574 uint8_t getVar8(uint8_t offset)
sgrsn 0:33bfb28b0ffc 1575 {
sgrsn 0:33bfb28b0ffc 1576 uint8_t result;
sgrsn 0:33bfb28b0ffc 1577 segmentRead(GetVariables, offset, 1, &result);
sgrsn 0:33bfb28b0ffc 1578 return result;
sgrsn 0:33bfb28b0ffc 1579 }
sgrsn 0:33bfb28b0ffc 1580
sgrsn 0:33bfb28b0ffc 1581 uint16_t getVar16(uint8_t offset)
sgrsn 0:33bfb28b0ffc 1582 {
sgrsn 0:33bfb28b0ffc 1583 uint8_t buffer[2];
sgrsn 0:33bfb28b0ffc 1584 segmentRead(GetVariables, offset, 2, buffer);
sgrsn 0:33bfb28b0ffc 1585 return ((uint16_t)buffer[0] << 0) | ((uint16_t)buffer[1] << 8);
sgrsn 0:33bfb28b0ffc 1586 }
sgrsn 0:33bfb28b0ffc 1587
sgrsn 0:33bfb28b0ffc 1588 uint32_t getVar32(uint8_t offset)
sgrsn 0:33bfb28b0ffc 1589 {
sgrsn 0:33bfb28b0ffc 1590 uint8_t buffer[4];
sgrsn 0:33bfb28b0ffc 1591 segmentRead(GetVariables, offset, 4, buffer);
sgrsn 0:33bfb28b0ffc 1592 return ((uint32_t)buffer[0] << 0) |
sgrsn 0:33bfb28b0ffc 1593 ((uint32_t)buffer[1] << 8) |
sgrsn 0:33bfb28b0ffc 1594 ((uint32_t)buffer[2] << 16) |
sgrsn 0:33bfb28b0ffc 1595 ((uint32_t)buffer[3] << 24);
sgrsn 0:33bfb28b0ffc 1596 }
sgrsn 0:33bfb28b0ffc 1597
sgrsn 0:33bfb28b0ffc 1598 void setRAMSetting8(uint8_t offset, uint8_t val)
sgrsn 0:33bfb28b0ffc 1599 {
sgrsn 0:33bfb28b0ffc 1600 segmentWrite(SetRAMSettings, offset, 1, &val);
sgrsn 0:33bfb28b0ffc 1601 }
sgrsn 0:33bfb28b0ffc 1602
sgrsn 0:33bfb28b0ffc 1603 void setRAMSetting16(uint8_t offset, uint16_t val)
sgrsn 0:33bfb28b0ffc 1604 {
sgrsn 0:33bfb28b0ffc 1605 uint8_t buffer[2] = {(uint8_t)val, (uint8_t)(val >> 8)};
sgrsn 0:33bfb28b0ffc 1606 segmentWrite(SetRAMSettings, offset, 2, buffer);
sgrsn 0:33bfb28b0ffc 1607 }
sgrsn 0:33bfb28b0ffc 1608
sgrsn 0:33bfb28b0ffc 1609 void setRAMSetting8x2(uint8_t offset, uint8_t val1, uint8_t val2)
sgrsn 0:33bfb28b0ffc 1610 {
sgrsn 0:33bfb28b0ffc 1611 uint8_t buffer[2] = {val1, val2};
sgrsn 0:33bfb28b0ffc 1612 segmentWrite(SetRAMSettings, offset, 2, buffer);
sgrsn 0:33bfb28b0ffc 1613 }
sgrsn 0:33bfb28b0ffc 1614
sgrsn 0:33bfb28b0ffc 1615 void setRAMSetting16x2(uint8_t offset, uint16_t val1, uint16_t val2)
sgrsn 0:33bfb28b0ffc 1616 {
sgrsn 0:33bfb28b0ffc 1617 uint8_t buffer[4] = {(uint8_t)val1, (uint8_t)(val1 >> 8),
sgrsn 0:33bfb28b0ffc 1618 (uint8_t)val2, (uint8_t)(val2 >> 8)};
sgrsn 0:33bfb28b0ffc 1619 segmentWrite(SetRAMSettings, offset, 4, buffer);
sgrsn 0:33bfb28b0ffc 1620 }
sgrsn 0:33bfb28b0ffc 1621
sgrsn 0:33bfb28b0ffc 1622 // set multiplier and exponent together in one segment write
sgrsn 0:33bfb28b0ffc 1623 // (slightly faster than separate calls to getRAMSetting16() and getRAMSetting8())
sgrsn 0:33bfb28b0ffc 1624 void setPIDCoefficient(uint8_t offset, uint16_t multiplier, uint8_t exponent)
sgrsn 0:33bfb28b0ffc 1625 {
sgrsn 0:33bfb28b0ffc 1626 uint8_t buffer[3] = {(uint8_t)multiplier, (uint8_t)(multiplier >> 8), exponent};
sgrsn 0:33bfb28b0ffc 1627 segmentWrite(SetRAMSettings, offset, 3, buffer);
sgrsn 0:33bfb28b0ffc 1628 }
sgrsn 0:33bfb28b0ffc 1629
sgrsn 0:33bfb28b0ffc 1630 uint8_t getRAMSetting8(uint8_t offset)
sgrsn 0:33bfb28b0ffc 1631 {
sgrsn 0:33bfb28b0ffc 1632 uint8_t result;
sgrsn 0:33bfb28b0ffc 1633 segmentRead(GetRAMSettings, offset, 1, &result);
sgrsn 0:33bfb28b0ffc 1634 return result;
sgrsn 0:33bfb28b0ffc 1635 }
sgrsn 0:33bfb28b0ffc 1636
sgrsn 0:33bfb28b0ffc 1637 uint16_t getRAMSetting16(uint8_t offset)
sgrsn 0:33bfb28b0ffc 1638 {
sgrsn 0:33bfb28b0ffc 1639 uint8_t buffer[2];
sgrsn 0:33bfb28b0ffc 1640 segmentRead(GetRAMSettings, offset, 2, buffer);
sgrsn 0:33bfb28b0ffc 1641 return ((uint16_t)buffer[0] << 0) | ((uint16_t)buffer[1] << 8);
sgrsn 0:33bfb28b0ffc 1642 }
sgrsn 0:33bfb28b0ffc 1643
sgrsn 0:33bfb28b0ffc 1644 // Convenience functions that take care of casting a JrkG2Command to a uint8_t.
sgrsn 0:33bfb28b0ffc 1645
sgrsn 0:33bfb28b0ffc 1646 void commandQuick(JrkG2Command cmd)
sgrsn 0:33bfb28b0ffc 1647 {
sgrsn 0:33bfb28b0ffc 1648 commandQuick((uint8_t)cmd);
sgrsn 0:33bfb28b0ffc 1649 }
sgrsn 0:33bfb28b0ffc 1650
sgrsn 0:33bfb28b0ffc 1651 void commandW7(JrkG2Command cmd, uint8_t val)
sgrsn 0:33bfb28b0ffc 1652 {
sgrsn 0:33bfb28b0ffc 1653 commandW7((uint8_t)cmd, val);
sgrsn 0:33bfb28b0ffc 1654 }
sgrsn 0:33bfb28b0ffc 1655
sgrsn 0:33bfb28b0ffc 1656 void commandWs14(JrkG2Command cmd, int16_t val)
sgrsn 0:33bfb28b0ffc 1657 {
sgrsn 0:33bfb28b0ffc 1658 commandWs14((uint8_t)cmd, val);
sgrsn 0:33bfb28b0ffc 1659 }
sgrsn 0:33bfb28b0ffc 1660
sgrsn 0:33bfb28b0ffc 1661 uint8_t commandR8(JrkG2Command cmd)
sgrsn 0:33bfb28b0ffc 1662 {
sgrsn 0:33bfb28b0ffc 1663 return commandR8((uint8_t)cmd);
sgrsn 0:33bfb28b0ffc 1664 }
sgrsn 0:33bfb28b0ffc 1665
sgrsn 0:33bfb28b0ffc 1666 uint16_t commandR16(JrkG2Command cmd)
sgrsn 0:33bfb28b0ffc 1667 {
sgrsn 0:33bfb28b0ffc 1668 return commandR16((uint8_t)cmd);
sgrsn 0:33bfb28b0ffc 1669 }
sgrsn 0:33bfb28b0ffc 1670
sgrsn 0:33bfb28b0ffc 1671 void segmentRead(JrkG2Command cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1672 uint8_t length, uint8_t * buffer)
sgrsn 0:33bfb28b0ffc 1673 {
sgrsn 0:33bfb28b0ffc 1674 segmentRead((uint8_t)cmd, offset, length, buffer);
sgrsn 0:33bfb28b0ffc 1675 }
sgrsn 0:33bfb28b0ffc 1676
sgrsn 0:33bfb28b0ffc 1677 void segmentWrite(JrkG2Command cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1678 uint8_t length, uint8_t * buffer)
sgrsn 0:33bfb28b0ffc 1679 {
sgrsn 0:33bfb28b0ffc 1680 segmentWrite((uint8_t)cmd, offset, length, buffer);
sgrsn 0:33bfb28b0ffc 1681 }
sgrsn 0:33bfb28b0ffc 1682
sgrsn 0:33bfb28b0ffc 1683 // Low-level functions implemented by the serial/I2C subclasses.
sgrsn 0:33bfb28b0ffc 1684
sgrsn 0:33bfb28b0ffc 1685 virtual void commandQuick(uint8_t cmd) = 0;
sgrsn 0:33bfb28b0ffc 1686 virtual void commandW7(uint8_t cmd, uint8_t val) = 0;
sgrsn 0:33bfb28b0ffc 1687 virtual void commandWs14(uint8_t cmd, int16_t val) = 0;
sgrsn 0:33bfb28b0ffc 1688 virtual uint8_t commandR8(uint8_t cmd) = 0;
sgrsn 0:33bfb28b0ffc 1689 virtual uint16_t commandR16(uint8_t cmd) = 0;
sgrsn 0:33bfb28b0ffc 1690 virtual void segmentRead(uint8_t cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1691 uint8_t length, uint8_t * buffer) = 0;
sgrsn 0:33bfb28b0ffc 1692 virtual void segmentWrite(uint8_t cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1693 uint8_t length, uint8_t * buffer) = 0;
sgrsn 0:33bfb28b0ffc 1694 };
sgrsn 0:33bfb28b0ffc 1695
sgrsn 0:33bfb28b0ffc 1696 /// Represents a serial connection to a Jrk G2.
sgrsn 0:33bfb28b0ffc 1697 ///
sgrsn 0:33bfb28b0ffc 1698 /// For the high-level commands you can use on this object, see JrkG2Base.
sgrsn 2:e78c0ddcf337 1699 class JrkG2Serial : public JrkG2Base
sgrsn 0:33bfb28b0ffc 1700 {
sgrsn 0:33bfb28b0ffc 1701 public:
sgrsn 2:e78c0ddcf337 1702 JrkG2Serial(AsyncSerial *stream, uint8_t deviceNumber = 255) :
sgrsn 0:33bfb28b0ffc 1703 _deviceNumber(deviceNumber)
sgrsn 0:33bfb28b0ffc 1704 {
sgrsn 0:33bfb28b0ffc 1705 _stream = stream;
sgrsn 0:33bfb28b0ffc 1706 }
sgrsn 0:33bfb28b0ffc 1707
sgrsn 0:33bfb28b0ffc 1708 /// Gets the serial device number this object is using.
sgrsn 0:33bfb28b0ffc 1709 uint8_t getDeviceNumber() { return _deviceNumber; }
sgrsn 0:33bfb28b0ffc 1710
sgrsn 0:33bfb28b0ffc 1711 private:
sgrsn 2:e78c0ddcf337 1712 //Serial *_stream;
sgrsn 2:e78c0ddcf337 1713 AsyncSerial *_stream;
sgrsn 2:e78c0ddcf337 1714
sgrsn 0:33bfb28b0ffc 1715 const uint8_t _deviceNumber;
sgrsn 0:33bfb28b0ffc 1716
sgrsn 0:33bfb28b0ffc 1717 virtual void commandQuick(uint8_t cmd) { sendCommandHeader(cmd); }
sgrsn 0:33bfb28b0ffc 1718 virtual void commandW7(uint8_t cmd, uint8_t val);
sgrsn 0:33bfb28b0ffc 1719 virtual void commandWs14(uint8_t cmd, int16_t val);
sgrsn 0:33bfb28b0ffc 1720 virtual uint8_t commandR8(uint8_t cmd);
sgrsn 0:33bfb28b0ffc 1721 virtual uint16_t commandR16(uint8_t cmd);
sgrsn 0:33bfb28b0ffc 1722 virtual void segmentRead(uint8_t cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1723 uint8_t length, uint8_t * buffer);
sgrsn 0:33bfb28b0ffc 1724 virtual void segmentWrite(uint8_t cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1725 uint8_t length, uint8_t * buffer);
sgrsn 0:33bfb28b0ffc 1726
sgrsn 0:33bfb28b0ffc 1727 void sendCommandHeader(uint8_t cmd);
sgrsn 0:33bfb28b0ffc 1728 void serialW7(uint8_t val) { _stream->putc(val & 0x7F); }
sgrsn 0:33bfb28b0ffc 1729 };
sgrsn 0:33bfb28b0ffc 1730
sgrsn 0:33bfb28b0ffc 1731 /// Represents an I2C connection to a Jrk G2.
sgrsn 0:33bfb28b0ffc 1732 ///
sgrsn 0:33bfb28b0ffc 1733 /// For the high-level commands you can use on this object, see JrkG2Base.
sgrsn 0:33bfb28b0ffc 1734 class JrkG2I2C : public JrkG2Base
sgrsn 0:33bfb28b0ffc 1735 {
sgrsn 0:33bfb28b0ffc 1736 public:
sgrsn 0:33bfb28b0ffc 1737 JrkG2I2C(I2C *i2c, uint8_t address = 11) : _address((address & 0x7F) << 1)
sgrsn 0:33bfb28b0ffc 1738 {
sgrsn 0:33bfb28b0ffc 1739 _i2c = i2c;
sgrsn 0:33bfb28b0ffc 1740 }
sgrsn 0:33bfb28b0ffc 1741
sgrsn 0:33bfb28b0ffc 1742 /// Gets the I2C address this object is using.
sgrsn 0:33bfb28b0ffc 1743 uint8_t getAddress() { return _address; }
sgrsn 0:33bfb28b0ffc 1744
sgrsn 0:33bfb28b0ffc 1745 private:
sgrsn 0:33bfb28b0ffc 1746 I2C *_i2c;
sgrsn 0:33bfb28b0ffc 1747 const uint8_t _address;
sgrsn 0:33bfb28b0ffc 1748
sgrsn 0:33bfb28b0ffc 1749 virtual void commandQuick(uint8_t cmd);
sgrsn 0:33bfb28b0ffc 1750 virtual void commandW7(uint8_t cmd, uint8_t val);
sgrsn 0:33bfb28b0ffc 1751 virtual void commandWs14(uint8_t cmd, int16_t val);
sgrsn 0:33bfb28b0ffc 1752 virtual uint8_t commandR8(uint8_t cmd);
sgrsn 0:33bfb28b0ffc 1753 virtual uint16_t commandR16(uint8_t cmd);
sgrsn 0:33bfb28b0ffc 1754 virtual void segmentRead(uint8_t cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1755 uint8_t length, uint8_t * buffer);
sgrsn 0:33bfb28b0ffc 1756 virtual void segmentWrite(uint8_t cmd, uint8_t offset,
sgrsn 0:33bfb28b0ffc 1757 uint8_t length, uint8_t * buffer) ;
sgrsn 0:33bfb28b0ffc 1758 };