FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

What's wrong with my autonomous?

Hello

I'm using the basic framework. I put my code into the Autonomous independent.vi, at the top of the framework.

We made a code based on the VIs from the "two color tracking camera example" to make the robot follow the trailer and it worked perfectly at the teleop, but when I put it at the autonomous VI, the servos didn't move.

I changed most variables to global to enable communication among all VIs. The servo positions are being calculated at the camera while-loop.

(our robot first finds the trailer with the camera mounted on servos, then corrects it's position)

I tried to set a fixed value to the servos to make sure it wasn't a variable problem.. and it apparently wasn't, because the servos didn't move.

Here's my autonomous code, if someone can point the problem, I'd be grateful.

There's no need to explain the case structures, they only decide what the motors should do based on servo position and size of the object.. my problem is only the servos.

Probably I forgot some basic aspect of the autonomous.

Thanks!http://img201.imageshack.us/img201/2070/autonuq8.jpg

0 Kudos
Message 1 of 9
(6,830 Views)

So this exact code works fine in your teleop?

Stephen B
0 Kudos
Message 2 of 9
(3,268 Views)

Autonomous independent should not have a while loop in it, as it is just called once when the robot starts up. Otherwise, it is called once the robot starts and it gets stuck in there and you never make it to teleop. Hence, the default example autonomous code has no while loop.

Your while loop also has no 'wait' function in it, so it is trying to run as fast as it possibly can. When it runs so fast, it starves out the CPU on the cRIO so that it is entirely dedicated to running your autonomous code as fast as it can. This causes other parallel tasks like your vision loop to have no CPU time.

When your vision loop never gets time to run, it never writes servo values and your servo never moves.

Stephen B
0 Kudos
Message 3 of 9
(3,268 Views)

Yes. My teleop code has more stuff, but this part is like that.

To my understanding, the camera while loop runs in parallel with the teleop and autonomous.. so it's constantly calculating the new positions.

I can't understand why the servos don't react.. do I need to add a "close servo" somewhere? is the watchdog correct?

0 Kudos
Message 4 of 9
(3,268 Views)

I changed to this and the servos are still not moving:

I also tried different waiting times, such as 1 and 2ms, with different N values.

http://img13.imageshack.us/img13/9770/auton2dx4.jpg

0 Kudos
Message 5 of 9
(3,268 Views)

OK, fixed it.

the problem was: I should not put a new OPEN SERVO at the autonomous, I must store the device reference in a global variable and open it at the autonomous.

thanks for the tips on the wait function , it made my code way better.

0 Kudos
Message 6 of 9
(3,268 Views)

Oh, yeah, that makes sense. Sorry about not catching that earlier. Glad you are on the right track now though.

Stephen B
0 Kudos
Message 7 of 9
(3,268 Views)

StephenB wrote:

Autonomous independent should not have a while loop in it, as it is just called once when the robot starts up. Otherwise, it is called once the robot starts and it gets stuck in there and you never make it to teleop. Hence, the default example autonomous code has no while loop.

I'm pretty sure this is incorrect.  Autonomous Independent can (and probably should) have a while loop.  It's called by reference and aborted when autonomous mode ends.  However, if you're using Autonomous Iterative, then it should not have a while loop.  This is the difference between Independent and Iterative.

0 Kudos
Message 8 of 9
(3,268 Views)

Yes, good correction. I was wrong about the while loop there.

Stephen B
0 Kudos
Message 9 of 9
(3,268 Views)