Run code on exit

So, my team is working on our robot, and we need a way to reset solenoids among other things when the program exits. Is there a way to run a bit of code on exit?

Do you mean when the robot is disabled ? or when you quit the program using the stop button on the V5 ?

When I quit the program by tapping the red square.

I don’t think we have a way for user code to detect that. When you stop a program, vexos halts the user cpu (yes, we have a dual cpu architecture, vexos is primarily running on one and user programs on the other). We will consider adding some way of graceful user code shutdown in the future

Couldn’t you use a different button (maybe one you make on the screen)? Run a task looking for that button to be pressed or set it up via an event. When the button is pressed, you kill off all non-main tasks and end any nigh-infinite loop, not while(true), but while(someBooleanToBeChangedOnThatButtonPress), running in main. Then main will execute whatever code follows the loop before ending.

We do have a way for a user program to request termination. That’s probably not in the VCS C++ API at the moment (it’s in the C API but we have not documented that and prefer that everyone use C++), perhaps we can also add that for the next VCS release.

Tell me more about the C API