Autonomous Programming

Hey guys, I’m here with a silly question. I’ve been fighting with myself over how to get a while loop to program during auton. I haven’t been able to get a while loop to exit after the auton task is complete. Can I do something along the lines of

while(autonomous == true){
//My code
}

or will it require something more complicated. Am I just missing something or do I need to do something more.

Is this while loop in the auton task? That task is automatically killed

task autonomous()
{
	while(true){
		
	//stuff
	}
}

Ok, so I’m using this while loop to run a form of a P loop, so is there a way where I can run through like a normal auton task and have a while loop running at the same time?

Ex:

task autonomous{
     while(true){
          //my P loop
     }
     //my code I want to run as well
}

Put the second control loop in another task, then start that second task from the auton task:

If you have bStopTasksBetweenModes = true, then you don’t need to manually stop the P_Control task, otherwise you may need to.


task P_control() {
    while(true) {
        //P loop goes here
        wait1Msec(50);
    }
}

task autonomous() {
    StartTask(P_control);
    //Other code
}

I think you might want your P loop to exit after some target has been met - this could be distance (while encoder/potentiometer < 300), time (say, maximum time you want the robot to spend driving 300 encoder counts forward), or a combination of the two.

You don’t necessarily need to create a new task for the while loop unless you need to your robot to do something else at the same time, such as moving a lift or running an intake.

So my approach to this was to keep my arm level at a certain level while running autonomous. I was going to use either an IME or Potentiometer, depending on my arm range, to say if the arm sags down a bit it will raise it back up. I was going to also use this to continue to adjust my arm range, for example, all the way down, I will set my “height” variable to 0, and maybe my “height” variable to 150 for up.

How would you go about manually stopping tasks between modes. Is there just a certain command, or is there series of code that will have to be run.

@tabor473 How did you make the code show up colored?

Top of comment you see buttons for
bold
italics
etc

the code button makes an area to put code.
[code}
Put stuff here
{/code]
I replaced with { so that it wouldnt work. Here is it working


Put stuff here

I tried that, but it only made certain parts of it colored.

It should be something like this example:


task Downposition(){
while(true){
//Code
}
}
task Intakeposition(){
while(true){
//Code
}
}
task Dumpposition(){
while(true){
//Code
}
}
task autonomous(){
startTask(Downposition);
motor[port1]=127;
motor[port2]=127;
wait1msec(1000);
stopTask(Downposition);
startTask(Intakeposition);
motor[port1]=127;
motor[port2]=-127;
wait1msec(1000);
startTask(Dumpposition);
}

This is practically what I do when programming my autonomous. It’s fairly simple and extremely useful.