Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Timing Autonomous with While Loops? (http://www.chiefdelphi.com/forums/showthread.php?t=135512)

stopyourself 06-03-2015 08:54

Timing Autonomous with While Loops?
 
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

Re: Timing Autonomous with While Loops?
 
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/program...php#Autonomous

Slade 06-03-2015 09:50

Re: Timing Autonomous with While Loops?
 
Quote:

Originally Posted by Mark McLeod (Post 1454366)
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/program...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

Re: Timing Autonomous with While Loops?
 
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

Re: Timing Autonomous with While Loops?
 
Quote:

Originally Posted by Slade (Post 1454369)
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

Re: Timing Autonomous with While Loops?
 
Quote:

Originally Posted by Ether (Post 1454408)
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

Re: Timing Autonomous with While Loops?
 
Quote:

Originally Posted by Slade (Post 1454477)
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...ee71979d_l.jpg

Kevin Phan 06-03-2015 14:34

Re: Timing Autonomous with While Loops?
 
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

Re: Timing Autonomous with While Loops?
 
Quote:

Originally Posted by Slade (Post 1454477)
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.c...7s%20Guide.pdf

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




All times are GMT -5. The time now is 18:43.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi