|
LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
|
#include <asyncMotionProfileController.hpp>
Public Member Functions | |
| AsyncMotionProfileController (const TimeUtil &itimeUtil, const PathfinderLimits &ilimits, const std::shared_ptr< ChassisModel > &imodel, const ChassisScales &iscales, const AbstractMotor::GearsetRatioPair &ipair, const std::shared_ptr< Logger > &ilogger=Logger::getDefaultLogger()) | |
| An Async Controller which generates and follows 2D motion profiles. | |
| AsyncMotionProfileController (AsyncMotionProfileController &&other)=delete | |
| AsyncMotionProfileController & | operator= (AsyncMotionProfileController &&other)=delete |
| ~AsyncMotionProfileController () override | |
| void | generatePath (std::initializer_list< PathfinderPoint > 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< PathfinderPoint > 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, bool imirrored=false) |
| 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. | |
| 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 (std::initializer_list< PathfinderPoint > iwaypoints, bool ibackwards=false, bool imirrored=false) |
| Generates a new path from the position (typically the current position) to the target and blocks until the controller has settled. | |
| void | moveTo (std::initializer_list< PathfinderPoint > iwaypoints, const PathfinderLimits &ilimits, bool ibackwards=false, bool imirrored=false) |
| Generates a new path from the position (typically the current position) to the target and blocks until the controller has settled. | |
| PathfinderPoint | 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 so it can start from 0 again properly. | |
| 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 |
| void | storePath (const std::string &idirectory, const std::string &ipathId) |
| Saves a generated path to a file. | |
| void | loadPath (const std::string &idirectory, const std::string &ipathId) |
| Loads a path from a directory on the SD card containing a path CSV file. | |
| void | forceRemovePath (const std::string &ipathId) |
| Attempts to remove a path without stopping execution. | |
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) |
| void | internalStorePath (std::ostream &file, const std::string &ipathId) |
| void | internalLoadPath (std::istream &file, const std::string &ipathId) |
| void | internalLoadPathfinderPath (std::istream &leftFile, std::istream &rightFile, const std::string &ipathId) |
Static Protected Member Functions | |
| static void | trampoline (void *context) |
| static std::string | makeFilePath (const std::string &directory, const std::string &filename) |
| Joins and escapes a directory and file name. | |
Protected Attributes | |
| std::shared_ptr< Logger > | logger |
| std::map< std::string, std::vector< squiggles::ProfilePoint > > | paths {} |
| PathfinderLimits | limits |
| std::shared_ptr< ChassisModel > | model |
| ChassisScales | scales |
| AbstractMotor::GearsetRatioPair | pair |
| TimeUtil | timeUtil |
| CrossplatformMutex | currentPathMutex |
| std::string | currentPath {""} |
| std::atomic_bool | isRunning {false} |
| std::atomic_int | direction {1} |
| std::atomic_bool | mirrored {false} |
| std::atomic_bool | disabled {false} |
| std::atomic_bool | dtorCalled {false} |
| CrossplatformThread * | task {nullptr} |
Static Protected Attributes | |
| static constexpr double | DT = 0.01 |
Definition at line 23 of file asyncMotionProfileController.hpp.
| okapi::AsyncMotionProfileController::AsyncMotionProfileController | ( | const TimeUtil & | itimeUtil, |
| const PathfinderLimits & | ilimits, | ||
| const std::shared_ptr< ChassisModel > & | imodel, | ||
| const ChassisScales & | iscales, | ||
| const AbstractMotor::GearsetRatioPair & | ipair, | ||
| const std::shared_ptr< Logger > & | ilogger = Logger::getDefaultLogger() |
||
| ) |
An Async Controller which generates and follows 2D motion profiles.
Throws a std::invalid_argument exception if the gear ratio is zero.
| itimeUtil | The TimeUtil. |
| ilimits | The default limits. |
| imodel | The chassis model to control. |
| iscales | The chassis dimensions. |
| 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::AsyncMotionProfileController::forceRemovePath | ( | const std::string & | ipathId | ) |
Attempts to remove a path without stopping execution.
If that fails, disables the controller and removes the path.
| ipathId | The path ID that will be removed |
| void okapi::AsyncMotionProfileController::generatePath | ( | std::initializer_list< PathfinderPoint > | 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::AsyncMotionProfileController::generatePath | ( | std::initializer_list< PathfinderPoint > | 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.
NOTE: The waypoints are expected to be in the okapi::State::FRAME_TRANSFORMATION format where +x is forward, +y is right, and 0 theta is measured from the +x axis to the +y axis.
| 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. This implementation always returns zero since the robot is assumed to perfectly follow the path. Subclasses can override this to be more accurate using odometry information.
Implements okapi::ClosedLoopController< Input, Output >.
|
protected |
| std::vector< std::string > okapi::AsyncMotionProfileController::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 >.
|
overridevirtual |
Gets the last set target, or the default target if none was set.
Implements okapi::ClosedLoopController< Input, Output >.
| CrossplatformThread * okapi::AsyncMotionProfileController::getThread | ( | ) | const |
|
protected |
|
protected |
|
protected |
|
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 >.
| void okapi::AsyncMotionProfileController::loadPath | ( | const std::string & | idirectory, |
| const std::string & | ipathId | ||
| ) |
Loads a path from a directory on the SD card containing a path CSV file.
/usd/ is automatically prepended to idirectory if it is not specified.
| idirectory | The directory that the path files are stored in |
| ipathId | The path ID that the paths are stored under (and will be loaded into) |
|
protected |
|
staticprotected |
Joins and escapes a directory and file name.
| directory | The directory path, separated by forward slashes (/) and with or without a trailing slash |
| filename | The file name in the directory |
| void okapi::AsyncMotionProfileController::moveTo | ( | std::initializer_list< PathfinderPoint > | iwaypoints, |
| bool | ibackwards = false, |
||
| bool | imirrored = 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.
| iwaypoints | The waypoints to hit on the path. |
| ibackwards | Whether to follow the profile backwards. |
| imirrored | Whether to follow the profile mirrored. |
| void okapi::AsyncMotionProfileController::moveTo | ( | std::initializer_list< PathfinderPoint > | iwaypoints, |
| const PathfinderLimits & | ilimits, | ||
| bool | ibackwards = false, |
||
| bool | imirrored = 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.
| iwaypoints | The waypoints to hit on the path. |
| ilimits | The limits to use for this path only. |
| ibackwards | Whether to follow the profile backwards. |
| imirrored | Whether to follow the profile mirrored. |
|
delete |
| bool okapi::AsyncMotionProfileController::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() |
|
overridevirtual |
Resets the controller so it can start from 0 again properly.
Keeps configuration from before. 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, PathfinderPoint >.
|
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::AsyncMotionProfileController::setTarget | ( | std::string | ipathId, |
| bool | ibackwards, | ||
| bool | imirrored = false |
||
| ) |
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. |
| imirrored | Whether to follow the profile mirrored. |
| void okapi::AsyncMotionProfileController::startThread | ( | ) |
Starts the internal thread.
This should not be called by normal users. This method is called by the AsyncMotionProfileControllerBuilder when making a new instance of this class.
| void okapi::AsyncMotionProfileController::storePath | ( | const std::string & | idirectory, |
| const std::string & | ipathId | ||
| ) |
Saves a generated path to a file.
Paths are stored as <ipathId>.csv. An SD card must be inserted into the brain and the directory must exist. idirectory can be prefixed with /usd/, but it this is not required.
| idirectory | The directory to store the path file in |
| ipathId | The path ID of the generated path |
|
overridevirtual |
This implementation does nothing because the API always requires the starting position to be specified.
Implements okapi::AsyncPositionController< std::string, PathfinderPoint >.
|
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 279 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 277 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 281 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 283 of file asyncMotionProfileController.hpp.
|
staticconstexprprotected |
Definition at line 324 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 284 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 280 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 270 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 268 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 282 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 271 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 273 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 269 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 272 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 285 of file asyncMotionProfileController.hpp.
|
protected |
Definition at line 274 of file asyncMotionProfileController.hpp.