Driving During a Function

I am currently developing an semi-autostack function to be able to drop cones onto my stack while driving to the next cone. I’m thinking about it right now, and it doesn’t seem like this could work, driving and running a fuction. Is my thinking correct, or is there some other way to go about doing this? (I use EasyC by the way so if that makes a difference please let me know.)

I have been waiting all season to ask this question!

The solution to this is quite simple actually. Create a controlRobot() function that contains all of your driver control code other than the button that runs the autostack. You can call this function inside of the autoStack function somewhere so that is constantly checked. Somewhere inside the loop of the function.

I believe people usually split each part into separate tasks running simultaneously (which I’m not sure if EasyC has). You would have a baseControl task for your base (and probably mogo) and a stackControl task for the rest. baseControl would be the same the whole time, but stackControl would toggle between driver control functions (if statements checking for button presses) and an auto stack function using your auto stack button.

The way suggested by Electrobotz would also work, except you would have to disable the if statements for lift, arm, and intake (or whatever you use for auto stack) or else they would double define motor values (discrepancy between value from auto stack function and value from joystick input) and cause issues.

Yes, if EasyC can do tasks, that’s the way to go. If not, roughly what @The Electrobotz said will work. Presumably, though, your autostack isn’t actually a loop. But you can put the command in a few spots, especially in loops inside autostack. For instance, let’s say your autostack has something like this (in pseudocode because I don’t know EasyC):


setMotor(armMotor,64);
while(ArmPot<3000){
delay(10);
}
setMotor(armMotor,0);

Then you can delete the delay and insert controlRobot() that @The Electrobotz suggested in its place to get


setMotor(armMotor,64);
while(ArmPot<3000){
controlRobot();
}
setMotor(armMotor,0);

Most likely nowhere you don’t have a loop will take much time at all. And most likely anywhere you do have a loop, it’s there to provide a delay. So replacing only the delays with controlRobot() should essentially remove all delay issues and allow you to control it fine.

You might also consider including an abort button press along with controlRobot(). It will complicate your code a little bit, but not so much. That way you can exit if something goes wrong, like while driving you smack the cone into the stationary goal and it falls out so there is nothing to continue stacking.

If I have a wait(1500) fuction or something of that nature, how would I control the robot during the wait time?
Actually I just thought of something. I beleive there’s a timer function in EasyC and I could use a while loop waiting for the timer to increase to a certain amount. For times when I use a potentiometer, I’ll do what you suggested above.

In place of the motors and wait:

Get the timer value;
Add your desired time to it;
Start motors;
While(timerValue<targetTime){
controlRobot();
}
Stop motors;

Yes, I believe that will work! Thank you very much all!