View unanswered posts | View active topics It is currently Sat Dec 15, 2018 12:17 am






Reply to topic  [ 4 posts ] 
Joystick Program Lag 
Author Message
Rookie

Joined: Tue Mar 10, 2015 6:24 pm
Posts: 3
Post Joystick Program Lag
Hello Community,
I am a programmer for FTC team 6965 WRA, and I recently ran into a problem. I programmed a short wait for a servo (400 Msecs) on joy2btn, but the wait distributes through the whole program.I.e. When a joystick on joy1 is moved there is also a long pause. Is there any way to fix this?
Thanks


Tue Mar 10, 2015 6:44 pm
Profile
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 46
Location: Saint Paul, MN
Post Re: Joystick Program Lag
Yes, there are many ways to get around this. I am taking a guess that your code for the button is something analogous to this:
Code:
if(joy2Btn(1)){
   wait1Msec(400);
   servo[test] = 0;
}

This is generally bad within a teleop program especially. The wait1Msec() method forces the brain to stop at that line for 400 milliseconds, you can see this if you run the debug. So any code you want to be running simultaneously will never be reached. Luckily, the NXT has four built in timers that run constantly, T1, T2, T3, and T4. You can check if a timer has reached a certain value (or greater) without having to affect the rest of the code. Here is a simple implementation that you could try:

Code:
bool pressed = false;//This will be used to see if the button has been pressed

task main()
{

while(true){
   if(joy2Btn(1)){
      pressed = true;//Tells the program that the servo is allowed to move
      ClearTimer(T1);//sets the timer to 0
   }
   //Note that you can press button 1 again before 400 msec's have passed and reset the counter
   
   if(pressed && time1(T1) >= 400){//time1() returns the value of T1 in milliseconds
      servo[test] = 0;
      pressed = false;//reset pressed so it doesn't happen again
   }
   
   //Other driving code should behave normally
}
}

So, the timer T1 resets once we press the button and we store a "true" in the pressed boolean variable that allows the servo to move. I believe this should work as described (though I haven't tested it). In general, if you want some sort of timed interval it's best to try to use the timers instead of a wait function.

If this isn't the source of your problem, please post some of your code. It is much easier to figure what's wrong that way.

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Tue Mar 10, 2015 11:10 pm
Profile WWW
Rookie

Joined: Tue Mar 10, 2015 6:24 pm
Posts: 3
Post Re: Joystick Program Lag
Thanks very much. But I'll it work if I programmed it like this:
servo[Test]=100;
wait1Msec(400);


Sat Mar 14, 2015 6:48 am
Profile
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 46
Location: Saint Paul, MN
Post Re: Joystick Program Lag
I'm not sure I see the point of putting the timer after the servo positioning. Are you waiting for the servo to reach its destination? If so it's not hard to just stop pushing buttons. Or are you waiting until it gets to 100 in order to send it a new value?

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Sat Mar 14, 2015 12:38 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.