Go to Post We are reluctant to deprive you of the experience of learning how to do your own research. - Alan Anderson [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 31-10-2016, 15:23
beijing_strbow beijing_strbow is offline
Registered User
FRC #5968 (Cyborg Indians)
Team Role: Programmer
 
Join Date: Aug 2016
Rookie Year: 2016
Location: Kansas
Posts: 36
beijing_strbow is an unknown quantity at this point
Gyro vs. Encoders for Driving Straight

At the moment, our algorithm for driving straight doesn't work too well. We just start at a set speed and increment the left and right speeds by a small amount based on encoder readings. We get about 3-5 inches drift on an 80 inch drive, which isn't good enough (like this year, to drive to a position to shoot).

We're looking at implementing PID with either the encoders or the navX MXP, so which works better? I would think the gyro would be better, as there isn't drift from wheel slipping, and it also seems simpler to implement, but I read on a different thread that encoders are really the right sensor to use.

Additionally, is it worth doing a PID control with both encoders and gyro and averaging the outputs? Would that improve accuracy enough that it would be worth implementing?
Reply With Quote
  #2   Spotlight this post!  
Unread 31-10-2016, 17:01
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 431
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Gyro vs. Encoders for Driving Straight

Simplest place to start is to perform your moves as a series of straight driving or turns in place.

Use the gyros heading to rotate to a speficoed angle, then use your encoders to drive set distances in straight lines.

All you have to develop are two commands/methods.
One that drives straight some arbitrary distance. And another that rotates to some arbitrary heading. Develop both of these and time them independently. Once they both get you to your destination position/heading within your acceptable error, you can create command groups that combine driving straight and rotating in the right order to perform more complex actions.

Your drive straight command/method should use the encoder ticks to determine distance traveled, did you go as far as needed. The gyro will be used to control to the heading the robot was at when the drive straight command begun. If heading slips off zero (or whatever it was at the begging of the move) adjust the relative speed of each side of the drivetrains to get back to zero.

You should be able to get both of these working pretty well with a simple proportional controller.
__________________
http://team2168.org

Last edited by otherguy : 31-10-2016 at 17:06.
Reply With Quote
  #3   Spotlight this post!  
Unread 31-10-2016, 17:15
gerthworm's Avatar
gerthworm gerthworm is offline
Making the 1's and 0's
FRC #1736 (Robot Casserole)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Peoria, IL
Posts: 68
gerthworm has a spectacular aura aboutgerthworm has a spectacular aura about
Re: Gyro vs. Encoders for Driving Straight

Gyro for keeping straight.

As to autonomous stuff, seems like more and more teams are going to a path-planner solution. Before autonomous starts, a set of x/y coordinate waypoints are fed into the algorithm. An output is generated that indicates varying desired velocities for each side of the drivetrain over the time duration of the path traversal.

In this case, each side of the drivetrain has an encoder feeding a PID to control the actual wheel velocity to the desired velocity (from the path-planner). To augment this, a gyro may be used to provide a "correction factor", which reduces error from wheel scrub or going over rough defenses.

Net result in 2016 was a ~50% accurate high-goal autonomous routine under the low bar. Not as good as some of the really slick vision systems, but we're still pretty proud of it...
Reply With Quote
  #4   Spotlight this post!  
Unread 31-10-2016, 17:22
Classified*'s Avatar
Classified* Classified* is offline
Work smarter, not harder
AKA: Julia Cecchetti
FRC #0291 (CIA: Creativity in Action)
Team Role: Leadership
 
Join Date: Nov 2015
Rookie Year: 2015
Location: Erie PA
Posts: 32
Classified* is on a distinguished road
Re: Gyro vs. Encoders for Driving Straight

I can't say much about using gyros to stay straight, I know we tried to use them before, but there was too much drift to be useful, However I was not personally involved in that so I'm not sure.

On the other hand, we have had a lot of success with encoders and PID. We used them all through the season with great success. Wheel slip was definitely not a problem (we had treads this year) even on slippery tile flooring our robot had no problems. We had a major problem with our treads being misaligned. After lots of hard driver practice on our practice bot this became a problem. The robot would drift to one side even though both encoders were reading the same value because of the bent tread.

Also, if you do end up using encoders, it is very important to make sure the slop in both gearboxes is forward, especially if your encoders aren't on the output shaft (they should never be anywhere else).

If you would like our encoder PID code, I have it in both Java and Labview, and I would be happy to share.

On another note, are you trying to shoot a high goal using just encoders? I wouldn't recommend this, the goal is very small for that. It is best to use vision tracking to find the retro reflective tape on the goals. If you use Labview I can help you with this. If you don't have vision, Going for a low goal auto is a better bet. Better to get 5 points most of the time than get 10 some of the time and lose the ball the rest of the time. Encoders are more than adequate for a low goal auto.

I hope this helps
Reply With Quote
  #5   Spotlight this post!  
Unread 31-10-2016, 18:02
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,532
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Gyro vs. Encoders for Driving Straight

I think you are traveling the wrong route - so to speak. 3 inches of drift left to right really isn't bad. The reality of driving with an FRC robot is that when you add up the drivetrain backlash, bumps, slips, and other mechanical losses you will never drive perfectly straight.

That's why vision, or sensors of some type are a necessity. It's the law of diminishing returns. You can spend weeks, or months working to get your robot to drive perfectly straight. But when you build your 2017 robot you will face a whole new set of challenges getting it perfect. Or you can spend that same time learning to utilize the vision examples so that when you hit a bump, or wall, or when you start using your new robot for 2017 you'll be able to hit a shot every time.

If you still want to continue optimizing driving straight, gerthworm nailed it.

The addition of a P term to each side of your drivetrain utilizing the gyro will get you darn close to perfect.

P is the proportional, or error term. It's calculated like this:

Proportional_Term = Constant * (Desired_Gyro_Angle - Actual_Gyro_Angle)
Left_Drive = Left_Drive + Proportional_Term
Right_Drive = Right_Drive - Proportional_Term


You may need to swap the +/- in the calculation depending on your drivetrain direction. Simply increase the constant term until you start driving straight. Start very small - like .05 or .1 for your Constant.

This is the most basic form of PID driving straight.

Edit: On another note, try not to saturate your drivetrain. That means try not to send it a full +1 or -1. There are a number of ways to scale the output so that you can still maintain straight driving at full speed.

Last edited by Tom Line : 31-10-2016 at 18:04.
Reply With Quote
  #6   Spotlight this post!  
Unread 31-10-2016, 18:14
beijing_strbow beijing_strbow is offline
Registered User
FRC #5968 (Cyborg Indians)
Team Role: Programmer
 
Join Date: Aug 2016
Rookie Year: 2016
Location: Kansas
Posts: 36
beijing_strbow is an unknown quantity at this point
Re: Gyro vs. Encoders for Driving Straight

Thanks for the responses! Seems the general idea is that using encoders and gyro is best.

Quote:
Originally Posted by Classified* View Post
On another note, are you trying to shoot a high goal using just encoders?
We did try to do camera vision (didn't end up finishing it though). That was just an example to say that we would like higher accuracy.

Quote:
Originally Posted by Classified* View Post
If you would like our encoder PID code, I have it in both Java and Labview, and I would be happy to share.
That Java example would be great, if you don't mind!
Reply With Quote
  #7   Spotlight this post!  
Unread 31-10-2016, 19:16
Classified*'s Avatar
Classified* Classified* is offline
Work smarter, not harder
AKA: Julia Cecchetti
FRC #0291 (CIA: Creativity in Action)
Team Role: Leadership
 
Join Date: Nov 2015
Rookie Year: 2015
Location: Erie PA
Posts: 32
Classified* is on a distinguished road
Re: Gyro vs. Encoders for Driving Straight

Quote:
Originally Posted by beijing_strbow View Post
That Java example would be great, if you don't mind!
I sent you a pm with the code
Reply With Quote
  #8   Spotlight this post!  
Unread 31-10-2016, 20:11
bankst's Avatar
bankst bankst is offline
Registered User
FRC #0832 (OSCAR)
Team Role: Mentor
 
Join Date: Feb 2016
Rookie Year: 2012
Location: Roswell, GA
Posts: 9
bankst is an unknown quantity at this point
Re: Gyro vs. Encoders for Driving Straight

Quote:
Originally Posted by Classified* View Post
I sent you a pm with the code
Can you send it to me as well? Thanks a lot!
__________________
2012-Present 832 Oscar (Alumni and Mentor)
Oscar's Website: http://oscarrobotics.meshnet0.com
Reply With Quote
  #9   Spotlight this post!  
Unread 01-11-2016, 08:14
adciv adciv is offline
One Eyed Man
FRC #0836 (RoboBees)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Southern Maryland
Posts: 478
adciv is a name known to alladciv is a name known to alladciv is a name known to alladciv is a name known to alladciv is a name known to alladciv is a name known to all
Re: Gyro vs. Encoders for Driving Straight

Use encoders for distance, use gyro for driving straight. With a properly tuned PID and a good gyro, you'll be off by at most 1/2" over 30 ft. Once we redid our autonomous for champs, we didn't need our camera half the time to score.

That said, with a shooter you want a camera for locking onto the target. Typically you're going to slide laterally during some situations (such as crossing a defense) and only a camera will allow for correction to that error. There's default image processing code in the FRC install every year, I'd recommend looking at it. The roboRIO is powerful enough to process 320x240 @10 fps.
__________________
Quote:
Originally Posted by texarkana View Post
I would not want the task of devising a system that 50,000 very smart people try to outwit.

Last edited by adciv : 01-11-2016 at 08:17.
Reply With Quote
  #10   Spotlight this post!  
Unread 01-11-2016, 09:12
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,067
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Gyro vs. Encoders for Driving Straight

Quote:
Originally Posted by adciv View Post
Use encoders for distance, use gyro for driving straight. With a properly tuned PID and a good gyro, you'll be off by at most 1/2" over 30 ft. Once we redid our autonomous for champs, we didn't need our camera half the time to score.
This. The NavX functions as a great gyro with very little drift, highly recommend it.

Quote:
The roboRIO is powerful enough to process 320x240 @10 fps.
Yep. That's what we used.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #11   Spotlight this post!  
Unread 01-11-2016, 16:18
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,532
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Gyro vs. Encoders for Driving Straight

Depending on what you want to do, it may be a mistake to process a camera stream real-time.

If you have a turret that aims while you are driving, it makes sense to process a video stream. You can be aiming all the time, so that when you stop you don't have to move very much.

If you're using the drivetrain, however, it's a much less costly proposition in terms of CPU if you stop, take a picture, then calculate how much you need to turn. Once you've completed your turn you can do another picture to verify you are aimed correctly, or do the loop again and turn a bit more.

Very few applications in FRC require real-time video processing at any appreciable frame rate. Unless you are 254.
Reply With Quote
  #12   Spotlight this post!  
Unread 01-11-2016, 16:49
xjschwen xjschwen is offline
Registered User
FRC #3668
 
Join Date: Jan 2016
Location: Michigan
Posts: 20
xjschwen is an unknown quantity at this point
Re: Gyro vs. Encoders for Driving Straight

Quote:
Originally Posted by Tom Line View Post
I think you are traveling the wrong route - so to speak. 3 inches of drift left to right really isn't bad. The reality of driving with an FRC robot is that when you add up the drivetrain backlash, bumps, slips, and other mechanical losses you will never drive perfectly straight.

That's why vision, or sensors of some type are a necessity. It's the law of diminishing returns. You can spend weeks, or months working to get your robot to drive perfectly straight. But when you build your 2017 robot you will face a whole new set of challenges getting it perfect. Or you can spend that same time learning to utilize the vision examples so that when you hit a bump, or wall, or when you start using your new robot for 2017 you'll be able to hit a shot every time.

If you still want to continue optimizing driving straight, gerthworm nailed it.

The addition of a P term to each side of your drivetrain utilizing the gyro will get you darn close to perfect.

P is the proportional, or error term. It's calculated like this:

Proportional_Term = Constant * (Desired_Gyro_Angle - Actual_Gyro_Angle)
Left_Drive = Left_Drive + Proportional_Term
Right_Drive = Right_Drive - Proportional_Term


You may need to swap the +/- in the calculation depending on your drivetrain direction. Simply increase the constant term until you start driving straight. Start very small - like .05 or .1 for your Constant.

This is the most basic form of PID driving straight.

Edit: On another note, try not to saturate your drivetrain. That means try not to send it a full +1 or -1. There are a number of ways to scale the output so that you can still maintain straight driving at full speed.
we used this approach and were good enough to cross the ramparts, rock wall, moat, and terrain and still score a low goal about 50% of the time. We were always close to scoring as long as we did not run into another bot.
Reply With Quote
  #13   Spotlight this post!  
Unread 02-11-2016, 02:00
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 803
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Gyro vs. Encoders for Driving Straight

Quote:
Originally Posted by gerthworm View Post
As to autonomous stuff, seems like more and more teams are going to a path-planner solution. Before autonomous starts, a set of x/y coordinate waypoints are fed into the algorithm. An output is generated that indicates varying desired velocities for each side of the drivetrain over the time duration of the path traversal.
There are a couple teams doing this (and yours may be one of them), but I'd like to emphasize that you don't need a path planner (and all the complexity that comes with one) to do really cool autonomous modes. 971's autonomous modes do not have a planner involved, and they are plenty complicated. We have trapezoidal motion profiles in distance and theta hand tuned, and that's enough to do some pretty neat stuff.

There are places where a real planner with feedback would do better than simple profiles, but you don't *need* them in FRC.

Quote:
Originally Posted by gerthworm View Post
In this case, each side of the drivetrain has an encoder feeding a PID to control the actual wheel velocity to the desired velocity (from the path-planner). To augment this, a gyro may be used to provide a "correction factor", which reduces error from wheel scrub or going over rough defenses.

Net result in 2016 was a ~50% accurate high-goal autonomous routine under the low bar. Not as good as some of the really slick vision systems, but we're still pretty proud of it...
Nice!

Until we had vision working, we scored 5+ 1 ball under the low goal autonomous modes with 100% reliability at Davis with motion profiles in theta and distance, good control loops, and very careful alignment. It's all about staying away from traction limits and designing nice control loops which track well. We use a gyro for heading and encoders for distance, which works great.

Keep it as simple as possible while still achieving your goals. (I didn't mean to pick on you in particular, and we are definitely a team which pushes the limits, but I want to emphasize KISS. It's better to shoot lower and succeed than bite off too much. Especially given the level I'm reading the OP to be at.)
Reply With Quote
  #14   Spotlight this post!  
Unread 02-11-2016, 08:27
Xanawatt Xanawatt is offline
Registered User
FRC #1024
 
Join Date: May 2015
Location: Indianapolis, Indiana
Posts: 24
Xanawatt is an unknown quantity at this point
Re: Gyro vs. Encoders for Driving Straight

Quote:
Originally Posted by Classified* View Post
I sent you a pm with the code
Me too?
Reply With Quote
  #15   Spotlight this post!  
Unread 02-11-2016, 12:22
inorbert inorbert is offline
Build Captain and Driver
FRC #5811 (BONDS)
Team Role: Driver
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Ohio
Posts: 29
inorbert is an unknown quantity at this point
Did anyone use the KoP gyro from Analog Devices for driving straight successfully this season? What did your setup look like? Could you send a link to the library you used, or just send your code?

Sent from my LG-D851 using Tapatalk
__________________
Reply With Quote
Reply


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 18:02.

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