The problem though is that when I’m driving the bot and hit the button while moving, I cannot control the driving until the lift stops. I think I heard that there is a way around this (i heard it called multitasking), but I have no idea how to do this in my code.
Any help is appreciated!
This thread talks about macros and might be relevant for you to understand.
If this is in your usercontrol() while(1) loop, then you cannot use blocking functions without the consequence you are experiencing. In the while(1) loop you can do something like this:
int run_macro=0;
int cube_done=0;
int arm_done=0;
while (1) {
// normal drive code
if ( arm button pressing) {
// your code
run_macro=0; // if user takes control stop macro
arm_done=0;
cube_done=0;
}
if (cube button pressing) {
// you code
run_macro=0;
arm_done=0;
cube_done=0;
}
...
// macro code
if (macro button pressing && run_macro=0) {
run_macro = 1;
}
if (run_macro) {
if (cubeTilt.position(rotationUnits::deg) < 255) {
cubeTilt.spin(directionType::fwd, tiltSpeed, velocityUnits::dps);
cube_done=0;
} else {
cube_done=1;
}
if (armLift.position(rotationUnits::deg) < 600) {
armLift.spin(directionType::fwd, armSpeed, velocityUnits::dps);
arm_done=0;
} else {
arm_done=1;
}
if (arm_done && cube_done) {
run_macro=0;
}
}
}
ed: added the stop if pushing the cube or arm button