I used a function that @Deicer told me about thread(functionname).detach();. It has solved a lot of tedious driving problems that have come up when practicing. I used it for the arms like so: if (MasterController.ButtonDown.pressing()) { thread(CollectPosition).detach(); } if (MasterController.ButtonLeft.pressing()) { thread(LiftToLevel1).detach(); } if (MasterController.ButtonRight.pressing()) { thread(LiftToLevel2).detach(); }
This only caused my arms to stop moving. My function specifically states to move the arms:
Here: thread(CollectPosition).detach(); I was trying to make it run along with everything else. This way of doing things has worked for everything else, why won’t it work for my arms?
I feel slightly terrified if your code runs inside while(1) loop, because it will create very unmanageble count of threads when you press buttons. Please, do not do that.
Then CollectPosition thread may hang waiting for rotateTo() to finish.
Please, call rotateTo() with last argument (waitForCompletion) set to false for non-blocking functionality.
@weilin, I tried what you suggested and after removing the while loop (which did not seem logical to me but I tried it anyway), none of my robot functions worked at all. this was because I removed the main execution loop in the program. Changing the waitForCompletion did not work either even after I added the main execution loop back in.
where you use rotateTo(…, waitForCompletion=false) as the action.
If you cannot figure out the code on your own, please, describe in all details exactly what your program needs to do and I will write another macro code example.