View Single Post
  Spotlight this post!  
Unread 19-02-2012, 08:22
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: time delayed task

Probably the easiest way is to call this function every time through teleop to update the state. In the function you use a shift register, feedback node, or even a global variable to remember the state of your device.

Your states are -- "off", "starting up", and "shooting". You can also remember things such as when you started applying power.

Each call to the loop you can look at the desired state and the actual state and do things to the motors and the state variables.

For example, let's say that you call the function with the button pressed and the device state is "off". Your function will set the shooter motor speed to 1.0, change the state variable to "starting up", and note that time t0 was when the motors were powered up.

On subsequent calls, you will see that the button is still pressed and the state is "starting up", so you will check to see if two seconds have elapsed since t0. If not, there is nothing to do.

On a call when the button is still down, the state is "spinning up", and two or more seconds have elapsed, you can update the other motor and set the state to "shooting".

If the function is called and the button is up, you update the motor speeds to zero and change the state to "off" and perhaps remember when you turned them off. You don't really need this info, but if you want to speed up subsequent shots, you may not need to wait a full two seconds if the last show was a half second ago.

This SW technique is called a state machine and it is used all the time. You may be able to find examples of it, or you can post more questions if you do not.

Greg McKaskle
Reply With Quote