MultiTasking in competition templete

Ok so my team and I are try to implement multitasking in both the autonomous and user controll of the templete but when the program runs it tries to run the autunmous and the the user controll all at the same time.

Here is my basic idea for the code

*start autonmous (depending on selected autnmous throught the pot)
*run autnoums and if e~stop is pressed stop all autnmous…and wait for aunoumous period to end.

*run usercontroll (drive,lift,intake/outtake)
*run usercontroll (scripted movements. Aka set goal heights)

Any help please.

Which version of RobotC are you using? this behavior happened in older versions but all tasks should now be stopped between autonomous and user control.

We are using the latest version of robotC. And I undertand that it stops automaticly between the two periods. But we have implemented a emergency stop on the autnmous if we see that going to the middle goal in the interaction zone posses a threat of maybe breaking something or flipping because some one is areay there. Also when we try to download a simple code from scratch with NOOOO autnmous at all it still runs a code that was never downloaded or even open in the windows at the time

Without seeing the code it’s hard to help. We (the three 8888 teams) make extensive use of multitasking and have not had any issues. If you want to share the code I’m happy to look at it for you.

This happens to me sometimes when I have been using the PC emulator and forget to switch back to the physical robot for download :slight_smile:

Here is the code in notepad… I do not have robot C at home but i tend to work on it in notepad and fix my mistakes when i get to the school…

We currently do not use the PC emulator it strictly physical programming
Worlds Competition Program.txt (6.97 KB)

How exactly is the e-stop triggered? Do you press a button?

The e stop is triggered by a button on the back of the robot.

OK, so a couple of things.

The most important is to make sure you download the code for competition and then power cycle the cortex (only once is needed then it will be in competition mode). There is a bug in RobotC that causes the autonomous flag to toggle if the cortex is not in competition mode.

https://vexforum.com/attachment.php?attachmentid=5218&stc=1&d=1328473540

If you do not do this I see the effect you describe. This was not an issue in RobotC V2.32 last year, I had seen this before and think I had done a bug report but need to remind them. It may also be a master firmware issue rather than a RobotC issue. Anyway, get the cortex in competition mode and you should be ok.

secondly, a couple of bugs in the code.

I would change the name of e-stop to use an underscore rather than a minus, sometimes compilers will get confused and think you are trying to say “e minus stop” so use e_stop instead.

You also need a double == for a conditional compare. Also the touch sensor should be digital, you have it as an analog input, So the code would be

task kill()
{
 while(true)
 {
   if(SensorValue[e_stop] == 0)
   {
     //do nothing
   } 
   else
   {
     StopTask(auto);
     StopTask(kill);
   }
   wait1Msec(10);
 }
}

There also an extra “;” in the autonomous task, not really a problem but would be a source of confusion if you ever put code in the while statement.

So fix this so it looks like


 while(True);

this

task autonomous()
{
 StartTask(auto);
 StartTask(kill);
 while(True)
 {
  
 }
}

Let us know if this fixes your issues.

Edit:
I changed the touch sensor code again, I hadn’t realized it was setup as an analog sensor and then set it up as a digital input rather than a touch sensor (which uses reversed logic levels).
downloadMode.jpg

It is triggered by a human by a bumper switch on the back of the robot

Hmmm…

I’ve noticed that, in the newest version of ROBOTC (3.05), there is a new variable in the competition template that is set during pre_auton. This variable is called bStopTasksBetweenModes - if set to true, user tasks will stop between autonomous and driver control; if false, user tasks will continue. Leaving this variable unset could create this symptom.

Try adding this statement to pre_auton()


bStopTasksBetweenModes = true;

//Andrew

bStopTasksBetweenModes is an initialized global variable so this is not necessary. I downloaded and ran masterglitch96’s code yesterday so he should be OK if he follows my instructions, although, having said that this line of code


#pragma competitionControl(Competition)

