Log in

View Full Version : Timing Autonomous with While Loops?


stopyourself
06-03-2015, 08:54
In the 2015 timed autonomous tutorial, found here: https://decibel.ni.com/content/docs/DOC-26295 NI uses wait loops to instruct the drive motors. My mentor who worked with me during build season is no longer coming to meetings, but he instructed me to NEVER use these because they're CPU hogs. The thought is giving me anxiety.

Is this the correct way? Is there an alternative?

Mark McLeod
06-03-2015, 09:39
They can be CPU hogs if used incorrectly.
The Wait call inside each one throttles the loop down and avoids sucking the life out of the CPU. So never use a While loop without a Wait.

So that example works as long as you make sure to use Waits.

There are several alternative styles that avoid the use of loops altogether, but Waits are still required to get your timing down.
Here is one alternative using a Flat Sequence Structure: http://www.team358.org/files/programming/ControlSystem2015-2019/labview/index.php#Autonomous

Slade
06-03-2015, 09:50
They can be CPU hogs if used incorrectly.
The Wait call inside each one throttles the loop down and avoids sucking the life out of the CPU. So never use a While loop without a Wait.

So that example works as long as you make sure to use Waits.

There are several alternative styles that avoid the use of loops altogether, but Waits are still required to get your timing down.
Here is one alternative using a Flat Sequence Structure: http://www.team358.org/files/programming/ControlSystem2015-2019/labview/index.php#Autonomous

Well my question would be is what if your moving a motor and you want to stop it at a limit switch, how would you go about doing so without a while loop?

Mark McLeod
06-03-2015, 11:24
Loops are used/required a couple of places, such as Robot Main and Periodic Tasks.vi
User programs loop to keep working and checking for driver packets, changes of robot state (Disabled/Enabled/Teleop/Autonomous), etc.

If you have to check constantly to see if a limit switch is reached then a loop can be used (just always throttle it with a Wait). If the operation is commonly used both for Teleop and for Autonomous, then a loop in Periodic Tasks might be a better location for it.

Ether
06-03-2015, 11:25
Well my question would be is what if your moving a motor and you want to stop it at a limit switch, how would you go about doing so without a while loop?

Attach the limit switch to your motor controller. The motor controller firmware will stop the motor.

Slade
06-03-2015, 14:14
Attach the limit switch to your motor controller. The motor controller firmware will stop the motor.




How would you go about putting the limit switch to the motor controller. I'm not exactly sure what you mean

stopyourself
06-03-2015, 14:32
How would you go about putting the limit switch to the motor controller. I'm not exactly sure what you mean


I think...our limit switches are in DIO 6 and 7 on out bot. So instead plug it in to the motor controller? I think it would be on a breakout board like this for the Talon SRX: http://www.chiefdelphi.com/media/img/585/585b0d9203e2436ce205ccefee71979d_l.jpg

Kevin Phan
06-03-2015, 14:34
For the talon srx and jaguar you are able to use a limit switch and put embedded code to stop the motor when the limit switch is pressed. If you do not possess these motor controllers. You probably want to use a condition in your while loop to state that if the limit switch is pressed to stop the loop.

Ether
06-03-2015, 14:55
How would you go about putting the limit switch to the motor controller. I'm not exactly sure what you mean

Talon SRX User's Guide; see pages 19 & 20:
http://www.crosstheroadelectronics.com/Talon%20SRX%20User%27s%20Guide.pdf

Jaguar Getting Started Guide; see pages 7 9 10 13 14 22
http://team358.org/files/electrical/MDL-BDC24_GSG.pdf