02-04-2009 10:08 AM
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!
02-04-2009 10:21 AM
So this exact code works fine in your teleop?
02-04-2009 10:31 AM
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.
02-04-2009 10:38 AM
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?
02-04-2009 11:19 AM
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.
02-04-2009 12:31 PM
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.
02-04-2009 12:51 PM
Oh, yeah, that makes sense. Sorry about not catching that earlier. Glad you are on the right track now though.
02-06-2009 12:53 PM
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.
02-06-2009 02:28 PM
Yes, good correction. I was wrong about the while loop there.