For our skills auton, we need to have our wings being pushed down all the time. However other code also needs to be running at the same time. Here’s the code:
I need to have wing() running at the same time as everything else in the auton() function. Is there a way to do this? I know this works with C++, but I haven’t found anything for VEXCode Python. Any help would be greatly appreciated!
Thanks,
AHumanIBelieve
Not fully sure what exactly you are doing, but multithreading can almost certainly help.
Given some function func(), you can run that function while also doing other code by using the command: Thread(func).
To see an example of how this is done, you can create a new blocks project, place two or three when_started blocks, and then go to code viewer python. You will see it selects one branch to run as the main function, and creates threads for the other functions.
For coding purposes, multithreading works by running multiple code loops simultaneously. As long as each function has a "while True: ", it can function as simply having multiple main loops. You can also store the thread with “myVar = Thread(func)”, which I would assume would allow a true main loop to close the other loops using myVar. Lastly, although vex will still work, I recommend having a wait(10,MSEC) in all of your loops.
Oh, and while I’m pretty sure this can help you, I would be careful. Test it moderately thoroughly to make sure you aren’t repeatedly opening your wings when they are already open or running your motor when you shouldn’t be, which could potentially damage the motor from trying to turn metal through metal. Idk if the V5 motors break from trying to turn something that can’t turn.