LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
asyncLinearMotionProfileController.hpp
Go to the documentation of this file.
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6#pragma once
7
15#include <atomic>
16#include <map>
17
18#include "squiggles.hpp"
19
20namespace okapi {
22 public:
34 const TimeUtil &itimeUtil,
35 const PathfinderLimits &ilimits,
36 const std::shared_ptr<ControllerOutput<double>> &ioutput,
37 const QLength &idiameter,
39 const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
40
42
45
47
59 void generatePath(std::initializer_list<QLength> iwaypoints, const std::string &ipathId);
60
73 void generatePath(std::initializer_list<QLength> iwaypoints,
74 const std::string &ipathId,
75 const PathfinderLimits &ilimits);
76
85 bool removePath(const std::string &ipathId);
86
92 std::vector<std::string> getPaths();
93
100 void setTarget(std::string ipathId) override;
101
109 void setTarget(std::string ipathId, bool ibackwards);
110
117 void controllerSet(std::string ivalue) override;
118
124 std::string getTarget() override;
125
131 virtual std::string getTarget() const;
132
138 std::string getProcessValue() const override;
139
144 void waitUntilSettled() override;
145
154 void moveTo(const QLength &iposition, const QLength &itarget, bool ibackwards = false);
155
165 void moveTo(const QLength &iposition,
166 const QLength &itarget,
167 const PathfinderLimits &ilimits,
168 bool ibackwards = false);
169
176 double getError() const override;
177
186 bool isSettled() override;
187
192 void reset() override;
193
198 void flipDisable() override;
199
206 void flipDisable(bool iisDisabled) override;
207
213 bool isDisabled() const override;
214
219 void tarePosition() override;
220
227 void setMaxVelocity(std::int32_t imaxVelocity) override;
228
234
241
248 void forceRemovePath(const std::string &ipathId);
249
250 protected:
251 std::shared_ptr<Logger> logger;
252 std::map<std::string, std::vector<squiggles::ProfilePoint>> paths{};
254 std::shared_ptr<ControllerOutput<double>> output;
255 QLength diameter;
259
260 // This must be locked when accessing the current path
262
263 std::string currentPath{""};
264 std::atomic_bool isRunning{false};
265 std::atomic_int direction{1};
266 std::atomic_bool disabled{false};
267 std::atomic_bool dtorCalled{false};
269
270 static void trampoline(void *context);
271 void loop();
272
276 virtual void executeSinglePath(const std::vector<squiggles::ProfilePoint> &path,
277 std::unique_ptr<AbstractRate> rate);
278
285 QAngularSpeed convertLinearToRotational(QSpeed linear) const;
286
287 std::string getPathErrorMessage(const std::vector<PathfinderPoint> &points,
288 const std::string &ipathId,
289 int length);
290};
291} // namespace okapi
virtual std::string getTarget() const
Gets the last set target, or the default target if none was set.
void setTarget(std::string ipathId) override
Executes a path with the given ID.
std::string getProcessValue() const override
This is overridden to return the current path.
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.
void flipDisable(bool iisDisabled) override
Sets whether the controller is off or on.
double getError() const override
Returns the last error of the controller.
std::string getPathErrorMessage(const std::vector< PathfinderPoint > &points, const std::string &ipathId, int length)
static void trampoline(void *context)
QAngularSpeed convertLinearToRotational(QSpeed linear) const
Converts linear "chassis" speed to rotational motor speed.
void controllerSet(std::string ivalue) override
Writes the value of the controller output.
AsyncLinearMotionProfileController & operator=(AsyncLinearMotionProfileController &&other)=delete
std::map< std::string, std::vector< squiggles::ProfilePoint > > paths
void flipDisable() override
Changes whether the controller is off or on.
void forceRemovePath(const std::string &ipathId)
Attempts to remove a path without stopping execution, then if that fails, disables the controller and...
std::shared_ptr< ControllerOutput< double > > output
void startThread()
Starts the internal thread.
void tarePosition() override
This implementation does nothing because the API always requires the starting position to be specifie...
void setTarget(std::string ipathId, bool ibackwards)
Executes a path with the given ID.
void reset() override
Resets the controller's internal state so it is similar to when it was first initialized,...
CrossplatformThread * getThread() const
Returns the underlying thread handle.
bool isDisabled() const override
Returns whether the controller is currently disabled.
AsyncLinearMotionProfileController(AsyncLinearMotionProfileController &&other)=delete
void setMaxVelocity(std::int32_t imaxVelocity) override
This implementation does nothing because the maximum velocity is configured using PathfinderLimits el...
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 unti...
std::vector< std::string > getPaths()
Gets the identifiers of all paths saved in this AsyncMotionProfileController.
bool removePath(const std::string &ipathId)
Removes a path and frees the memory it used.
void waitUntilSettled() override
Blocks the current task until the controller has settled.
virtual void executeSinglePath(const std::vector< squiggles::ProfilePoint > &path, std::unique_ptr< AbstractRate > rate)
Follow the supplied path.
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 isSettled() override
Returns whether the controller has settled at the target.
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.
std::string getTarget() override
Gets the last set target, or the default target if none was set.
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 unti...
static std::shared_ptr< Logger > getDefaultLogger()
Utility class for holding an AbstractTimer, AbstractRate, and SettledUtil together in one class since...
Definition timeUtil.hpp:18
A simple structure representing the full ratio between motor and wheel.