|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
time delayed task
Hello,
Our robot has a button that when pressed gives full power to our shooting mechanism. We also have a belt that supplies the shooter with the balls. I have put together a function to run both the belt motor and the shooting motor when a button is pressed. However we need the belt to start 2 seconds after the shooting motor engages. I am having a major block here and can't figure out how to put a 2 second delay on a task after the button is pressed. I have looked all over and not found anything for the past few days. If anyone can offer any help or examples, it would be greatly appreciated. thank you |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Re: time delayed task
Thank you, that helps
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|