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

Base classes

template<typename Input, typename Output>
class AsyncController virtual
Closed-loop controller that steps on its own in another thread and automatically writes to the output.

Constructors, destructors, conversion operators

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) deleted
~AsyncWrapper() override

Public functions

auto operator=(AsyncWrapper<Input, Output>&& other) -> AsyncWrapper<Input, Output>& deleted
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.
auto getTarget() -> Input override
Gets the last set target, or the default target if none was set.
auto getProcessValue() const -> Input override
auto getOutput() const -> Output
Returns the last calculated output of the controller.
auto getError() const -> Output override
Returns the last error of the controller.
auto isSettled() -> bool 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.
auto getMaxOutput() -> Output
Get the upper output bound.
auto getMinOutput() -> Output
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.
auto isDisabled() const -> bool 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.
auto getThread() const -> CrossplatformThread*
Returns the underlying thread handle.

Protected static functions

static void trampoline(void* context)

Protected functions

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

Protected variables

std::shared_ptr<Logger> logger
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
Input lastTarget
double ratio
std::atomic_bool dtorCalled
CrossplatformThread* task

Function documentation

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())

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

Parameters
iinput controller input, passed to the IterativeController
ioutput controller output, written to from the IterativeController
icontroller the controller to use
irateSupplier used for rates used in the main loop and in waitUntilSettled
iratio Any external gear ratio.
ilogger The logger this instance will log to.

The input controller will act like an AsyncController.

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

Writes the value of the controller output.

Parameters
ivalue the controller's output

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

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

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

Returns the last target

template<typename Input, typename Output>
Input okapi::AsyncWrapper<Input, Output>::getProcessValue() const override

Returns The most recent value of the process variable.

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

Returns the last error of the controller.

Does not update when disabled.

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

Returns whether the controller has settled at the target.

Returns whether the controller is settled

Determining what settling means is implementation-dependent.

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

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

Set time between loops.

Parameters
isampleTime time between loops

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

Set controller output bounds.

Parameters
imax max output
imin min output

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

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

Parameters
itargetMax The new max target for controllerSet().
itargetMin The new min target for controllerSet().

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

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

Get the upper output bound.

Returns the upper output bound

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

Get the lower output bound.

Returns the lower output bound

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

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.

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

Sets whether the controller is off or on.

Parameters
iisDisabled whether the controller is disabled

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.

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

Returns whether the controller is currently disabled.

Returns whether the controller is currently disabled

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

Blocks the current task until the controller has settled.

Determining what settling means is implementation-dependent.

template<typename Input, typename Output>
void okapi::AsyncWrapper<Input, Output>::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.

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

Returns the underlying thread handle.

Returns The underlying thread handle.

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

Resumes moving after the controller is reset.

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