HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
hololib::motion_handler Namespace Reference

Functions

void move (std::function< void(void)> _motion, std::optional< uint32_t > _priority=std::nullopt)
 run a motion algorithm
 
bool isMoving ()
 cancel the currently running motion, if it exists
 
void cancel ()
 cancel the currently running motion, if it exists
 
void waitUntilDone ()
 

Function Documentation

◆ move()

void hololib::motion_handler::move ( std::function< void(void)>  _motion,
std::optional< uint32_t >  _priority = std::nullopt 
)

run a motion algorithm

Parameters
fthe motion function

Example:

// a simple motion algorithm, as an example
void simpleMotion() {
std::uint32_t prevTime = pros::millis();
// run until the task has been notified
while (!pros::Task::notify_take(true, 0)) {
// motion algorithm stuff would go here
// ...
// wait 10 ms to free up CPU time for other tasks
pros::Task::delay_until(&prevTime, 10);
}
}
// runs during the autonomous period
void autonomous() {
// pass the motion to the motion handler
hololib::motion_handler::move([&] { simpleMotion(); });
// "Hello World!" is printed immediately after the motion starts
std::cout << "Hello World!" << std::endl;
// but if we try to run another motion while one is still running,
// it will wait until the last one stops running
hololib::motion_handler::move([&] { simpleMotion(); });
std::cout << "Last motion ended, new motion started!" << std::endl;
}
void autonomous(void)
Autonomous phase entry point.
void move(std::function< void(void)> _motion, std::optional< uint32_t > _priority=std::nullopt)
run a motion algorithm

◆ isMoving()

bool hololib::motion_handler::isMoving ( )

cancel the currently running motion, if it exists

Example:

// a simple motion algorithm, as an example
void simpleMotion() {
std::uint32_t prevTime = pros::millis();
// run until the task has been notified
while (!pros::Task::notify_take(true, 0)) {
// motion algorithm stuff would go here
// ...
// wait 10 ms to free up CPU time for other tasks
pros::Task::delay_until(&prevTime, 10);
}
}
// runs during the autonomous period
void autonomous() {
// pass the motion to the motion handler
hololib::motion_handler::move([&] { simpleMotion(); });
// cancel the motion
pros::delay(10); // give the task time to stop
}
void cancel()
cancel the currently running motion, if it exists
bool isMoving()
cancel the currently running motion, if it exists

◆ cancel()

void hololib::motion_handler::cancel ( )

cancel the currently running motion, if it exists

Example:

// a simple motion algorithm, as an example
void simpleMotion() {
std::uint32_t prevTime = pros::millis();
// run until the task has been notified
while (!pros::Task::notify_take(true, 0)) {
// motion algorithm stuff would go here
// ...
// wait 10 ms to free up CPU time for other tasks
pros::Task::delay_until(&prevTime, 10);
}
}
// runs during the autonomous period
void autonomous() {
// pass the motion to the motion handler
hololib::motion_handler::move([]{ simpleMotion(); });
// cancel the motion
pros::delay(10); // give the task time to stop
}

◆ waitUntilDone()

void hololib::motion_handler::waitUntilDone ( )