JMotor
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
JServoControllerAdvanced Class Reference

class for controlling JMotorDriverServoAdvanced, with power reducing option along with standard JServoController features More...

#include <JServoControllerAdvanced.h>

Inheritance diagram for JServoControllerAdvanced:
Inheritance graph
[legend]
Collaboration diagram for JServoControllerAdvanced:
Collaboration graph
[legend]

Public Member Functions

 JServoControllerAdvanced (JMotorDriverServoAdvanced &_servo, float _weakFreq=.5, unsigned long _weakenTimeout=0, float _normalFreq=1.0, unsigned long _startWeakTimeout=0, 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 JServoControllerAdvanced, a class for controlling JMotorDriverServoAdvanced, with angle calibration and accel and velocity limiting.
 
virtual void run ()
 call this in your main loop
 
bool setEnable (bool _enable)
 enable or disable the servo (start or stop sending a signal to the servo)
 
void setStrengthWeak ()
 set servo to weaker setting
 
void setStrengthNormal ()
 set servo to normal setting
 
void adjustServoFrequency (float freq=1.0)
 adjust frequency as a fraction of standard 50hz frequency lower frequencies (try .75) may let you reduce how strongly the servo holds its position
 
void setWeakFreq (float _weak)
 change setting for what fraction of normal frequency the signal should go to in order to weaken the servo's strength
 
void setNormalFreq (float _norm)
 
bool getWeakened ()
 
void setWeakTimeout (unsigned long _timeout)
 
unsigned long getWeakenTimeout ()
 
void setStartWeakTimeout (unsigned long _timeout)
 
unsigned long getStartWeakTimeout ()
 
float getWeakFreq ()
 
float getNormalFreq ()
 
- Public Member Functions inherited from JServoController
 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.
 
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
 
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
 

Protected Attributes

JMotorDriverServoAdvancedadServo
 reference to the servo motor driver
 
unsigned long weakenTimeout
 
float defaultFreq
 
float weakFreq
 
bool weakened
 
unsigned long startWeakTimeout
 
unsigned long enabledMillis
 
- Protected Attributes inherited from JServoController
JMotorDriverServoservo
 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?
 

Additional Inherited Members

- Public Attributes inherited from JServoController
Derivs_Limiter dL
 instance of Derivs_Limiter class used to smoothly move servo
 
- Protected Member Functions inherited from JServoController
void writeAngleToServo (float ang)
 
float floatMap (float x, float in_min, float in_max, float out_min, float out_max)
 

Detailed Description

class for controlling JMotorDriverServoAdvanced, with power reducing option along with standard JServoController features

Note
this servo controller supports adjusting the servo signal frequency which for many servos can change how hard the servos push

Constructor & Destructor Documentation

◆ JServoControllerAdvanced()

JServoControllerAdvanced::JServoControllerAdvanced ( JMotorDriverServoAdvanced _servo,
float  _weakFreq = .5,
unsigned long  _weakenTimeout = 0,
float  _normalFreq = 1.0,
unsigned long  _startWeakTimeout = 0,
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 
)
inline

Constructor for JServoControllerAdvanced, a class for controlling JMotorDriverServoAdvanced, with angle calibration and accel and velocity limiting.

Note
the "advanced" servo driver supports adjusting the servo signal frequency
Parameters
_servo(JMotorDriverServoAdvanced&) reference to an instance of a class that's a subclass of JMotorDriverServo
_weakFreq(float) default: .5, what fraction of normal frequency the signal should go to in order to weaken the servo's strength
_weakenTimeout(unsigned long) default: 0, after how many milliseconds of no movement should the servo be set to lower power? 0=never switch to low power
_normalFreq(float) default: 1, what fraction of 50Hz should be used
_startWeakTimeout(unsigned long) default 0, how many milliseconds after enabling should the servo be in weakened mode (to soften jumps at startup)? 0=inactive
_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)

Member Function Documentation

◆ adjustServoFrequency()

void JServoControllerAdvanced::adjustServoFrequency ( float  freq = 1.0)
inline

adjust frequency as a fraction of standard 50hz frequency lower frequencies (try .75) may let you reduce how strongly the servo holds its position

Note
different servos may respond differently to non-normal signals, including possibly being damaged, so use at your own risk!
Parameters
freq(float) freq*50=setFrequency

◆ getNormalFreq()

float JServoControllerAdvanced::getNormalFreq ( )
inline

◆ getStartWeakTimeout()

unsigned long JServoControllerAdvanced::getStartWeakTimeout ( )
inline

◆ getWeakened()

bool JServoControllerAdvanced::getWeakened ( )
inline

◆ getWeakenTimeout()

unsigned long JServoControllerAdvanced::getWeakenTimeout ( )
inline

◆ getWeakFreq()

float JServoControllerAdvanced::getWeakFreq ( )
inline

◆ run()

virtual void JServoControllerAdvanced::run ( )
inlinevirtual

call this in your main loop

Reimplemented from JServoController.

Reimplemented in JServoControllerStallProtected.

◆ setEnable()

bool JServoControllerAdvanced::setEnable ( bool  _enable)
inlinevirtual

enable or disable the servo (start or stop sending a signal to the servo)

Note
some (nicer digital) servos may not turn off their motors when the signal is stopped, but cheap servos usually do
Parameters
_enable(bool) true=enable, false=disable
Return values
(bool)true if state changed, otherwise false

Reimplemented from JServoController.

◆ setNormalFreq()

void JServoControllerAdvanced::setNormalFreq ( float  _norm)
inline

◆ setStartWeakTimeout()

void JServoControllerAdvanced::setStartWeakTimeout ( unsigned long  _timeout)
inline

◆ setStrengthNormal()

void JServoControllerAdvanced::setStrengthNormal ( )
inline

set servo to normal setting

◆ setStrengthWeak()

void JServoControllerAdvanced::setStrengthWeak ( )
inline

set servo to weaker setting

◆ setWeakFreq()

void JServoControllerAdvanced::setWeakFreq ( float  _weak)
inline

change setting for what fraction of normal frequency the signal should go to in order to weaken the servo's strength

Parameters
_weak(float)

◆ setWeakTimeout()

void JServoControllerAdvanced::setWeakTimeout ( unsigned long  _timeout)
inline
Note
if set to zero (disabling weakening after a timeout) strength remains at the last set value until you use setStrengthWeak() or setStrengthNormal()

Member Data Documentation

◆ adServo

JMotorDriverServoAdvanced& JServoControllerAdvanced::adServo
protected

reference to the servo motor driver

Note
this reference is of the advanced type so can set frequency.
Return values
None

◆ defaultFreq

float JServoControllerAdvanced::defaultFreq
protected

◆ enabledMillis

unsigned long JServoControllerAdvanced::enabledMillis
protected

◆ startWeakTimeout

unsigned long JServoControllerAdvanced::startWeakTimeout
protected

◆ weakened

bool JServoControllerAdvanced::weakened
protected

◆ weakenTimeout

unsigned long JServoControllerAdvanced::weakenTimeout
protected

◆ weakFreq

float JServoControllerAdvanced::weakFreq
protected

The documentation for this class was generated from the following file: