HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
MotionHandler Class Reference

Manages the execution of motion commands asynchronously. More...

#include <motion_handler.h>

Public Member Functions

 MotionHandler ()
 Construct a new MotionHandler object.
 
void enqueue (std::function< void()> motion, bool async)
 Enqueue a new motion function.
 
void cancelAll ()
 Cancel all pending motions in the queue.
 
void waitUntilDone ()
 Wait until all queued motions have finished executing.
 
void cancelMotion ()
 Cancel the currently executing motion.
 
bool isInMotion ()
 Check if the handler is currently executing a motion.
 
uint32_t getLastEnqueuedId () const
 Get the ID of the last enqueued motion.
 
uint32_t getCurrentRunningId () const
 Get the ID of the currently running motion.
 
bool isQueueEmpty ()
 Check if the motion queue is empty.
 
void setOnMotionStart (std::function< void()> callback)
 Set a callback that is executed whenever a new motion starts.
 

Friends

void motionHandlerTask (void *param)
 

Detailed Description

Manages the execution of motion commands asynchronously.

The MotionHandler class allows queueing of movement commands, which are executed in a separate PROS task. This permits asynchronous operation without blocking the main control loop.

Definition at line 15 of file motion_handler.h.

Constructor & Destructor Documentation

◆ MotionHandler()

MotionHandler::MotionHandler ( )

Construct a new MotionHandler object.

Member Function Documentation

◆ enqueue()

void MotionHandler::enqueue ( std::function< void()>  motion,
bool  async 
)

Enqueue a new motion function.

Parameters
motionThe function to execute.
asyncIf false, waits until the motion is done before returning.

◆ cancelAll()

void MotionHandler::cancelAll ( )

Cancel all pending motions in the queue.

◆ waitUntilDone()

void MotionHandler::waitUntilDone ( )

Wait until all queued motions have finished executing.

◆ cancelMotion()

void MotionHandler::cancelMotion ( )

Cancel the currently executing motion.

◆ isInMotion()

bool MotionHandler::isInMotion ( )

Check if the handler is currently executing a motion.

Returns
true if a motion is currently running, false otherwise.

◆ getLastEnqueuedId()

uint32_t MotionHandler::getLastEnqueuedId ( ) const
inline

Get the ID of the last enqueued motion.

Returns
uint32_t The ID of the last motion.

Definition at line 57 of file motion_handler.h.

◆ getCurrentRunningId()

uint32_t MotionHandler::getCurrentRunningId ( ) const
inline

Get the ID of the currently running motion.

Returns
uint32_t The ID of the currently running motion.

Definition at line 64 of file motion_handler.h.

◆ isQueueEmpty()

bool MotionHandler::isQueueEmpty ( )
inline

Check if the motion queue is empty.

Returns
true if the queue is empty, false otherwise.

Definition at line 71 of file motion_handler.h.

◆ setOnMotionStart()

void MotionHandler::setOnMotionStart ( std::function< void()>  callback)
inline

Set a callback that is executed whenever a new motion starts.

Parameters
callbackThe callback function.

Definition at line 83 of file motion_handler.h.

Friends And Related Symbol Documentation

◆ motionHandlerTask

void motionHandlerTask ( void *  param)
friend