competition switch

What do I put in my program and where to make autonomous run for 15 seconds. I want to simulate the actual conditions of a match and cannot get my timer to run for only 15 seconds.

I’m using Robotc to program. What I’ve tried is listed below. I know that there should be a better place for it, but I don’t know where.[PHP]task autonomous()

{
ClearTimer(T1);
while(time1[T1] < 15000)
{
(code)
}}
[/PHP]
Just to be clear, the code itself works fine. I’m just trying to make it run for only 15 seconds.

Are you sure that no other part of your autonomous code is resetting T1? For example, are you using any defined functions that might have watchdog timers or something that is resetting T1?

I didn’t use the timer at any other points because I added it in last. All I have in the code is what is posted above. Does anybody know how the fields work when you have to set them up for a competition? The codes on the robots must go through some simple code. I’m thinking it’s missing a start time or some function like that.

RobotC has a built-in debugger that provides a virtual competition switch. I think you can use that the same way you would a physical competition switch.

Problem is, I don’t think the VexNet will automatically shut off the autonomous even with the competition template:

http://help.robotc.net/WebHelpVEX/index.htm#Topics/ROBOTC%20Debugger/Debug%20Windows/Competition%20Control.htm%3FTocPath%3DROBOTC%20Debugger|_____9

I think the field controller does that, but I don’t know how to simulate that.

So I think we’re back to the mystery of why your timer does not seem to work as it should…

Can you use your debugger window to see what your timers are actually doing?
http://help.robotc.net/WebHelpVEX/index.htm#Topics/ROBOTC%20Debugger/Debug%20Windows/Timers.htm%3FTocPath%3DROBOTC%2520Debugger%7C_____10

I tried what you recommended and found out a few things. 1) You must set the motor running in autonomous to 0 in the section after the timer goes. 2) The second section after the autonomous did run after 15 seconds. From these results, I think it’s possible to have the code shut off after 15 seconds if you set all the motors to 0. However, the problem is that with the code that I tried, I didn’t put a wait1msec() , so it would make sense for it to run. I’m wondering if in other circumstances, like a code with loops inside it and wait blocks and so on, if other code overrides the wait function.

Eithre that, or I put in the motors equaling 0 in the wrong part at the end of auton, but there was no signal at all that something happened after 15 seconds.

The debugger window shows that the timer is going up and not stopping after 15. This makes sense though because I have no other clear timer portions of the code.

I think it makes sense to shut down the motors after you kick out of the timer while loop. Usually motors will keep running until something tells them to shut off, which in a normal game would be the field controller, but in this case you need to fake it.

To really do this correctly, use a separate task that starts autonomous, waits 15 seconds, stops the autonomous task and sets all motors to 0.

How do I do this? I don’t know if I’m using the right type of timers and programming in the correct places. Can you show me some pseudo code?

I’m not 100% sure what jpearman has in mind, but since he hasn’t answered yet, I’ll toss this out there for you to consider. Hopefully my advice won’t run you too far aground…

First, write all your autonomous code into a task named, let’s say, autonomous2.

Then, in the main task write code that starts that task, autonomous2, have the main task wait 15 seconds, then have it stop the task named autonomous2.

Maybe something like this:



task main()
{

startTask autonomous2();
wait1MSec(15000);
stopTask autonomous2();

//Next, set all your motors to zero...

}  

Will that work?

If worst comes to worst, use the physical or virtual competition switch use a timer(i.e. phone) to time it manually.