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

This class controls velocity and position of a motor without any encoder feedback. More...

#include <JMotorControllerOpen.h>

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

Public Member Functions

 JMotorControllerOpen (JMotorDriver &_driver, JMotorCompensator &_compensator, float _velLimit=INFINITY, float _accelLimit=INFINITY, unsigned long _minMotorPulseTime=0)
 Constructor for an object that controls a motor, and can smooth the motion of the motor and go approximately to a position.
 
void run ()
 update driver
 
bool setEnable (bool _enable)
 change whether motor controller is enabled
 
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 getPosTarget ()
 get position set as target (for smoothed position setting mode)
 
float getPosSetpoint ()
 get position controller is currently trying to get to
 
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
 
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)
 
void setVelLimit (float _velLimit)
 set maximum motor speed
 
void setAccelLimit (float _accelLimit)
 set maximum rate that motor speed can be changed at
 
void setVelAccelLimits (float _vel, float _accel)
 set velocity and acceleration limits for motor
 
void setMinMotorPulseTime (unsigned long _minMotorPulseTime)
 At low speeds in setPosDelta the motor cycles between min speed and stopped. What is the minimum pulse that makes the motor move, in MICROseconds?
 
- Public Member Functions inherited from JMotorControllerBasic
 JMotorControllerBasic (JMotorDriver &_driver, JMotorCompensator &_compensator, float _velLimit=INFINITY, float _accelLimit=INFINITY)
 constructor
 
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
 
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
 
void setMaxDriverRangeAmount (float _driverRangeAmount)
 set what fraction of driverRange can be used
 
float getVelLimit ()
 returns value of velLimit
 
float getAccelLimit ()
 returns value of accelLimit
 

Public Attributes

Derivs_Limiter dL
 use functions from JMotorControllerOpen whenever possible, but the Derivs_Limiter object is public in case you need to change a setting like dL.setPreventGoingWrongWay()
 

Protected Attributes

bool posMode
 
bool smoothedMode
 
float position
 
float positionTarget
 
float posDelta
 
unsigned long lastRunOpenMicros
 
unsigned long minMotorPulseTime
 
unsigned long lastPosDeltaWrite
 
- Protected Attributes inherited from JMotorControllerBasic
float velocity
 
float setVal
 
float velocityTarget
 
float accelLimit
 
float velLimit
 
unsigned long lastRunMicros
 
JMotorDriverdriver
 
bool driverInRange
 
JMotorCompensatorcompensator
 

Detailed Description

This class controls velocity and position of a motor without any encoder feedback.

Constructor & Destructor Documentation

◆ JMotorControllerOpen()

JMotorControllerOpen::JMotorControllerOpen ( JMotorDriver _driver,
JMotorCompensator _compensator,
float  _velLimit = INFINITY,
float  _accelLimit = INFINITY,
unsigned long  _minMotorPulseTime = 0 
)
inline

Constructor for an object that controls a motor, and can smooth the motion of the motor and go approximately to a position.

Parameters
_driverreference to a JMotorDriver
_compensatorreference to a JMotorCompensator
_velLimitfloat, default INFINITY
_accelLimitfloat, default INFINITY
_minMotorPulseTimeunsigned long, default 0. At low speeds in setPosDelta the motor cycles between min speed and stopped. What is the minimum pulse that makes the motor move, in MICROseconds?

Member Function Documentation

◆ getPos()

float JMotorControllerOpen::getPos ( )
inlinevirtual

get what position the motor is currently at

Return values
(float)

Implements JMotorController.

◆ getPosSetpoint()

float JMotorControllerOpen::getPosSetpoint ( )
inlinevirtual

get position controller is currently trying to get to

Return values
(float)

Implements JMotorController.

◆ getPosTarget()

float JMotorControllerOpen::getPosTarget ( )
inlinevirtual

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

Return values
(float)

Implements JMotorController.

◆ isPosModeNotVelocity()

bool JMotorControllerOpen::isPosModeNotVelocity ( )
inlinevirtual

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

Return values
(bool)

Implements JMotorController.

◆ resetPos()

float JMotorControllerOpen::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 JMotorControllerOpen::run ( )
inlinevirtual

update driver

Note
call this function as frequently as possible

Implements JMotorControllerBase.

◆ setAccelLimit()

void JMotorControllerOpen::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.

◆ setEnable()

bool JMotorControllerOpen::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.

◆ setMinMotorPulseTime()

void JMotorControllerOpen::setMinMotorPulseTime ( unsigned long  _minMotorPulseTime)
inline

At low speeds in setPosDelta the motor cycles between min speed and stopped. What is the minimum pulse that makes the motor move, in MICROseconds?

Parameters
_minMotorPulseTimeunsigned long

◆ setPosDelta()

bool JMotorControllerOpen::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 JMotorControllerOpen::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 JMotorControllerOpen::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.

◆ setVel()

void JMotorControllerOpen::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.

◆ setVelAccelLimits()

void JMotorControllerOpen::setVelAccelLimits ( float  _vel,
float  _accel 
)
inline

set velocity and acceleration limits for motor

Parameters
_vel
_accel
Return values
None

◆ setVelLimit()

void JMotorControllerOpen::setVelLimit ( float  _velLimit)
inlinevirtual

set maximum motor speed

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

Implements JMotorController.

◆ setVelTarget()

void JMotorControllerOpen::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

◆ dL

Derivs_Limiter JMotorControllerOpen::dL

use functions from JMotorControllerOpen whenever possible, but the Derivs_Limiter object is public in case you need to change a setting like dL.setPreventGoingWrongWay()

Note
https://github.com/joshua-8/Derivs_Limiter

◆ lastPosDeltaWrite

unsigned long JMotorControllerOpen::lastPosDeltaWrite
protected

◆ lastRunOpenMicros

unsigned long JMotorControllerOpen::lastRunOpenMicros
protected

◆ minMotorPulseTime

unsigned long JMotorControllerOpen::minMotorPulseTime
protected

◆ posDelta

float JMotorControllerOpen::posDelta
protected

◆ position

float JMotorControllerOpen::position
protected

◆ positionTarget

float JMotorControllerOpen::positionTarget
protected

◆ posMode

bool JMotorControllerOpen::posMode
protected

◆ smoothedMode

bool JMotorControllerOpen::smoothedMode
protected

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