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

closed loop (uses encoder) motor controller More...

#include <JMotorControllerClosed.h>

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

Public Member Functions

 JMotorControllerClosed (JMotorDriver &_driver, JMotorCompensator &_compensator, JEncoder &_encoder, JControlLoop &_controlLoop, float _velLimit=INFINITY, float _accelLimit=INFINITY, float _distFromSetpointLimit=1, bool _preventGoingWrongWay=true, float _maxStoppingDecel=2)
 Constructor for closed loop motor controller.
 
void run ()
 update driver
 
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)
 
bool setPosTarget (float _posTarget, bool _run=true)
 set target position (motor drives towards position, following acceleration profile)
 
bool setPosTargetStallable (float _posTarget, bool _run=true)
 
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
 
void setAccelPosDelta (float _posDelta, bool _run=true, bool _resetPos=false)
 
void setOpenVel (float vel, bool _run=true)
 set velocity without closed loop control
 
void setOpenVelTarget (float vel, bool _run=true)
 set velocity without closed loop control, with limited acceleration
 
float getSpeedError ()
 
float getPosTarget ()
 get position set as target (for smoothed position setting mode)
 
float getPosSetpoint ()
 get position controller is currently trying to get to
 
float getVelTarget ()
 get target velocity for controller
 
float getPosDeltaSetpoint ()
 
float getLastPosSetpoint ()
 
float getTime ()
 
float getDistFromSetpointLimit ()
 
void setDistFromSetpointLimit (float _distFromSetpointLimit)
 
float getVelSetpoint ()
 returns how fast the motor driver is told to move
 
float getVel ()
 get current velocity of motor
 
float getPos ()
 get what position the motor is currently at
 
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
 
bool isClosedLoop ()
 
void setAccelLimit (float _accelLimit)
 set maximum rate that motor speed can be changed at
 
void setVelLimit (float _velLimit)
 set maximum motor speed
 
float getAccelLimit ()
 returns value of accelLimit
 
float getVelLimit ()
 returns value of velLimit
 
void setPreventGoingWrongWay (bool _preventGoingWrongWay)
 
void setMaxStoppingDecel (float _maxStoppingDecel)
 
float getDriverSetVal ()
 returns the value the motor driver is being set to
 
bool setEnable (bool _enable)
 change whether motor controller is enabled
 
void setMaxDriverRangeAmount (float _driverRangeAmount)
 set what fraction of driverRange can be used
 
bool isDriverInRange ()
 true if motor driver is being set to within its range, false if driver is at a maximum
 
bool enable ()
 enable motor controller
 
bool disable ()
 disable motor controller
 
float getDriverMinRange ()
 if getDriverSetVal goes below this, isDriverInRange will go false
 
float getDriverMaxRange ()
 if getDriverSetVal exceeds this, isDriverInRange will go false
 
bool getEnable ()
 is the controller enabled
 
float getMaxVel ()
 How fast of a motor speed setting would get adjusted to full motor power.
 
float getMinVel ()
 slowest speed motor can go
 

Public Attributes

Derivs_Limiter posSetpointSmoother
 
JControlLoopcontrolLoop
 

Protected Attributes

JMotorDriverdriver
 
JMotorCompensatorcompensator
 
JEncoderencoder
 
float velLimit
 
float accelLimit
 
float setVal
 
bool driverInRange
 
bool open
 
unsigned long lastRunMicros
 
float velSetpoint
 
float velSetpointTarget
 
bool posMode
 
float posSetpoint
 
bool smoothed
 
float posDeltaSetpoint
 
float posDeltaSetpointTarget
 
bool limitSetpointDistFromCurrent
 
float distFromSetpointLimit
 
float lastPosSetpoint
 
float time
 

Detailed Description

closed loop (uses encoder) motor controller

Constructor & Destructor Documentation

◆ JMotorControllerClosed()