will force RobotC to automatically select competition download for you so it may be something else entirely, perhaps a bad connection to the competition switch or something like that.

ok so i did everything you said and we still came up with the same probelm…i ended up swaping out the brain and controller completly and it fixed the problem… no the new problem that has arised is now my autonmous switching isnt working… we are using a pot to switch between 4 autnomous

my code has a basic going of something like this:

void autonmous()
{
if(SensorValue[auto1] > 0) || (SensorValue[auto1] < 500)
{
//run this code
}
if(SensorValue[auto1] > 1000) || (SensorValue[auto1] < 1500)
{
//run this code
}
if(SensorValue[auto1] > 2500) || (SensorValue[auto1] < 3000)
{
//run this code
}
if(SensorValue[auto1] > 3500) || (SensorValue[auto1] < 4096)
{
//run this code
}
}

and all that happens is it runs on code after the other…

any ideas on how to fix this… i had it working once but lost the code so

Your OR’s ( || ) should be AND’s ( && ), also missing a couple of round brackets.

if( (SensorValue[auto1] > 0) && (SensorValue[auto1] < 500) )
{
//run this code
}

etc...

There are more efficient ways to do this but it should work.

Did you ever try re-downloading the master firmware in the cortex and/or joystick that had the problem? Glad you found a workaround but it would be nice to know which had the error and if reflashing would fix it.

SOAP BOX ]
Sorry to “Nit Pick”, and be Antiquated, and be US Centric, but using the word “Brackets” with a modifier, like “Round Brackets”, seems less precise than a Single Word that Uniquely describes the Symbols like “Parentheses”.

**
**

Parentheses ( )

Parenthesis (
Parenthesis )

Brackets ]

Bracket
Bracket ]

Braces { }

Brace {
Brace }

Inequality Signs < >

Inequality Sign <
Inequality Sign >

Re: Wikipedia article on Bracket ]

I know that it makes it a little Harder to Learn, but when describing “Logic” or “Language Coding”, where the Potential of Errors or Misinterpretation is plausible and undesirable, every little thing that minimizes that Error or Misinterpretation is a very positive thing.

**“The single biggest problem in communication is the illusion that it has taken place.” - George Bernard Shaw **

/SOAP BOX ]

I guess you have discovered one of my secrets, I’m an Englishman.

It’s the habit of a lifetime, I just call them round brackets, square brackets, curly brackets etc. maybe something to do with the students where I went to college in London being predominately foreign and not using English as a first language.

Mark, it’s nice to have you posting again after what seems like a long hiatus :slight_smile:

I was thinking the same thing. Welcome home, Mark.

Well… That explains a lot… The English, who have brought us Lucas Industries plc and , Wood Trimmed Fasciareal

BTW, I would have never guessed your English… :wink: You must have lived here too long…
My Next Door neighbour is of English Origin, he wrote a little book called, “Bum Bags and Fanny Packs”, ISBN 978-0-7867-1702-6.

I guess I can give you a little “grace”… :wink:
My “formal education” on this subject is some Original Computer Manuals of the early 1980’s , High School Dictation Class, and “The C programming Language” By Brian W. Kernighan and Dennis M. Ritchie.

Thanks for Noticing… I have been on to other “Tasks”… And my Value Here has “waned some” because I have not moved on to the Coretex and newer Motors and Sensors… In the past few months, I receive a Loaner Cortex Controller, so I can Replicate, Experiment and Comment on its Usage and Application… I still need to work more with RobotC, both the Older PIC Only version and the Newer Cortex/PIC version, so as to be “more helpful” with its Programmers… I am hoping to get some of the Newer Vex “equipment” in the near future…

Thanks for the Welcome… :wink: I have been working with other Embedded Systems, besides Vex… And for the Time Being, am back working Full Time, so College will be a Part Time or No Time thing… Since I have a Cortex to “play with”, I can start assisting with Questions with it, Try some things Out, and Finish my New User Documentation I started Two and a Half years ago…