Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Program Delay (http://www.chiefdelphi.com/forums/showthread.php?t=82244)

Rikard023 02-09-2010 12:05 PM

Program Delay
 
In windriver is there a way to program a button to activate lets say a jaguar to turn on a motor for short time then hav the same button activate a piston a second later

Racer26 02-09-2010 01:18 PM

Re: Program Delay
 
There exists a way to program your robot to do pretty much anything. You have to define the conditions you want things to operate in. For instance:

You have Switch A, and Switch B.

If Switch A is on, then pressing Switch B causes action X to happen.
If Switch A is off, then pressing Switch B causes action Y to happen.

You can also cause a switch to perform one action, such as turning a motor on, then activate a timer, and when the timer expires, do something else.

Rikard023 02-09-2010 02:22 PM

Re: Program Delay
 
how would i make it activate the timer

Racer26 02-09-2010 03:49 PM

Re: Program Delay
 
You need to instantiate an object of the Timer class, and then call the Timer->Start(); function in your button code. Then in the routine that runs when the timer expires, you do something else.

Look up the WPILib Documentation on the Timer class.

slavik262 02-10-2010 09:25 AM

Re: Program Delay
 
Rikard, if I'm understanding your original post, you want to perform two actions with a single input, with the first action occurring immediately and the second occurring a second later. Instead using a timer (which would force you to continuoulsy check to see if a second has elapsed), you could use a Notifier class.

To use the Notifier class, you first create a function you want called after your elapsed time period (i.e. a function that would activate the piston in your case). The function takes a void pointer. You could use this by passing in a pointer to the solonoid you want to actuate, for example, and cast it back to a Solonoid pointer in the function.

Now to use the notifier class, when you construct it, give it the name of the function you want called as the TimerEventHandler argument and the pointer you want to pass to the function as the param argument. Then, when the user presses the button (or whatever your input is), call Notifier::StartSingle with the delay in seconds as the argument. In that amount of time, your function will automatically be called with the parameter you provided it.

I know this is kind of advanced programming, and if you're confused, feel free to PM me, but I think it would be the best way to do it. Unlike a timer, the Notifier class will automatically call your function in the specified amount of time without you having to worry about it any more.


All times are GMT -5. The time now is 10:37 AM.

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