JMotorControllerClosed::JMotorControllerClosed ( JMotorDriver _driver,
JMotorCompensator _compensator,
JEncoder _encoder,
JControlLoop _controlLoop,
float  _velLimit = INFINITY,
float  _accelLimit = INFINITY,
float  _distFromSetpointLimit = 1,
bool  _preventGoingWrongWay = true,
float  _maxStoppingDecel = 2 
)
inline

Constructor for closed loop motor controller.

Parameters
_driver(JMotorDriver&)
_compensator(JMotorCompensator&)
_encoder(JEncoder)
_controlLoop(JControlLoop)
_velLimit(float) default=INFINITY,
_accelLimit(float) default=INFINITY,
_distFromSetpointLimit(float)= 1.0,
_preventGoingWrongWay(bool) default=true,
_maxStoppingDecel(float) default=2,

Member Function Documentation

◆ disable()

bool JMotorControllerClosed::disable ( )
inlinevirtual

disable motor controller

Return values
(bool)true if state changed

Implements JMotorControllerBase.

◆ enable()

bool JMotorControllerClosed::enable ( )
inlinevirtual

enable motor controller

Return values
(bool)true if state changed

Implements JMotorControllerBase.

◆ getAccelLimit()

float JMotorControllerClosed::getAccelLimit ( )
inlinevirtual

returns value of accelLimit

Return values
(float)

Implements JMotorControllerBase.

◆ getDistFromSetpointLimit()

float JMotorControllerClosed::getDistFromSetpointLimit ( )
inline

◆ getDriverMaxRange()

float JMotorControllerClosed::getDriverMaxRange ( )
inlinevirtual

if getDriverSetVal exceeds this, isDriverInRange will go false

Return values
(float)

Implements JMotorControllerBase.

◆ getDriverMinRange()

float JMotorControllerClosed::getDriverMinRange ( )
inlinevirtual

if getDriverSetVal goes below this, isDriverInRange will go false

Return values
(float)

Implements JMotorControllerBase.

◆ getDriverSetVal()

float JMotorControllerClosed::getDriverSetVal ( )
inlinevirtual

returns the value the motor driver is being set to

Return values
(float)

Implements JMotorControllerBase.

◆ getEnable()

bool JMotorControllerClosed::getEnable ( )
inlinevirtual

is the controller enabled

Return values
(bool)

Implements JMotorControllerBase.

◆ getLastPosSetpoint()

float JMotorControllerClosed::getLastPosSetpoint ( )
inline

◆ getMaxVel()

float JMotorControllerClosed::getMaxVel ( )
inlinevirtual

How fast of a motor speed setting would get adjusted to full motor power.

Note
may change as battery voltage changes
Return values
(float)

Implements JMotorControllerBase.

◆ getMinVel()

float JMotorControllerClosed::getMinVel ( )
inlinevirtual

slowest speed motor can go

Implements JMotorControllerBase.

◆ getPos()

float JMotorControllerClosed::getPos ( )
inlinevirtual

get what position the motor is currently at

Return values
(float)

Implements JMotorController.

◆ getPosDeltaSetpoint()

float JMotorControllerClosed::getPosDeltaSetpoint ( )
inline

◆ getPosSetpoint()

float JMotorControllerClosed::getPosSetpoint ( )
inlinevirtual

get position controller is currently trying to get to

Return values
(float)

Implements JMotorController.

◆ getPosTarget()

float JMotorControllerClosed::getPosTarget ( )
inlinevirtual

get position set as target (for smoothed position setting mode)

Return values
(float)

Implements JMotorController.

◆ getSpeedError()

float JMotorControllerClosed::getSpeedError ( )
inline

◆ getTime()

float JMotorControllerClosed::getTime ( )
inline

◆ getVel()

float JMotorControllerClosed::getVel ( )
inlinevirtual

get current velocity of motor

Return values
(float)

Implements JMotorControllerBase.

◆ getVelLimit()

float JMotorControllerClosed::getVelLimit ( )
inlinevirtual

returns value of velLimit

Return values
(float)

