HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
motion_handler.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstdint>
4
#include <functional>
5
#include <optional>
6
7
namespace
hololib::motion_handler
{
8
/**
9
* @brief run a motion algorithm
10
*
11
* @param f the motion function
12
*
13
* @b Example:
14
* @code {.cpp}
15
* // a simple motion algorithm, as an example
16
* void simpleMotion() {
17
* std::uint32_t prevTime = pros::millis();
18
* // run until the task has been notified
19
* while (!pros::Task::notify_take(true, 0)) {
20
* // motion algorithm stuff would go here
21
* // ...
22
* // wait 10 ms to free up CPU time for other tasks
23
* pros::Task::delay_until(&prevTime, 10);
24
* }
25
* }
26
*
27
* // runs during the autonomous period
28
* void autonomous() {
29
* // pass the motion to the motion handler
30
* hololib::motion_handler::move([&] { simpleMotion(); });
31
* // "Hello World!" is printed immediately after the motion starts
32
* std::cout << "Hello World!" << std::endl;
33
* // but if we try to run another motion while one is still running,
34
* // it will wait until the last one stops running
35
* hololib::motion_handler::move([&] { simpleMotion(); });
36
* std::cout << "Last motion ended, new motion started!" << std::endl;
37
* }
38
* @endcode
39
*/
40
void
move
(std::function<
void
(
void
)> _motion, std::optional<uint32_t> _priority = std::nullopt);
41
/**
42
* @brief cancel the currently running motion, if it exists
43
*
44
* @b Example:
45
* @code {.cpp}
46
* // a simple motion algorithm, as an example
47
* void simpleMotion() {
48
* std::uint32_t prevTime = pros::millis();
49
* // run until the task has been notified
50
* while (!pros::Task::notify_take(true, 0)) {
51
* // motion algorithm stuff would go here
52
* // ...
53
* // wait 10 ms to free up CPU time for other tasks
54
* pros::Task::delay_until(&prevTime, 10);
55
* }
56
* }
57
*
58
* // runs during the autonomous period
59
* void autonomous() {
60
* // pass the motion to the motion handler
61
* hololib::motion_handler::move([&] { simpleMotion(); });
62
* hololib::motion_handler::isMoving(); // returns true
63
* // cancel the motion
64
* hololib::motion_handler::cancel();
65
* pros::delay(10); // give the task time to stop
66
* hololib::motion_handler::isMoving(); // returns false
67
* }
68
* @endcode
69
*/
70
bool
isMoving
();
71
/**
72
* @brief cancel the currently running motion, if it exists
73
*
74
* @b Example:
75
* @code {.cpp}
76
* // a simple motion algorithm, as an example
77
* void simpleMotion() {
78
* std::uint32_t prevTime = pros::millis();
79
* // run until the task has been notified
80
* while (!pros::Task::notify_take(true, 0)) {
81
* // motion algorithm stuff would go here
82
* // ...
83
* // wait 10 ms to free up CPU time for other tasks
84
* pros::Task::delay_until(&prevTime, 10);
85
* }
86
* }
87
*
88
* // runs during the autonomous period
89
* void autonomous() {
90
* // pass the motion to the motion handler
91
* hololib::motion_handler::move([]{ simpleMotion(); });
92
* hololib::motion_handler::isMoving(); // returns true
93
* // cancel the motion
94
* hololib::motion_handler::cancel();
95
* pros::delay(10); // give the task time to stop
96
* hololib::motion_handler::isMoving(); // returns false
97
* }
98
* @endcode
99
*/
100
void
cancel
();
101
102
void
waitUntilDone
();
103
}
// namespace hololib::motion_handler
hololib::motion_handler
Definition
motion_handler.hpp:7
hololib::motion_handler::move
void move(std::function< void(void)> _motion, std::optional< uint32_t > _priority=std::nullopt)
run a motion algorithm
hololib::motion_handler::waitUntilDone
void waitUntilDone()
hololib::motion_handler::cancel
void cancel()
cancel the currently running motion, if it exists
hololib::motion_handler::isMoving
bool isMoving()
cancel the currently running motion, if it exists
include
hololib
motions
motion_handler.hpp
Generated by
1.9.8