LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
okapi::AsyncLinearMotionProfileController Class Reference

#include <asyncLinearMotionProfileController.hpp>

Inheritance diagram for okapi::AsyncLinearMotionProfileController:
okapi::AsyncPositionController< std::string, double > okapi::AsyncController< Input, Output > okapi::ClosedLoopController< Input, Output > okapi::ControllerOutput< Input >

Public Member Functions

 AsyncLinearMotionProfileController (const TimeUtil &itimeUtil, const PathfinderLimits &ilimits, const std::shared_ptr< ControllerOutput< double > > &ioutput, const QLength &idiameter, const AbstractMotor::GearsetRatioPair &ipair, const std::shared_ptr< Logger > &ilogger=Logger::getDefaultLogger())
 An Async Controller which generates and follows 1D motion profiles.
 
 AsyncLinearMotionProfileController (AsyncLinearMotionProfileController &&other)=delete
 
AsyncLinearMotionProfileControlleroperator= (AsyncLinearMotionProfileController &&other)=delete
 
 ~AsyncLinearMotionProfileController () override
 
void generatePath (std::initializer_list< QLength > iwaypoints, const std::string &ipathId)
 Generates a path which intersects the given waypoints and saves it internally with a key of pathId.
 
void generatePath (std::initializer_list< QLength > iwaypoints, const std::string &ipathId, const PathfinderLimits &ilimits)
 Generates a path which intersects the given waypoints and saves it internally with a key of pathId.
 
bool removePath (const std::string &ipathId)
 Removes a path and frees the memory it used.
 
std::vector< std::string > getPaths ()
 Gets the identifiers of all paths saved in this AsyncMotionProfileController.
 
void setTarget (std::string ipathId) override
 Executes a path with the given ID.
 
void setTarget (std::string ipathId, bool ibackwards)
 Executes a path with the given ID.
 
void controllerSet (std::string ivalue) override
 Writes the value of the controller output.
 
std::string getTarget () override
 Gets the last set target, or the default target if none was set.
 
virtual std::string getTarget () const
 Gets the last set target, or the default target if none was set.
 
std::string getProcessValue () const override
 This is overridden to return the current path.
 
void waitUntilSettled () override
 Blocks the current task until the controller has settled.
 
void moveTo (const QLength &iposition, const QLength &itarget, bool ibackwards=false)
 Generates a new path from the position (typically the current position) to the target and blocks until the controller has settled.
 
void moveTo (const QLength &iposition, const QLength &itarget, const PathfinderLimits &ilimits, bool ibackwards=false)
 Generates a new path from the position (typically the current position) to the target and blocks until the controller has settled.
 
double getError () const override
 Returns the last error of the controller.
 
bool isSettled () override
 Returns whether the controller has settled at the target.
 
void reset () override
 Resets the controller's internal state so it is similar to when it was first initialized, while keeping any user-configured information.
 
void flipDisable () override
 Changes whether the controller is off or on.
 
void flipDisable (bool iisDisabled) override
 Sets whether the controller is off or on.
 
bool isDisabled () const override
 Returns whether the controller is currently disabled.
 
void tarePosition () override
 This implementation does nothing because the API always requires the starting position to be specified.
 
void setMaxVelocity (std::int32_t imaxVelocity) override
 This implementation does nothing because the maximum velocity is configured using PathfinderLimits elsewhere.
 
void startThread ()
 Starts the internal thread.
 
CrossplatformThreadgetThread () const
 Returns the underlying thread handle.
 
void forceRemovePath (const std::string &ipathId)
 Attempts to remove a path without stopping execution, then if that fails, disables the controller and removes the path.
 
- Public Member Functions inherited from okapi::ClosedLoopController< Input, Output >
virtual ~ClosedLoopController ()=default
 
virtual void setTarget (Input itarget)=0
 Sets the target for the controller.
 
- Public Member Functions inherited from okapi::ControllerOutput< Input >
virtual void controllerSet (Input ivalue)=0
 Writes the value of the controller output.
 

Protected Member Functions

void loop ()
 
virtual void executeSinglePath (const std::vector< squiggles::ProfilePoint > &path, std::unique_ptr< AbstractRate > rate)
 Follow the supplied path.
 
QAngularSpeed convertLinearToRotational (QSpeed linear) const
 Converts linear "chassis" speed to rotational motor speed.
 
std::string getPathErrorMessage (const std::vector< PathfinderPoint > &points, const std::string &ipathId, int length)
 

Static Protected Member Functions

static void trampoline (void *context)
 

Protected Attributes

std::shared_ptr< Loggerlogger
 
