Go to Post Life is too short to spend 40 hours a week doing something you are not enthusiastic about. - Karthik [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 01-02-2014, 15:01
SteveJ4564 SteveJ4564 is offline
Registered User
FRC #4564 (Orange Chaos)
Team Role: Mentor
 
Join Date: Feb 2014
Rookie Year: 2013
Location: Maine
Posts: 3
SteveJ4564 is an unknown quantity at this point
Hmm...How can I respond quicker to encoder input?

I've been searching the forums to get some insight into this problem, but haven't found a good solution yet.

We have a catapult system that is driven with a couple CIM motors, gearboxes, chains, and there's a rotary encoder on one of the gearboxes. Right now we have Jaguars driving this mechanism, with electronic braking enabled.

The concept is to apply full power to the catapult arm and accelerate the ball up until we reach a predetermined encoder count, which is the desired release point for the toss. A simple bit of Java code just watches the encoder and when the count has reached or exceeded the target count, set the motor speed to zero. By adjusting the target count, we can change the launch angle of the ball. Simple...

What we're finding is that the Java code is not running quick enough to keep up with the rapid arm movement. The control loop is running around 15ms, but at that rate the arm can move several degrees beyond the targeted stop before the code even notices it.

As a possible solution, I'm thinking of running a scheduled timer thread that does nothing more than watch the encoder count and stop the motors as appropriate. Would scheduling that to run once every millisecond be practical in the Java/cRIO environment?

Maybe there's a much smarter way to watch the encoder count and stop the motors. What other approaches might work?

Thanks for your thoughts.

Steve
  #2   Spotlight this post!  
Unread 01-02-2014, 23:48
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Hmm...How can I respond quicker to encoder input?

If you're running your loop in teleopPeriodic(), your latency will probably be closer to 20ms (that's the default period). However, making a higher-frequency loop with a TimerTask is definitely feasible. 1ms, I'm not sure of, but what I'd do is bring it down to 10ms, then 5ms, and see how the CPU usage is affected (you can check that with the DS Log Viewer). As long as you stay below ~80%, you should be fine. You could push it higher if you're certain there won't be any occasional peaks that take up that 20%.
__________________
I code stuff.
  #3   Spotlight this post!  
Unread 02-02-2014, 01:39
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Hmm...How can I respond quicker to encoder input?

The fastest you can change the PWM value going to the jaguar is 200hz.

Rather then doing everything in code, can you add a mechanical stop?
  #4   Spotlight this post!  
Unread 02-02-2014, 07:21
Jared's Avatar
Jared Jared is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2012
Location: Connecticut
Posts: 602
Jared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond repute
Re: Hmm...How can I respond quicker to encoder input?

Quote:
Originally Posted by Ginto8 View Post
If you're running your loop in teleopPeriodic(), your latency will probably be closer to 20ms (that's the default period). However, making a higher-frequency loop with a TimerTask is definitely feasible. 1ms, I'm not sure of, but what I'd do is bring it down to 10ms, then 5ms, and see how the CPU usage is affected (you can check that with the DS Log Viewer). As long as you stay below ~80%, you should be fine. You could push it higher if you're certain there won't be any occasional peaks that take up that 20%.
We used a TimerTask for our shooter control last year, and decreasing the loop time definitely made the shooter more responsive. As long as what's running isn't too complicated, you should be able to get the loop time down to 5 ms.

If you wanted to go even faster, you could make a new thread and call thread.yield(), so that it runs as fast as possible, without affecting your other threads.
  #5   Spotlight this post!  
Unread 02-02-2014, 08:33
SteveJ4564 SteveJ4564 is offline
Registered User
FRC #4564 (Orange Chaos)
Team Role: Mentor
 
Join Date: Feb 2014
Rookie Year: 2013
Location: Maine
Posts: 3
SteveJ4564 is an unknown quantity at this point
Re: Hmm...How can I respond quicker to encoder input?

Great feedback...thank you all.

I'll head down the TimerTask route. I might swap out the Jags for Victors, since the stated response time is quicker. As long as the response time is at a consistent rate, then we'll be able to consistently target a point to initiate a stop.

We will definitely have a physical stop, so the arm will not travel beyond design limits. Ideally, it will stop electronically, before it slams into the hard stop .
  #6   Spotlight this post!  
Unread 02-02-2014, 08:44
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Hmm...How can I respond quicker to encoder input?

Quote:
Originally Posted by SteveJ4564 View Post
I might swap out the Jags for Victors, since the stated response time is quicker.
According to what?
  #7   Spotlight this post!  
Unread 02-02-2014, 15:10
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Hmm...How can I respond quicker to encoder input?

Quote:
Originally Posted by Jared View Post
you could make a new thread and call thread.yield(), so that it runs as fast as possible, without affecting your other threads.
Out of curiosity, does anyone know what the context switching overhead is for each of the 3 FRC supported languages?


  #8   Spotlight this post!  
Unread 02-02-2014, 17:10
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Hmm...How can I respond quicker to encoder input?

Context switching speed is practically irrelevant for LabVIEW, as the language is parallel by nature. I can't think of a good reason for running something in a separate thread.
  #9   Spotlight this post!  
Unread 02-02-2014, 17:22
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Hmm...How can I respond quicker to encoder input?

If I'm not mistaken, you also have the problem that the motor controllers don't have too high of a refresh rate (for what you want to do). I think you may find it better to do a mechanical stop to give the code some time to refresh.
You can move the stop with some window motors because they have a high torque and are worm-gear powered
  #10   Spotlight this post!  
Unread 02-02-2014, 17:27
cmwilson13's Avatar
cmwilson13 cmwilson13 is offline
Registered User
AKA: Christopher Wilson
FRC #1771 (N. G. R.)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: buford GA
Posts: 89
cmwilson13 has a spectacular aura aboutcmwilson13 has a spectacular aura aboutcmwilson13 has a spectacular aura about
Re: Hmm...How can I respond quicker to encoder input?

use can for the jaguars and use the on board position control on the jaguars
__________________
"Like the WWF, but for smart people." -George HW Bush

Team Member 1771 2008-2009
Team Mentor 1771 2010-2012 2014- Future
Team Mentor 4509 2013-2014
Team Mentor 3998 2013-2014
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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