okapi::AsyncLinearMotionProfileController class

Base classes

template<typename Input, typename Output>
class AsyncPositionController

Constructors, destructors, conversion operators

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

Public functions

auto operator=(AsyncLinearMotionProfileController&& other) -> AsyncLinearMotionProfileController& deleted
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.
auto removePath(const std::string& ipathId) -> bool
Removes a path and frees the memory it used.
auto getPaths() -> std::vector<std::string>
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.
auto getTarget() -> std::string override
Gets the last set target, or the default target if none was set.
auto getTarget() const -> std::string virtual
Gets the last set target, or the default target if none was set.
auto getProcessValue() const -> std::string 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.
auto getError() const -> double override
Returns the last error of the controller.
auto isSettled() -> bool 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.
auto isDisabled() const -> bool 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.
auto getThread() const -> CrossplatformThread*
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.

Protected static functions

static void trampoline(void* context)

Protected functions

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

Protected variables

std::shared_ptr<Logger> logger
std::map<std::string, std::vector<squiggles::ProfilePoint>> paths
PathfinderLimits limits
std::shared_ptr<ControllerOutput<double>> output
QLength diameter
AbstractMotor::GearsetRatioPair pair
double currentProfilePosition
TimeUtil timeUtil
CrossplatformMutex currentPathMutex
std::string currentPath
std::atomic_bool isRunning
std::atomic_int direction
std::atomic_bool disabled
std::atomic_bool dtorCalled
CrossplatformThread* task

Function documentation

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
itimeUtil The TimeUtil.
ilimits The default limits.
ioutput The output to write velocity targets to.
idiameter The effective diameter for whatever the motor spins.
ipair The gearset.
ilogger The logger this instance will log to.

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.

Parameters
iwaypoints The waypoints to hit on the path.
ipathId A unique identifier to save the path with.

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.

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.

Parameters
iwaypoints The waypoints to hit on the path.
ipathId A unique identifier to save the path with.
ilimits The limits to use for this path only.

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.

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

Removes a path and frees the memory it used.

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

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.

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

Gets the identifiers of all paths saved in this AsyncMotionProfileController.

Returns The identifiers of all paths

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

Executes a path with the given ID.

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

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

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

Executes a path with the given ID.

Parameters
ipathId A unique identifier for the path, previously passed to generatePath().
ibackwards Whether to follow the profile backwards.

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

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

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

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

Returns the last target

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

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

Returns the last target

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

This is overridden to return the current path.

Returns The most recent value of the process variable.

void okapi::AsyncLinearMotionProfileController::waitUntilSettled() override

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.

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.

Parameters
iposition The starting position.
itarget The target position.
ibackwards Whether to follow the profile backwards.

Does not save the path which was generated.

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.

Parameters
iposition The starting position.
itarget The target position.
ilimits The limits to use for this path only.
ibackwards Whether to follow the profile backwards.

Does not save the path which was generated.

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

Returns the last error of the controller.

Returns the last error

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

bool okapi::AsyncLinearMotionProfileController::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.

void okapi::AsyncLinearMotionProfileController::reset() override

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.

void okapi::AsyncLinearMotionProfileController::flipDisable() override

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.

void okapi::AsyncLinearMotionProfileController::flipDisable(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 NOT cause the controller to move to its last set target, unless it was reset in that time.

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

Returns whether the controller is currently disabled.

Returns whether the controller is currently disabled

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

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

Parameters
imaxVelocity Ignored.

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.

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

Returns the underlying thread handle.

Returns The underlying thread handle.

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
ipathId The path ID that will be removed

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

Follow the supplied path.

Must follow the disabled lifecycle.

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