std::map< std::string, std::vector< squiggles::ProfilePoint > > paths {}
 
PathfinderLimits limits
 
std::shared_ptr< ControllerOutput< double > > output
 
QLength diameter
 
AbstractMotor::GearsetRatioPair pair
 
double currentProfilePosition {0}
 
TimeUtil timeUtil
 
CrossplatformMutex currentPathMutex
 
std::string currentPath {""}
 
std::atomic_bool isRunning {false}
 
std::atomic_int direction {1}
 
std::atomic_bool disabled {false}
 
std::atomic_bool dtorCalled {false}
 
CrossplatformThreadtask {nullptr}
 

Detailed Description

Definition at line 21 of file asyncLinearMotionProfileController.hpp.

Constructor & Destructor Documentation

◆ AsyncLinearMotionProfileController() [1/2]

okapi::AsyncLinearMotionProfileController::AsyncLinearMotionProfileController ( const TimeUtil itimeUtil,
const PathfinderLimits ilimits,
const std::shared_ptr< ControllerOutput< double > > &  ioutput,
const QLength &  idiameter,
const AbstractMotor::GearsetRatioPair ipair,
const std::shared_ptr< Logger > &  ilogger = Logger::getDefaultLogger() 
)

An Async Controller which generates and follows 1D motion profiles.

Parameters
itimeUtilThe TimeUtil.
ilimitsThe default limits.
ioutputThe output to write velocity targets to.
idiameterThe effective diameter for whatever the motor spins.
ipairThe gearset.
iloggerThe logger this instance will log to.

◆ AsyncLinearMotionProfileController() [2/2]

okapi::AsyncLinearMotionProfileController::AsyncLinearMotionProfileController ( AsyncLinearMotionProfileController &&  other)
delete

◆ ~AsyncLinearMotionProfileController()

okapi::AsyncLinearMotionProfileController::~AsyncLinearMotionProfileController ( )
override

Member Function Documentation

◆ controllerSet()

void okapi::AsyncLinearMotionProfileController::controllerSet ( std::string  ivalue)
override

Writes the value of the controller output.

This method might be automatically called in another thread by the controller.

This just calls setTarget().

◆ convertLinearToRotational()

QAngularSpeed okapi::AsyncLinearMotionProfileController::convertLinearToRotational ( QSpeed  linear) const
protected

Converts linear "chassis" speed to rotational motor speed.

Parameters
linear"chassis" frame speed
Returns
motor frame speed

◆ executeSinglePath()

virtual void okapi::AsyncLinearMotionProfileController::executeSinglePath ( const std::vector< squiggles::ProfilePoint > &  path,
std::unique_ptr< AbstractRate rate 
)
protectedvirtual

Follow the supplied path.

Must follow the disabled lifecycle.

◆ flipDisable() [1/2]

void okapi::AsyncLinearMotionProfileController::flipDisable ( )
overridevirtual

Changes whether the controller is off or on.

Turning the controller on after it was off will NOT cause the controller to move to its last set target.

Implements okapi::ClosedLoopController< Input, Output >.

◆ flipDisable() [2/2]

void okapi::AsyncLinearMotionProfileController::flipDisable ( bool  iisDisabled)
overridevirtual

Sets whether the controller is off or on.

Turning the controller on after it was off will NOT cause the controller to move to its last set target, unless it was reset in that time.

Parameters
iisDisabledwhether the controller is disabled

Implements okapi::ClosedLoopController< Input, Output >.

◆ forceRemovePath()

void okapi::AsyncLinearMotionProfileController::forceRemovePath ( const std::string &  ipathId)

Attempts to remove a path without stopping execution, then if that fails, disables the controller and removes the path.

Parameters
ipathIdThe path ID that will be removed

◆ generatePath() [1/2]

void okapi::AsyncLinearMotionProfileController::generatePath ( std::initializer_list< QLength >  iwaypoints,
const std::string &  ipathId 
)

Generates a path which intersects the given waypoints and saves it internally with a key of pathId.

Call executePath() with the same pathId to run it.

If the waypoints form a path which is impossible to achieve, an instance of std::runtime_error is thrown (and an error is logged) which describes the waypoints. If there are no waypoints, no path is generated.

Parameters
iwaypointsThe waypoints to hit on the path.
ipathIdA unique identifier to save the path with.

◆ generatePath() [2/2]

void okapi::AsyncLinearMotionProfileController::generatePath ( std::initializer_list< QLength >  iwaypoints,
const std::string &  ipathId,
const PathfinderLimits ilimits 
)

Generates a path which intersects the given waypoints and saves it internally with a key of pathId.

Call executePath() with the same pathId to run it.

If the waypoints form a path which is impossible to achieve, an instance of std::runtime_error is thrown (and an error is logged) which describes the waypoints. If there are no waypoints, no path is generated.

Parameters
iwaypointsThe waypoints to hit on the path.
ipathIdA unique identifier to save the path with.
ilimitsThe limits to use for this path only.

◆ getError()

double okapi::AsyncLinearMotionProfileController::getError ( ) const
overridevirtual

Returns the last error of the controller.

Does not update when disabled. Returns zero if there is no path currently being followed.

Returns
the last error

Implements okapi::ClosedLoopController< Input, Output >.

◆ getPathErrorMessage()

std::string okapi::AsyncLinearMotionProfileController::getPathErrorMessage ( const std::vector< PathfinderPoint > &  points,
const std::string &  ipathId,
int  length 
)
protected

◆ getPaths()

std::vector< std::string > okapi::AsyncLinearMotionProfileController::getPaths ( )

Gets the identifiers of all paths saved in this AsyncMotionProfileController.

Returns
The identifiers of all paths

◆ getProcessValue()

std::string okapi::AsyncLinearMotionProfileController::getProcessValue ( ) const
overridevirtual

This is overridden to return the current path.

Returns
The most recent value of the process variable.

Implements okapi::ClosedLoopController< Input, Output >.

◆ getTarget() [1/2]

virtual std::string okapi::AsyncLinearMotionProfileController::getTarget ( ) const
virtual

Gets the last set target, or the default target if none was set.

Returns
the last target

◆ getTarget() [2/2]

std::string okapi::AsyncLinearMotionProfileController::getTarget ( )
overridevirtual

Gets the last set target, or the default target if none was set.

Returns
the last target

Implements okapi::ClosedLoopController< Input, Output >.

◆ getThread()

CrossplatformThread * okapi::AsyncLinearMotionProfileController::getThread ( ) const

Returns the underlying thread handle.

Returns
The underlying thread handle.

◆ isDisabled()

bool okapi::AsyncLinearMotionProfileController::isDisabled ( ) const
overridevirtual

Returns whether the controller is currently disabled.

Returns
whether the controller is currently disabled

Implements okapi::ClosedLoopController< Input, Output >.

◆ isSettled()

bool okapi::AsyncLinearMotionProfileController::isSettled ( )
overridevirtual

Returns whether the controller has settled at the target.

Determining what settling means is implementation-dependent.

If the controller is disabled, this method must return true.

Returns
whether the controller is settled

Implements okapi::ClosedLoopController< Input, Output >.

◆ loop()

void okapi::AsyncLinearMotionProfileController::loop ( )
protected

◆ moveTo() [1/2]

void okapi::AsyncLinearMotionProfileController::moveTo ( const QLength &  iposition,
const QLength &  itarget,
bool  ibackwards = false 
)

Generates a new path from the position (typically the current position) to the target and blocks until the controller has settled.

Does not save the path which was generated.

Parameters
ipositionThe starting position.
itargetThe target position.
ibackwardsWhether to follow the profile backwards.

◆ moveTo() [2/2]

void okapi::AsyncLinearMotionProfileController::moveTo ( const QLength &  iposition,
const QLength &  itarget,
const PathfinderLimits ilimits,
bool  ibackwards = false 
)

Generates a new path from the position (typically the current position) to the target and blocks until the controller has settled.

Does not save the path which was generated.

Parameters
ipositionThe starting position.
itargetThe target position.
ilimitsThe limits to use for this path only.
ibackwardsWhether to follow the profile backwards.

◆ operator=()

AsyncLinearMotionProfileController & okapi::AsyncLinearMotionProfileController::operator= ( AsyncLinearMotionProfileController &&  other)
delete

◆ removePath()

bool okapi::AsyncLinearMotionProfileController::removePath ( const std::string &  ipathId)

Removes a path and frees the memory it used.

This function returns true if the path was either deleted or didn't exist in the first place. It returns false if the path could not be removed because it is running.

Parameters
ipathIdA unique identifier for the path, previously passed to generatePath()
Returns
true if the path no longer exists

◆ reset()

void okapi::AsyncLinearMotionProfileController::reset ( )
overridevirtual

Resets the controller's internal state so it is similar to when it was first initialized, while keeping any user-configured information.

This implementation also stops movement.

Implements okapi::ClosedLoopController< Input, Output >.

◆ setMaxVelocity()

void okapi::AsyncLinearMotionProfileController::setMaxVelocity ( std::int32_t  imaxVelocity)
overridevirtual