Implements JMotorControllerBase.

◆ getVelSetpoint()

float JMotorControllerClosed::getVelSetpoint ( )
inline

returns how fast the motor driver is told to move

Note
use getVel for actual encoder reading
Return values
(float)

◆ getVelTarget()

float JMotorControllerClosed::getVelTarget ( )
inlinevirtual

get target velocity for controller

Return values
(float)current velocity target

Implements JMotorControllerBase.

◆ isClosedLoop()

bool JMotorControllerClosed::isClosedLoop ( )
inline

◆ isDriverInRange()

bool JMotorControllerClosed::isDriverInRange ( )
inlinevirtual

true if motor driver is being set to within its range, false if driver is at a maximum

Return values
(bool)

Implements JMotorControllerBase.

◆ isPosModeNotVelocity()

bool JMotorControllerClosed::isPosModeNotVelocity ( )
inlinevirtual

true if controller is in position target mode, false if in velocity mode

Return values
(bool)

Implements JMotorController.

◆ resetPos()

float JMotorControllerClosed::resetPos ( )
inlinevirtual

reset what position the controller thinks it's in

Note
don't drive too far without resetting this so that the limited precision of floats doesn't become a problem.
Return values
(float)returns old position

Implements JMotorController.

◆ run()

void JMotorControllerClosed::run ( )
inlinevirtual

update driver

Note
call this function as frequently as possible

Implements JMotorControllerBase.

◆ setAccelLimit()

void JMotorControllerClosed::setAccelLimit ( float  _accelLimit)
inlinevirtual

set maximum rate that motor speed can be changed at

Note
set to INFINITY to disable acceleration limiting
Parameters
_accelLimit(float)

Implements JMotorControllerBase.

◆ setAccelPosDelta()

void JMotorControllerClosed::setAccelPosDelta ( float  _posDelta,
bool  _run = true,
bool  _resetPos = false 
)
inline

◆ setDistFromSetpointLimit()

void JMotorControllerClosed::setDistFromSetpointLimit ( float  _distFromSetpointLimit)
inline

◆ setEnable()

bool JMotorControllerClosed::setEnable ( bool  _enable)
inlinevirtual

change whether motor controller is enabled

Parameters
_enable(bool)
Note
velocity related variables are reset to zero on disable. you can set velocity then enable
Return values
(bool)true if state changed

Implements JMotorControllerBase.

◆ setMaxDriverRangeAmount()

void JMotorControllerClosed::setMaxDriverRangeAmount ( float  _driverRangeAmount)
inlinevirtual

set what fraction of driverRange can be used

Parameters
_driverRangeAmount(float)

Implements JMotorControllerBase.

◆ setMaxStoppingDecel()

void JMotorControllerClosed::setMaxStoppingDecel ( float  _maxStoppingDecel)
inline

◆ setOpenVel()

void JMotorControllerClosed::setOpenVel ( float  vel,
bool  _run = true 
)
inline

set velocity without closed loop control

Parameters
vel(float) velocity to set
_run(bool) default:true, true = call run() in this function, false = you'll call run() yourself

◆ setOpenVelTarget()

void JMotorControllerClosed::setOpenVelTarget ( float  vel,
bool  _run = true 
)
inline

set velocity without closed loop control, with limited acceleration

Parameters
vel(float) velocity to approach
_run(bool) default:true, true = call run() in this function, false = you'll call run() yourself

◆ setPosDelta()

bool JMotorControllerClosed::setPosDelta ( float  _posDelta,
bool  _run = true,
bool  _resetPos = false 
)
inlinevirtual

alternative method for setting velocity that uses setPosSetpoint

Note
handles velocities below getMinVel(), and may have better distance accuracy, doesn't smooth velocity
Parameters
_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
Return values
(bool)did the setting change?

Implements JMotorController.

◆ setPosSetpoint()

bool JMotorControllerClosed::setPosSetpoint ( float  _posSetpoint,
bool  _run = true 
)
inlinevirtual

