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

#include <asyncWrapper.hpp>

Inheritance diagram for okapi::AsyncWrapper< Input, Output >:
okapi::AsyncController< Input, Output > okapi::ClosedLoopController< Input, Output > okapi::ControllerOutput< Input >

Public Member Functions

 AsyncWrapper (const std::shared_ptr< ControllerInput< Input > > &iinput, const std::shared_ptr< ControllerOutput< Output > > &ioutput, const std::shared_ptr< IterativeController< Input, Output > > &icontroller, const Supplier< std::unique_ptr< AbstractRate > > &irateSupplier, const double iratio=1, std::shared_ptr< Logger > ilogger=Logger::getDefaultLogger())
 A wrapper class that transforms an IterativeController into an AsyncController by running it in another task.
 
 AsyncWrapper (AsyncWrapper< Input, Output > &&other)=delete
 
AsyncWrapper< Input, Output > & operator= (AsyncWrapper< Input, Output > &&other)=delete
 
 ~AsyncWrapper () override
 
void setTarget (const Input itarget) override
 Sets the target for the controller.
 
void controllerSet (const Input ivalue) override
 Writes the value of the controller output.
 
Input getTarget () override
 Gets the last set target, or the default target if none was set.
 
Input getProcessValue () const override
 
Output getOutput () const
 Returns the last calculated output of the controller.
 
Output getError () const override
 Returns the last error of the controller.
 
bool isSettled () override
 Returns whether the controller has settled at the target.
 
void setSampleTime (const QTime &isampleTime)
 Set time between loops.
 
void setOutputLimits (const Output imax, const Output imin)
 Set controller output bounds.
 
void setControllerSetTargetLimits (double itargetMax, double itargetMin)
 Sets the (soft) limits for the target range that controllerSet() scales into.
 
Output getMaxOutput ()
 Get the upper output bound.
 
Output getMinOutput ()
 Get the lower output bound.
 
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 (const bool iisDisabled) override
 Sets whether the controller is off or on.
 
bool isDisabled () const override
 Returns whether the controller is currently disabled.
 
void waitUntilSettled () override
 Blocks the current task until the controller has settled.
 
void startThread ()
 Starts the internal thread.
 
CrossplatformThreadgetThread () const
 Returns the underlying thread handle.
 
- Public Member Functions inherited from okapi::ClosedLoopController< Input, Output >
virtual ~ClosedLoopController ()=default
 

Protected Member Functions

void loop ()
 
virtual void resumeMovement ()
 Resumes moving after the controller is reset.
 

Static Protected Member Functions

static void trampoline (void *context)
 

Protected Attributes

std::shared_ptr< Loggerlogger
 
Supplier< std::unique_ptr< AbstractRate > > rateSupplier
 
std::shared_ptr< ControllerInput< Input > > input
 
std::shared_ptr< ControllerOutput< Output > > output
 
std::shared_ptr< IterativeController< Input, Output > > controller
 
bool hasFirstTarget {false}
 
Input lastTarget
 
double ratio
 
std::atomic_bool dtorCalled {false}
 
CrossplatformThreadtask {nullptr}
 

Detailed Description

template<typename Input, typename Output>
class okapi::AsyncWrapper< Input, Output >

Definition at line 22 of file asyncWrapper.hpp.

Constructor & Destructor Documentation

◆ AsyncWrapper() [1/2]

template<typename Input , typename Output >
okapi::AsyncWrapper< Input, Output >::AsyncWrapper ( const std::shared_ptr< ControllerInput< Input > > &  iinput,
const std::shared_ptr< ControllerOutput< Output > > &  ioutput,
const std::shared_ptr< IterativeController< Input, Output > > &  icontroller,
const Supplier< std::unique_ptr< AbstractRate > > &  irateSupplier,
const double  iratio = 1,
std::shared_ptr< Logger ilogger = Logger::getDefaultLogger() 
)
inline

A wrapper class that transforms an IterativeController into an AsyncController by running it in another task.

The input controller will act like an AsyncController.

Parameters
iinputcontroller input, passed to the IterativeController
ioutputcontroller output, written to from the IterativeController
icontrollerthe controller to use
irateSupplierused for rates used in the main loop and in waitUntilSettled
iratioAny external gear ratio.
iloggerThe logger this instance will log to.

Definition at line 35 of file asyncWrapper.hpp.

◆ AsyncWrapper() [2/2]

template<typename Input , typename Output >
okapi::AsyncWrapper< Input, Output >::AsyncWrapper ( AsyncWrapper< Input, Output > &&  other)
delete

◆ ~AsyncWrapper()

template<typename Input , typename Output >
okapi::AsyncWrapper< Input, Output >::~AsyncWrapper ( )
inlineoverride

Definition at line 53 of file asyncWrapper.hpp.

Member Function Documentation

◆ controllerSet()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::controllerSet ( const Input  ivalue)
inlineoverridevirtual

Writes the value of the controller output.

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

Parameters
ivaluethe controller's output

Implements okapi::ControllerOutput< Input >.

Definition at line 74 of file asyncWrapper.hpp.

◆ flipDisable() [1/2]

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::flipDisable ( )
inlineoverridevirtual

Changes whether the controller is off or on.

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

Implements okapi::ClosedLoopController< Input, Output >.

Definition at line 182 of file asyncWrapper.hpp.

◆ flipDisable() [2/2]

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::flipDisable ( const bool  iisDisabled)
inlineoverridevirtual

Sets whether the controller is off or on.

Turning the controller on after it was off will 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 >.

Definition at line 194 of file asyncWrapper.hpp.

◆ getError()

template<typename Input , typename Output >
Output okapi::AsyncWrapper< Input, Output >::getError ( ) const
inlineoverridevirtual

Returns the last error of the controller.

Does not update when disabled.

Implements okapi::ClosedLoopController< Input, Output >.

Definition at line 104 of file asyncWrapper.hpp.

◆ getMaxOutput()

template<typename Input , typename Output >
Output okapi::AsyncWrapper< Input, Output >::getMaxOutput ( )
inline

Get the upper output bound.

Returns
the upper output bound

Definition at line 155 of file asyncWrapper.hpp.

◆ getMinOutput()

template<typename Input , typename Output >
Output okapi::AsyncWrapper< Input, Output >::getMinOutput ( )
inline

Get the lower output bound.

Returns
the lower output bound

Definition at line 164 of file asyncWrapper.hpp.

◆ getOutput()

template<typename Input , typename Output >
Output okapi::AsyncWrapper< Input, Output >::getOutput ( ) const
inline

Returns the last calculated output of the controller.

Definition at line 97 of file asyncWrapper.hpp.

◆ getProcessValue()

template<typename Input , typename Output >
Input okapi::AsyncWrapper< Input, Output >::getProcessValue ( ) const
inlineoverridevirtual
Returns
The most recent value of the process variable.

Implements okapi::ClosedLoopController< Input, Output >.

Definition at line 90 of file asyncWrapper.hpp.

◆ getTarget()

template<typename Input , typename Output >
Input okapi::AsyncWrapper< Input, Output >::getTarget ( )
inlineoverridevirtual

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

Returns
the last target

Implements okapi::ClosedLoopController< Input, Output >.

Definition at line 83 of file asyncWrapper.hpp.

◆ getThread()

template<typename Input , typename Output >
CrossplatformThread * okapi::AsyncWrapper< Input, Output >::getThread ( ) const
inline

Returns the underlying thread handle.

Returns
The underlying thread handle.

Definition at line 239 of file asyncWrapper.hpp.

◆ isDisabled()

template<typename Input , typename Output >
bool okapi::AsyncWrapper< Input, Output >::isDisabled ( ) const
inlineoverridevirtual

Returns whether the controller is currently disabled.

Returns
whether the controller is currently disabled

Implements okapi::ClosedLoopController< Input, Output >.

Definition at line 205 of file asyncWrapper.hpp.

◆ isSettled()

template<typename Input , typename Output >
bool okapi::AsyncWrapper< Input, Output >::isSettled ( )
inlineoverridevirtual

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 >.

Definition at line 116 of file asyncWrapper.hpp.

◆ loop()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::loop ( )
inlineprotected

Definition at line 261 of file asyncWrapper.hpp.

◆ operator=()

template<typename Input , typename Output >
AsyncWrapper< Input, Output > & okapi::AsyncWrapper< Input, Output >::operator= ( AsyncWrapper< Input, Output > &&  other)
delete

◆ reset()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::reset ( )
inlineoverridevirtual

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

Implements okapi::ClosedLoopController< Input, Output >.

Definition at line 172 of file asyncWrapper.hpp.

◆ resumeMovement()

template<typename Input , typename Output >
virtual void okapi::AsyncWrapper< Input, Output >::resumeMovement ( )
inlineprotectedvirtual

Resumes moving after the controller is reset.

Should not cause movement if the controller is turned off, reset, and turned back on.

Definition at line 276 of file asyncWrapper.hpp.

◆ setControllerSetTargetLimits()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::setControllerSetTargetLimits ( double  itargetMax,
double  itargetMin 
)
inline

Sets the (soft) limits for the target range that controllerSet() scales into.

The target computed by controllerSet() is scaled into the range [-itargetMin, itargetMax].

Parameters
itargetMaxThe new max target for controllerSet().
itargetMinThe new min target for controllerSet().

Definition at line 146 of file asyncWrapper.hpp.

◆ setOutputLimits()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::setOutputLimits ( const Output  imax,
const Output  imin 
)
inline

Set controller output bounds.

Parameters
imaxmax output
iminmin output

Definition at line 135 of file asyncWrapper.hpp.

◆ setSampleTime()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::setSampleTime ( const QTime &  isampleTime)
inline

Set time between loops.

Parameters
isampleTimetime between loops

Definition at line 125 of file asyncWrapper.hpp.

◆ setTarget()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::setTarget ( const Input  itarget)
inlineoverridevirtual

Sets the target for the controller.

Implements okapi::ClosedLoopController< Input, Output >.

Definition at line 61 of file asyncWrapper.hpp.

◆ startThread()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::startThread ( )
inline

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.

Definition at line 228 of file asyncWrapper.hpp.

◆ trampoline()

template<typename Input , typename Output >
static void okapi::AsyncWrapper< Input, Output >::trampoline ( void *  context)
inlinestaticprotected

Definition at line 255 of file asyncWrapper.hpp.

◆ waitUntilSettled()

template<typename Input , typename Output >
void okapi::AsyncWrapper< Input, Output >::waitUntilSettled ( )
inlineoverridevirtual

Blocks the current task until the controller has settled.

Determining what settling means is implementation-dependent.

Implements okapi::AsyncController< Input, Output >.

Definition at line 213 of file asyncWrapper.hpp.

Member Data Documentation

◆ controller

template<typename Input , typename Output >
std::shared_ptr<IterativeController<Input, Output> > okapi::AsyncWrapper< Input, Output >::controller
protected

Definition at line 248 of file asyncWrapper.hpp.

◆ dtorCalled

template<typename Input , typename Output >
std::atomic_bool okapi::AsyncWrapper< Input, Output >::dtorCalled {false}
protected

Definition at line 252 of file asyncWrapper.hpp.

◆ hasFirstTarget

template<typename Input , typename Output >
bool okapi::AsyncWrapper< Input, Output >::hasFirstTarget {false}
protected

Definition at line 249 of file asyncWrapper.hpp.

◆ input

template<typename Input , typename Output >
std::shared_ptr<ControllerInput<Input> > okapi::AsyncWrapper< Input, Output >::input
protected

Definition at line 246 of file asyncWrapper.hpp.

◆ lastTarget

template<typename Input , typename Output >
Input okapi::AsyncWrapper< Input, Output >::lastTarget
protected

Definition at line 250 of file asyncWrapper.hpp.

◆ logger

template<typename Input , typename Output >
std::shared_ptr<Logger> okapi::AsyncWrapper< Input, Output >::logger
protected

Definition at line 244 of file asyncWrapper.hpp.

◆ output

template<typename Input , typename Output >
std::shared_ptr<ControllerOutput<Output> > okapi::AsyncWrapper< Input, Output >::output
protected

Definition at line 247 of file asyncWrapper.hpp.

◆ rateSupplier

template<typename Input , typename Output >
Supplier<std::unique_ptr<AbstractRate> > okapi::AsyncWrapper< Input, Output >::rateSupplier
protected

Definition at line 245 of file asyncWrapper.hpp.

◆ ratio

template<typename Input , typename Output >
double okapi::AsyncWrapper< Input, Output >::ratio
protected

Definition at line 251 of file asyncWrapper.hpp.

◆ task

template<typename Input , typename Output >
CrossplatformThread* okapi::AsyncWrapper< Input, Output >::task {nullptr}
protected

Definition at line 253 of file asyncWrapper.hpp.


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