1#ifndef J_MOTOR_CONTROLLER_CLOSED_H
2#define J_MOTOR_CONTROLLER_CLOSED_H
3#include "Derivs_Limiter.h"
66 velLimit = max(_velLimit, (
float)0.0);
224 bool setPosDelta(
float _posDelta,
bool _run =
true,
bool _resetPos =
false)
378 velLimit = max(_velLimit, (
float)0.0);
408 if (_enable ==
false) {
interface for control loop used by JMotorControllerClosed
Definition JControlLoop.h:7
virtual void resetTime()=0
virtual float calc(JMotorControllerClosed *controller)=0
defines common interface for JEncoder
Definition JEncoder.h:33
virtual void setRev(bool _rev)
empty function for directionless encoders to override
Definition JEncoder.h:38
virtual void run()
if an encoder needs to have some code called each loop (like absolute encoder polling encoder and cal...
virtual float getPos()
returns how far the encoder has turned from the zero position converted to distance
virtual float getVel()
calculates velocity in distance per second where distance was set by setdistPerCountFactor()
virtual bool hasDirection()
can this encoder measure direction or just speed
virtual long zeroCounter()
reset the counter of how far the encoder has turned
This class defines a common interface for converting from speed to driver input. It should compensate...
Definition JMotorCompensator.h:9
virtual float getMaxVel()
How fast of a motor speed setting would get adjusted to full motor power.
void setDriverRange(float _driverRange)
set what value makes the driver output 100% of supply voltage
Definition JMotorCompensator.h:19
virtual float compensate(float val)
calculate
virtual float getMinVel()
Slowest speed motor can go.
void setMaxDriverRangeAmount(float _driverRangeAmount)
set what fraction of driverRange can be used
Definition JMotorCompensator.h:27
float getMaxDriverRangeAmount()
get what fraction of driverRange can be used
Definition JMotorCompensator.h:64
This class defines a common interface for classes which control velocity of a motor controlled by a J...
Definition JMotorControllerBase.h:7
closed loop (uses encoder) motor controller
Definition JMotorControllerClosed.h:13
void setDistFromSetpointLimit(float _distFromSetpointLimit)
Definition JMotorControllerClosed.h:330
bool isClosedLoop()
Definition JMotorControllerClosed.h:367
float accelLimit
Definition JMotorControllerClosed.h:20
float posSetpoint
Definition JMotorControllerClosed.h:28
float getVelLimit()
returns value of velLimit
Definition JMotorControllerClosed.h:386
float getAccelLimit()
returns value of accelLimit
Definition JMotorControllerClosed.h:382
float getPosTarget()
get position set as target (for smoothed position setting mode)
Definition JMotorControllerClosed.h:289
bool driverInRange
Definition JMotorControllerClosed.h:22
float getDriverMinRange()
if getDriverSetVal goes below this, isDriverInRange will go false
Definition JMotorControllerClosed.h:439
float velSetpointTarget
Definition JMotorControllerClosed.h:26
bool isPosModeNotVelocity()
true if controller is in position target mode, false if in velocity mode
Definition JMotorControllerClosed.h:363
float getMaxVel()
How fast of a motor speed setting would get adjusted to full motor power.
Definition JMotorControllerClosed.h:454
unsigned long lastRunMicros
Definition JMotorControllerClosed.h:24
void run()
update driver
Definition JMotorControllerClosed.h:83
void setOpenVelTarget(float vel, bool _run=true)
set velocity without closed loop control, with limited acceleration
Definition JMotorControllerClosed.h:275
void setOpenVel(float vel, bool _run=true)
set velocity without closed loop control
Definition JMotorControllerClosed.h:261
float posDeltaSetpoint
Definition JMotorControllerClosed.h:30
float getLastPosSetpoint()
Definition JMotorControllerClosed.h:315
bool disable()
disable motor controller
Definition JMotorControllerClosed.h:434
bool setPosTarget(float _posTarget, bool _run=true)
set target position (motor drives towards position, following acceleration profile)
Definition JMotorControllerClosed.h:175
JEncoder & encoder
Definition JMotorControllerClosed.h:17
bool smoothed
Definition JMotorControllerClosed.h:29
float velSetpoint
Definition JMotorControllerClosed.h:25
bool isDriverInRange()
true if motor driver is being set to within its range, false if driver is at a maximum
Definition JMotorControllerClosed.h:424
bool setEnable(bool _enable)
change whether motor controller is enabled
Definition JMotorControllerClosed.h:406
void setVelLimit(float _velLimit)
set maximum motor speed
Definition JMotorControllerClosed.h:376
void setPreventGoingWrongWay(bool _preventGoingWrongWay)
Definition JMotorControllerClosed.h:391
void setMaxDriverRangeAmount(float _driverRangeAmount)
set what fraction of driverRange can be used
Definition JMotorControllerClosed.h:419
float getPos()
get what position the motor is currently at
Definition JMotorControllerClosed.h:348
float setVal
Definition JMotorControllerClosed.h:21
bool setPosDelta(float _posDelta, bool _run=true, bool _resetPos=false)
alternative method for setting velocity that uses setPosSetpoint
Definition JMotorControllerClosed.h:224
bool getEnable()
is the controller enabled
Definition JMotorControllerClosed.h:449
void setVelTarget(float vel, bool _run=true)
set target velocity for controller (acceleration limited)
Definition JMotorControllerClosed.h:168
float resetPos()
reset what position the controller thinks it's in
Definition JMotorControllerClosed.h:352
float time
Definition JMotorControllerClosed.h:35
void setMaxStoppingDecel(float _maxStoppingDecel)
Definition JMotorControllerClosed.h:396
bool open
Definition JMotorControllerClosed.h:23
JControlLoop & controlLoop
Definition JMotorControllerClosed.h:42
float getVelTarget()
get target velocity for controller
Definition JMotorControllerClosed.h:302
float getDriverMaxRange()
if getDriverSetVal exceeds this, isDriverInRange will go false
Definition JMotorControllerClosed.h:444
float getPosSetpoint()
get position controller is currently trying to get to
Definition JMotorControllerClosed.h:297
float getDistFromSetpointLimit()
Definition JMotorControllerClosed.h:325
float getDriverSetVal()
returns the value the motor driver is being set to
Definition JMotorControllerClosed.h:401
void setVel(float vel, bool _run=true)
set velocity for controller
Definition JMotorControllerClosed.h:161
float getTime()
Definition JMotorControllerClosed.h:320
float getVelSetpoint()
returns how fast the motor driver is told to move
Definition JMotorControllerClosed.h:340
JMotorCompensator & compensator
Definition JMotorControllerClosed.h:16
float lastPosSetpoint
Definition JMotorControllerClosed.h:34
bool enable()
enable motor controller
Definition JMotorControllerClosed.h:429
float getVel()
get current velocity of motor
Definition JMotorControllerClosed.h:344
float getPosDeltaSetpoint()
Definition JMotorControllerClosed.h:310
JMotorDriver & driver
Definition JMotorControllerClosed.h:15
bool posMode
Definition JMotorControllerClosed.h:27
Derivs_Limiter posSetpointSmoother
Definition JMotorControllerClosed.h:41
float velLimit
Definition JMotorControllerClosed.h:19
float posDeltaSetpointTarget
Definition JMotorControllerClosed.h:31
bool setPosSetpoint(float _posSetpoint, bool _run=true)
set position for motor to drive towards position as fast as possible (setpoint for control loop if av...
Definition JMotorControllerClosed.h:211
float getMinVel()
slowest speed motor can go
Definition JMotorControllerClosed.h:459
float getSpeedError()
Definition JMotorControllerClosed.h:284
void setAccelPosDelta(float _posDelta, bool _run=true, bool _resetPos=false)
Definition JMotorControllerClosed.h:240
bool setPosTargetStallable(float _posTarget, bool _run=true)
Definition JMotorControllerClosed.h:193
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.
Definition JMotorControllerClosed.h:56
void setAccelLimit(float _accelLimit)
set maximum rate that motor speed can be changed at
Definition JMotorControllerClosed.h:371
float distFromSetpointLimit
Definition JMotorControllerClosed.h:33
bool limitSetpointDistFromCurrent
Definition JMotorControllerClosed.h:32
This class defines a common interface for classes which control velocity and position of a motor cont...
Definition JMotorController.h:8
defines common interface for all types of JMotorDrivers
Definition JMotorDriver.h:10
virtual bool set(float val)
set motor power
virtual bool setEnable(bool _enable)
use to enable or disable a motor, and sets up pin states
virtual float getMaxRange()
high end of the range
virtual float getMinRange()
low end of the range
virtual bool getEnable()
get the enable state of the driver