set position for motor to drive towards position as fast as possible (setpoint for control loop if available)

Note
run() needs to be called in order for the motor to move
Parameters
_posSetpoint(float) position setpoint
_run(bool) default:true, true = call run() in this function, false = you'll call run() yourself
Return values
(bool)did the setpoint change?

Implements JMotorController.

◆ setPosTarget()

bool JMotorControllerClosed::setPosTarget ( float  _posTarget,
bool  _run = true 
)
inlinevirtual

set target position (motor drives towards position, following acceleration profile)

Parameters
_posTarget(float) target position
_run(bool) default:true, true = call run() in this function, false = you'll call run() yourself
Return values
(bool)did the target change?

Implements JMotorController.

◆ setPosTargetStallable()

bool JMotorControllerClosed::setPosTargetStallable ( float  _posTarget,
bool  _run = true 
)
inline

◆ setPreventGoingWrongWay()

void JMotorControllerClosed::setPreventGoingWrongWay ( bool  _preventGoingWrongWay)
inline

◆ setVel()

void JMotorControllerClosed::setVel ( float  vel,
bool  _run = true 
)
inlinevirtual

set velocity for controller

Note
this function can be called repeatedly, or just once if run() is called frequently
Parameters
vel(float)
_run(bool) default:true, true = call run() in this function, false = you'll call run() yourself

Implements JMotorControllerBase.

◆ setVelLimit()

void JMotorControllerClosed::setVelLimit ( float  _velLimit)
inlinevirtual

set maximum motor speed

Note
set to INFINITY to disable limit
Parameters
_velLimit(float)

Implements JMotorController.

◆ setVelTarget()

void JMotorControllerClosed::setVelTarget ( float  vel,
bool  _run = true 
)
inlinevirtual

set target velocity for controller (acceleration limited)

Note
this function can be called repeatedly, or just once if run() is called frequently
Parameters
vel(float) target velocity
_run(bool) default:true, true = call run() in this function, false = you'll call run() yourself

Implements JMotorControllerBase.

Member Data Documentation

◆ accelLimit

float JMotorControllerClosed::accelLimit
protected

◆ compensator

JMotorCompensator& JMotorControllerClosed::compensator
protected

◆ controlLoop

JControlLoop& JMotorControllerClosed::controlLoop

◆ distFromSetpointLimit

float JMotorControllerClosed::distFromSetpointLimit
protected

◆ driver

JMotorDriver& JMotorControllerClosed::driver
protected

◆ driverInRange

bool JMotorControllerClosed::driverInRange
protected

◆ encoder

JEncoder& JMotorControllerClosed::encoder
protected

◆ lastPosSetpoint

float JMotorControllerClosed::lastPosSetpoint
protected

◆ lastRunMicros

unsigned long JMotorControllerClosed::lastRunMicros
protected

◆ limitSetpointDistFromCurrent

bool JMotorControllerClosed::limitSetpointDistFromCurrent
protected

◆ open

bool JMotorControllerClosed::open
protected

◆ posDeltaSetpoint

float JMotorControllerClosed::posDeltaSetpoint
protected

◆ posDeltaSetpointTarget

float JMotorControllerClosed::posDeltaSetpointTarget
protected

◆ posMode

bool JMotorControllerClosed::posMode
protected

◆ posSetpoint

float JMotorControllerClosed::posSetpoint
protected

◆ posSetpointSmoother

Derivs_Limiter JMotorControllerClosed::posSetpointSmoother

Derivs_Limiter object, used for smoothly driving to position

◆ setVal

float JMotorControllerClosed::setVal
protected

◆ smoothed

bool JMotorControllerClosed::smoothed
protected

◆ time

float JMotorControllerClosed::time
protected

◆ velLimit

float JMotorControllerClosed::velLimit
protected

◆ velSetpoint

float JMotorControllerClosed::velSetpoint
protected

◆ velSetpointTarget

float JMotorControllerClosed::velSetpointTarget
protected

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