|
LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
|
#include <asyncLinearMotionProfileController.hpp>
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 | |
| AsyncLinearMotionProfileController & | operator= (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. | |
| CrossplatformThread * | getThread () 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< 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 {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} |
| CrossplatformThread * | task {nullptr} |
Definition at line 21 of file asyncLinearMotionProfileController.hpp.
| 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.
| 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. |
|
delete |
|
override |
|
override |
Writes the value of the controller output.
This method might be automatically called in another thread by the controller.
This just calls setTarget().
|
protected |
Converts linear "chassis" speed to rotational motor speed.
| linear | "chassis" frame speed |
|
protectedvirtual |
Follow the supplied path.
Must follow the disabled lifecycle.
|
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 >.
|
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.
| iisDisabled | whether the controller is disabled |
Implements okapi::ClosedLoopController< Input, Output >.
| 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.
| ipathId | The path ID that will be removed |
| 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.
| iwaypoints | The waypoints to hit on the path. |
| ipathId | A unique identifier to save the path with. |
| 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.
| 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. |
|
overridevirtual |
Returns the last error of the controller.
Does not update when disabled. Returns zero if there is no path currently being followed.
Implements okapi::ClosedLoopController< Input, Output >.
|
protected |
| std::vector< std::string > okapi::AsyncLinearMotionProfileController::getPaths | ( | ) |
Gets the identifiers of all paths saved in this AsyncMotionProfileController.
|
overridevirtual |
This is overridden to return the current path.
Implements okapi::ClosedLoopController< Input, Output >.
|
virtual |
Gets the last set target, or the default target if none was set.
|
overridevirtual |
Gets the last set target, or the default target if none was set.
Implements okapi::ClosedLoopController< Input, Output >.
| CrossplatformThread * okapi::AsyncLinearMotionProfileController::getThread | ( | ) | const |
Returns the underlying thread handle.
|
overridevirtual |
Returns whether the controller is currently disabled.
Implements okapi::ClosedLoopController< Input, Output >.
|
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.
Implements okapi::ClosedLoopController< Input, Output >.
|
protected |
| 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.
| iposition | The starting position. |
| itarget | The target position. |
| ibackwards | Whether to follow the profile backwards. |
| 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.
| iposition | The starting position. |
| itarget | The target position. |
| ilimits | The limits to use for this path only. |
| ibackwards | Whether to follow the profile backwards. |
|
delete |
| 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.
| ipathId | A unique identifier for the path, previously passed to generatePath() |
true if the path no longer exists
|
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 >.
|
overridevirtual |
This implementation does nothing because the maximum velocity is configured using PathfinderLimits elsewhere.
| imaxVelocity | Ignored. |
Implements okapi::AsyncPositionController< std::string, double >.
|
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.
| ipathId | A unique identifier for the path, previously passed to generatePath(). |
| 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.
| ipathId | A unique identifier for the path, previously passed to generatePath(). |
| ibackwards | Whether to follow the profile backwards. |
| 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.
|
overridevirtual |
This implementation does nothing because the API always requires the starting position to be specified.
Implements okapi::AsyncPositionController< std::string, double >.
|
staticprotected |
|
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 >.
|
protected |
Definition at line 263 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 261 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 257 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 255 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 265 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 266 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 267 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 264 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 253 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 251 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 254 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 256 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 252 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 268 of file asyncLinearMotionProfileController.hpp.
|
protected |
Definition at line 258 of file asyncLinearMotionProfileController.hpp.