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

Committer:
sgrsn
Date:
Sat Aug 25 13:15:38 2018 +0000
Revision:
1:d611aa1f9f70
Parent:
0:33bfb28b0ffc
Child:
2:e78c0ddcf337
remove comments

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