Performing an operation for a set amount of time
Shane from United States  [10 posts]
12 year

I am using a servo motor to pull the trigger of a paintball gun. So that I don't waste too many paintballs I want to pull the trigger for a set amount of time. What would be the best way to have the servo move to a position, for say 1.5 seconds and have it move back? I know there is a script_count variable that has proved useful in the past and I've been looking at the image_time variable as well, but I can't find a good solution that will ensure I consistently pull the trigger for a specific amount of time.  Suggestions would be very much appreciated.

Anonymous 12 year

Have a look at the usage for

SetTimedVariable "test", 0, 1500

within a VBScript module (or CScript, Python, etc).

The trick is that you much only call this function ONCE as each time it is used it will reset the timing (in this case 1.5 sec) to 1.5 sec from the time it is called. Thus using a state variable can be helpful in this case.

if GetVariable("joystick_fire") = 1 then
  if GetVariable("firing") = 0 then
    SetVariable "firing", 1
    SetTimedVariable "firing", 0, 1500
  end if
end if

The above assumes joystick_fire is specified in one of the joystick button variables and will not set firing more than once to 1. When firing is 1 the servo should move (you could use the actual servo value if you want) and will be set back to 0 (or perhaps 128) after 1.5 seconds.

Hope this helps.
Shane from United States  [10 posts] 12 year
Thank you STeven, this helps a lot. I forgot about the setTimedVariable function and I think this will solve my problem. I will play around with it to make sure.
Shane from United States  [10 posts] 12 year

Just a follow up to my question. I think that this may help someone out. I did end up solving my problem using the setTimedVariable() function. Thank you for the suggestion. I've posted the RoboRealm file that will toggle a value(in this case a servo to pull a trigger of a paintball gun) for specific amounts of time. By changing the period values, PERIOD_1 and PERIOD_2, in the code you can toggle a servo to different positions for any length of time in milliseconds. I have it set up right now to fire for 1 second and NOT fire for 2 seconds, to have the servo in the closed position and open open respectively.

Hope this helps someone,
Shane from United States  [10 posts] 12 year
The last sentence should open *position*
Shane from United States  [10 posts] 12 year
Wow, Sorry!

Just realized i forgot to post the file.

Here it is.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index