|
JMotor
|
class for controlling JMotorDriverServo, with angle calibration and accel and velocity limiting More...
#include <JServoController.h>


Public Member Functions | |
| JServoController (JMotorDriverServo &_servo, bool _reverse=false, float velLimit=INFINITY, float accelLimit=INFINITY, float decelLimit=NAN, unsigned long _disableTimeout=0, float _minAngleLimit=0, float _maxAngleLimit=180, float _pos=90, float _minSetAngle=0, float _maxSetAngle=180, int minServoVal=544, int maxServoVal=2400, bool _preventGoingWrongWay=true, bool _preventGoingTooFast=true, float _stoppingDecelLimit=INFINITY) | |
| Constructor for JServoController, a class for controlling JMotorDriverServo, with angle calibration and accel and velocity limiting. | |
| virtual void | run () |
| call this in your main loop | |
| void | setAngleImmediate (float angle, bool _run=true) |
| set servo angle immediately, without velocity or acceleration limiting | |
| void | setAngleImmediateInc (float angleDiff, bool _run=true) |
| increment servo angle and set immediately, without velocity or acceleration limiting | |
| void | setAngleSmoothed (float angle, bool _run=true) |
| set servo angle target, servo will move to target but at limited velocity and acceleration | |
| void | setDisableTimeout (unsigned long _timeout) |
| default: 0, after how many milliseconds of no movement should the servo be disabled? 0=never disable | |
| unsigned long | getDisableTimeout () |
| unsigned long | getLastMovedMillis () |
| returns the value of millis() when the servo last moved | |
| unsigned long | getMillisSinceMoved () |
| returns the number of milliseconds since the servo last moved | |
| void | setLastMovedMillis (unsigned long mil) |
| allows for changing the variable that stores when the servo last moved | |
| virtual bool | setEnable (bool _enable) |
| enable or disable the servo (start or stop sending a signal to the servo) | |
| bool | enable () |
| equivalent to setEnable(true) | |
| bool | disable () |
| equivalent to setEnable(false) | |
| bool | getEnable () |
| returns whether the servo is enabled or not | |
| float | getPosTarget () |
| what position is the servo moving towards or at | |
| float | getPos () |
| what position is the servo actually being set to? (slowly approaches target if smoothing is used) | |
| float | getVelocity () |
| what rate is servo position being changed at? | |
| bool | isPosAtTarget () |
| true if position=target, false otherwise | |
| bool | isPosNotAtTarget () |
| equivalent to !isPosAtTarget() | |
| float | distToTarget () |
| returns target-position | |
| void | restartRun () |
| if you stopped calling run() for a while, call this before restarting run() to avoid a big jump in movement | |
| bool | getActive () |
| returns whether the servo is "awake" (whether signals are being sent) | |
| void | wake () |
| if the servo has been disabled because of inactivity, calling this function simulates the servo being told to move and wakes it up | |
| void | setReverse (bool rev) |
| bool | getReverse () |
| void | setAngleLimits (float _minAngleLimit, float _maxAngleLimit) |
| void | setMinAngleLimit (float _minAngleLimit) |
| void | setMaxAngleLimit (float _maxAngleLimit) |
| float | getMinAngleLimit () |
| float | getMaxAngleLimit () |
| float | getAngleLimitRange () |
| void | setSetAngles (float _minSetAngle, float _maxSetAngle) |
| void | setMinSetAngle (float _minSetAngle) |
| void | setMaxSetAngle (float _maxSetAngle) |
| float | getAccelLimit () |
| returns value of accelLimit | |
| float | getDecelLimit () |
| float | getVelLimit () |
| returns value of velLimit | |
| void | setAccelLimit (float accelLim) |
| set maximum rate that motor speed can be changed at | |
| void | setAccelAndDecelLimits (float accelLim, float decelLim=NAN) |
| void | setDecelLimit (float decelLim=NAN) |
| void | setVelLimit (float velLim) |
| set maximum motor speed | |
| void | setVelAccelLimits (float velLim, float accelLim, float decelLim=NAN) |
| void | setPosition (float pos, bool _run=true) |
| sets servo position, leaves target where it was | |
| void | setMinServoValue (int value) |
| microseconds for shortest servo pulse | |
| void | setMaxServoValue (int value) |
| microseconds for longest servo pulse | |
| void | setServoRangeValues (int min, int max) |
| set the settings for short and long servo pulses at the same time | |
| int | getMinServoRangeValue () |
| returns setting for microseconds for shortest servo pulse | |
| int | getMaxServoRangeValue () |
| returns setting for microseconds for longest servo pulse | |
| int | getServoValueRange () |
| returns difference (in microseconds) between longest and shortest servo pulse settings | |
| int | getSetMicroseconds () |
| returns how many microseconds the servo signal pulse was most recently set to | |
| bool | getConstrainRange () |
| returns whether the range of set() will be constrained to within -1 and 1 | |
| void | setConstrainRange (bool _constrainRange) |
| set whether the range of set() will be constrained to within -1 and 1 | |
| void | setVel (float vel, bool _run=true) |
| set velocity for controller | |
| void | setVelTarget (float vel, bool _run=true) |
| set target velocity for controller (acceleration limited) | |
| float | getVelTarget () |
| get target velocity for controller | |
| float | getVel () |
| get current velocity of motor | |
| float | getDriverSetVal () |
| returns the value the motor driver is being set to | |
| bool | isDriverInRange () |
| true if motor driver is being set to within its range, false if driver is at a maximum | |
| float | getDriverMinRange () |
| if getDriverSetVal goes below this, isDriverInRange will go false | |
| float | getDriverMaxRange () |
| if getDriverSetVal exceeds this, isDriverInRange will go false | |
| float | getMaxVel () |
| How fast of a motor speed setting would get adjusted to full motor power. | |
| float | getMinVel () |
| slowest speed motor can go | |
| void | setMaxDriverRangeAmount (float _driverRangeAmount) |
| set what fraction of driverRange can be used | |
| bool | setPosTarget (float _posTarget, bool _run=true) |
| set target position (motor drives towards position, following acceleration profile) | |
| bool | setPosSetpoint (float _posSetpoint, bool _run=true) |
| set position for motor to drive towards position as fast as possible (setpoint for control loop if available) | |
| bool | setPosDelta (float _posDelta, bool _run=true, bool _resetPos=false) |
| alternative method for setting velocity that uses setPosSetpoint | |
| float | getPosSetpoint () |
| get position controller is currently trying to get to | |
| float | resetPos () |
| reset what position the controller thinks it's in | |
| bool | isPosModeNotVelocity () |
| true if controller is in position target mode, false if in velocity mode | |
Public Attributes | |
| Derivs_Limiter | dL |
| instance of Derivs_Limiter class used to smoothly move servo | |
Protected Member Functions | |
| void | writeAngleToServo (float ang) |
| float | floatMap (float x, float in_min, float in_max, float out_min, float out_max) |
Protected Attributes | |
| JMotorDriverServo & | servo |
| reference to driver that's a subclass of JMotorDriverServo | |
| unsigned long | disableTimeout |
| variable for how long to wait if not moved before disabling (default: 0, never disable) | |
| float | minAngleLimit |
| lower limit for angle setpoint | |
| float | maxAngleLimit |
| higher limit for angle setpoint | |
| float | minSetAngle |
| when servodriver is set to getMinValue what angle is the servo? | |
| float | maxSetAngle |
| when servodriver is set to getMaxValue what angle is the servo? | |
| bool | reverse |
| reverse range of servo | |
| unsigned long | lastMovedMillis |
| variable used to keep track of how long the servo has been still for | |
| bool | enabled |
| keep track of whether controller is enabled (since even when controller is enabled driver might be disabled if timedout and sleeping) | |
| bool | sleeping |
| has it been longer than disableTimeout since the servo has moved? | |
class for controlling JMotorDriverServo, with angle calibration and accel and velocity limiting
|
inline |
Constructor for JServoController, a class for controlling JMotorDriverServo, with angle calibration and accel and velocity limiting.
| _servo | (JMotorDriverServo&) reference to an instance of a class that's a subclass of JMotorDriverServo |
| _reverse | (bool) default: false, use to reverse direction of servo |
| velLimit | (float) default: INFINITY, maximum velocity you want the servo to move at in limited mode |
| accelLimit | (float) default: INFINITY, maximum acceleration you want the servo to move at in limited mode |
| decelLimit | (float) default: NAN, maximum deceleration you want the servo to move at in limited mode, NAN= use accelLimit |
| _disableTimeout | (unsigned long) default: 0, after how many milliseconds of no movement should the servo be disabled? 0=never disable |
| _minAngleLimit | (float) minimum angle limit for servo |
| _maxAngleLimit | (float) maximum angle limit for servo |
| _pos | (float) default: 90, value to set servo position to at startup |
| _minSetAngle | (float) default: 0, when servo driver is set to its minimum (probably -1) what angle does the servo go to? |
| _maxSetAngle | (float) default: 180, when servo driver is set to its maximum (probably 1) what angle does the servo go to? |
| minServoVal | (int) default: 544, microseconds for servo signal pulse for minimum angle |
| maxServoVal | (int) default: 2400, microseconds for servo signal pulse for maximum angle |
| _preventGoingWrongWay | (bool) default: true, immediately stop if going away from target |
| _preventGoingTooFast | (bool) default: true, immediately slow down if set to a speed above velLimit |
| _stoppingDecelLimit | (float) default: INFINITY, how much extra deceleration can be used to stop the servo in time (if the target moves towards the servo's position) |
|
inlinevirtual |
equivalent to setEnable(false)
Implements JMotorControllerBase.
|
inline |
returns target-position
| (float) |
|
inlinevirtual |
equivalent to setEnable(true)
Implements JMotorControllerBase.
|
inlineprotected |
|
inlinevirtual |
|
inline |
returns whether the servo is "awake" (whether signals are being sent)
| (bool) |
|
inline |
|
inline |
returns whether the range of set() will be constrained to within -1 and 1
| (bool) |
|
inline |
|
inline |
|
inlinevirtual |
if getDriverSetVal exceeds this, isDriverInRange will go false
| (float) |
Implements JMotorControllerBase.
|
inlinevirtual |
if getDriverSetVal goes below this, isDriverInRange will go false
| (float) |
Implements JMotorControllerBase.
|
inlinevirtual |
returns the value the motor driver is being set to
| (float) |
Implements JMotorControllerBase.
|
inlinevirtual |
|
inline |
returns the value of millis() when the servo last moved
| (unsigned | long) |
|
inline |
|
inline |
returns setting for microseconds for longest servo pulse
| (int) |
|
inlinevirtual |
How fast of a motor speed setting would get adjusted to full motor power.
| (float) |
Implements JMotorControllerBase.
|
inline |
returns the number of milliseconds since the servo last moved
| (unsigned | long) |
|
inline |
|
inline |
returns setting for microseconds for shortest servo pulse
| (int) |
|
inlinevirtual |
slowest speed motor can go
Implements JMotorControllerBase.
|
inlinevirtual |
what position is the servo actually being set to? (slowly approaches target if smoothing is used)
| (float) |
Implements JMotorController.
|
inlinevirtual |
get position controller is currently trying to get to
| (float) |
Implements JMotorController.
|
inlinevirtual |
|
inline |
|
inline |
returns difference (in microseconds) between longest and shortest servo pulse settings
| (int) |
|
inline |
returns how many microseconds the servo signal pulse was most recently set to
| (int) |
|
inlinevirtual |
|
inlinevirtual |
|
inline |
what rate is servo position being changed at?
| (float) |
|
inlinevirtual |
get target velocity for controller
| (float) | current velocity target |
Implements JMotorControllerBase.
|
inlinevirtual |
true if motor driver is being set to within its range, false if driver is at a maximum
| (bool) |
Implements JMotorControllerBase.
|
inline |
true if position=target, false otherwise
| (bool) |
|
inlinevirtual |
true if controller is in position target mode, false if in velocity mode
| (bool) |
Implements JMotorController.
|
inline |
equivalent to !isPosAtTarget()
| (bool) |
|
inlinevirtual |
reset what position the controller thinks it's in
| (float) | returns old position |
Implements JMotorController.
|
inline |
|
inlinevirtual |
call this in your main loop
Implements JMotorControllerBase.
Reimplemented in JServoControllerAdvanced, JServoControllerGentle, and JServoControllerStallProtected.
|
inline |
|
inlinevirtual |
set maximum rate that motor speed can be changed at
| _accelLimit | (float) |
Implements JMotorControllerBase.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
set whether the range of set() will be constrained to within -1 and 1
| _constrainRange | (bool) |
|
inline |
|
inline |
default: 0, after how many milliseconds of no movement should the servo be disabled? 0=never disable
| _timeout | (unsigned long) |
|
inlinevirtual |
enable or disable the servo (start or stop sending a signal to the servo)
| _enable | (bool) true=enable, false=disable |
| (bool) | true if state changed, otherwise false |
Implements JMotorControllerBase.
Reimplemented in JServoControllerAdvanced.
|
inline |
allows for changing the variable that stores when the servo last moved
| mil | (unsigned long) |
|
inline |
|
inlinevirtual |
set what fraction of driverRange can be used
| _driverRangeAmount | (float) |
Implements JMotorControllerBase.
|
inline |
microseconds for longest servo pulse
| value | (int) |
|
inline |
|
inline |
|
inline |
microseconds for shortest servo pulse
| value | (int) |
|
inline |
|
inlinevirtual |
alternative method for setting velocity that uses setPosSetpoint
| _posDelta | (float) basically velocity |
| _resetPos | (bool) default=false, keep setting current position to zero |
| _run | (bool) default:true, true = call run() in this function, false = you'll call run() yourself |
| (bool) | did the setting change? |
Implements JMotorController.
|
inline |
|
inlinevirtual |
set position for motor to drive towards position as fast as possible (setpoint for control loop if available)
| _posSetpoint | (float) position setpoint |
| _run | (bool) default:true, true = call run() in this function, false = you'll call run() yourself |
| (bool) | did the setpoint change? |
Implements JMotorController.
|
inlinevirtual |
set target position (motor drives towards position, following acceleration profile)
| _posTarget | (float) target position |
| _run | (bool) default:true, true = call run() in this function, false = you'll call run() yourself |
| (bool) | did the target change? |
Implements JMotorController.
|
inline |
|
inline |
set the settings for short and long servo pulses at the same time
| min | (int) microseconds, often 544 |
| max | (int) microseconds, often 2400 |
|
inline |
|
inlinevirtual |
set velocity for controller
| vel | (float) |
| _run | (bool) default:true, true = call run() in this function, false = you'll call run() yourself |
Implements JMotorControllerBase.
|
inline |
|
inlinevirtual |
set maximum motor speed
| _velLimit | (float) |
Implements JMotorController.
|
inlinevirtual |
set target velocity for controller (acceleration limited)
| vel | (float) target velocity |
| _run | (bool) default:true, true = call run() in this function, false = you'll call run() yourself |
Implements JMotorControllerBase.
|
inline |
if the servo has been disabled because of inactivity, calling this function simulates the servo being told to move and wakes it up
|
inlineprotected |
|
protected |
variable for how long to wait if not moved before disabling (default: 0, never disable)
| Derivs_Limiter JServoController::dL |
instance of Derivs_Limiter class used to smoothly move servo
|
protected |
keep track of whether controller is enabled (since even when controller is enabled driver might be disabled if timedout and sleeping)
|
protected |
variable used to keep track of how long the servo has been still for
|
protected |
higher limit for angle setpoint
|
protected |
when servodriver is set to getMaxValue what angle is the servo?
|
protected |
lower limit for angle setpoint
|
protected |
when servodriver is set to getMinValue what angle is the servo?
|
protected |
reverse range of servo
|
protected |
reference to driver that's a subclass of JMotorDriverServo
|
protected |
has it been longer than disableTimeout since the servo has moved?