This implementation does nothing because the maximum velocity is configured using PathfinderLimits elsewhere.

Parameters
imaxVelocityIgnored.

Implements okapi::AsyncPositionController< std::string, double >.

◆ setTarget() [1/2]

void okapi::AsyncLinearMotionProfileController::setTarget ( std::string  ipathId)
override

Executes a path with the given ID.

If there is no path matching the ID, the method will return. Any targets set while a path is being followed will be ignored.

Parameters
ipathIdA unique identifier for the path, previously passed to generatePath().

◆ setTarget() [2/2]

void okapi::AsyncLinearMotionProfileController::setTarget ( std::string  ipathId,
bool  ibackwards 
)

Executes a path with the given ID.

If there is no path matching the ID, the method will return. Any targets set while a path is being followed will be ignored.

Parameters
ipathIdA unique identifier for the path, previously passed to generatePath().
ibackwardsWhether to follow the profile backwards.

◆ startThread()

void okapi::AsyncLinearMotionProfileController::startThread ( )

Starts the internal thread.

This should not be called by normal users. This method is called by the AsyncControllerFactory when making a new instance of this class.

◆ tarePosition()

void okapi::AsyncLinearMotionProfileController::tarePosition ( )
overridevirtual

This implementation does nothing because the API always requires the starting position to be specified.

Implements okapi::AsyncPositionController< std::string, double >.

◆ trampoline()

static void okapi::AsyncLinearMotionProfileController::trampoline ( void *  context)
staticprotected

◆ waitUntilSettled()

void okapi::AsyncLinearMotionProfileController::waitUntilSettled ( )
overridevirtual

Blocks the current task until the controller has settled.

This controller is settled when it has finished following a path. If no path is being followed, it is settled.

Implements okapi::AsyncController< Input, Output >.

Member Data Documentation

◆ currentPath

std::string okapi::AsyncLinearMotionProfileController::currentPath {""}
protected

Definition at line 263 of file asyncLinearMotionProfileController.hpp.

◆ currentPathMutex

CrossplatformMutex okapi::AsyncLinearMotionProfileController::currentPathMutex
protected

Definition at line 261 of file asyncLinearMotionProfileController.hpp.

◆ currentProfilePosition

double okapi::AsyncLinearMotionProfileController::currentProfilePosition {0}
protected

Definition at line 257 of file asyncLinearMotionProfileController.hpp.

◆ diameter

QLength okapi::AsyncLinearMotionProfileController::diameter
protected

Definition at line 255 of file asyncLinearMotionProfileController.hpp.

◆ direction

std::atomic_int okapi::AsyncLinearMotionProfileController::direction {1}
protected

Definition at line 265 of file asyncLinearMotionProfileController.hpp.

◆ disabled

std::atomic_bool okapi::AsyncLinearMotionProfileController::disabled {false}
protected

Definition at line 266 of file asyncLinearMotionProfileController.hpp.

◆ dtorCalled

std::atomic_bool okapi::AsyncLinearMotionProfileController::dtorCalled {false}
protected

Definition at line 267 of file asyncLinearMotionProfileController.hpp.

◆ isRunning

std::atomic_bool okapi::AsyncLinearMotionProfileController::isRunning {false}
protected

Definition at line 264 of file asyncLinearMotionProfileController.hpp.

◆ limits

PathfinderLimits okapi::AsyncLinearMotionProfileController::limits
protected

Definition at line 253 of file asyncLinearMotionProfileController.hpp.

◆ logger

std::shared_ptr<Logger> okapi::AsyncLinearMotionProfileController::logger
protected

Definition at line 251 of file asyncLinearMotionProfileController.hpp.

◆ output

std::shared_ptr<ControllerOutput<double> > okapi::AsyncLinearMotionProfileController::output
protected

Definition at line 254 of file asyncLinearMotionProfileController.hpp.

◆ pair

AbstractMotor::GearsetRatioPair okapi::AsyncLinearMotionProfileController::pair
protected

Definition at line 256 of file asyncLinearMotionProfileController.hpp.

◆ paths

std::map<std::string, std::vector<squiggles::ProfilePoint> > okapi::AsyncLinearMotionProfileController::paths {}
protected

Definition at line 252 of file asyncLinearMotionProfileController.hpp.

◆ task

CrossplatformThread* okapi::AsyncLinearMotionProfileController::task {nullptr}
protected

Definition at line 268 of file asyncLinearMotionProfileController.hpp.

◆ timeUtil

TimeUtil okapi::AsyncLinearMotionProfileController::timeUtil
protected

Definition at line 258 of file asyncLinearMotionProfileController.hpp.


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