I'm gonna laugh when the GDC numbers the first official game hint #3. - Racer26 [more]
 Chief Delphi > Java Using an encoder and a gyro to find absolute displacement
 CD-Media CD-Spy
 portal register members calendar search Today's Posts Mark Forums Read FAQ rules

#1
07-18-2018, 11:40 AM
 jakebacker44 Registered User FRC #4761 (Robockets) Team Role: Programmer Join Date: Sep 2016 Rookie Year: 2016 Location: Reading Posts: 4
Using an encoder and a gyro to find absolute displacement

I am working on a project that requires the robot's displacement from the starting position to be known. The only useful sensors that I have are two encoders, one on each side of the robot, and a gyro. My general idea so far is that the encoders can be used to measure how far the wheels have spun. This can only be used to find displacement when driving in a straight line. I think the gyro could be used to correct for the turning of the wheels. I can also take multiple measurements along the path if needed.

Thanks!
#2
07-18-2018, 12:06 PM
 iwilcove It's not the code AKA: Isaac Wilcove FRC #7308 (DeepVision) Team Role: Programmer Join Date: Jan 2018 Rookie Year: 2017 Location: California, USA Posts: 62
Re: Using an encoder and a gyro to find absolute displacement

What exactly is being asked here?
__________________
DV8
#3
07-18-2018, 12:39 PM
 WillNess ✋ FRC #4944 (The Hi Fives) Team Role: College Student Join Date: Apr 2014 Rookie Year: 2014 Location: United States Posts: 191
Re: Using an encoder and a gyro to find absolute displacement

Assuming you mean the robot's distance from the starting point, not the distance the robot has traveled, this would be my suggestion:

If you imagine the robot on a coordinate plane starting at (0,0) and facing 0 degrees, each tick of the code you could update the position using the distance traveled and the angle.

For example, if you track that you've moved 2 inches forward in the last tick while facing 0 degrees you could update your coordinates to (2,0) and update the angle. The next tick if you moved 3 inches forward but you were facing 15 degrees you'd take your current X and add 3*cos(15) and take your current Y and add 3*sin(15) and that'd be your new position in the coordinate plane. Then to take the distance traveled from the origin it'd simply be the Pythagorean theorem.
__________________

2018 FRC: SF @ Utah | QF @ Colorado | QF & Chairman's @ Idaho | Captain & Finalist @ Houston - Carver | IRI
2017 FRC: QF & Chairman's @ Utah | QF @ Houston - Hopper
2016 FRC: SF @ Utah | SF @ Colorado
2015 FRC: Creativity In Engineering & SF @ Arizona West
2014 FRC: Rookie Allstar & QF @ Utah | Rookie Allstar & Captain & QF @ Colorado
#4
07-18-2018, 12:59 PM
 Prateek M Kotlin Master Race FRC #5190 (Green Hope Falcons) Team Role: Programmer Join Date: May 2018 Rookie Year: 2018 Location: Cary, North Carolina Posts: 27
Re: Using an encoder and a gyro to find absolute displacement

This is a process that is used by many teams and is commonly referred to as "odometry" or "state estimation". You can basically calculate the distance traveled by the robot at a fixed interval by averaging your left and right encoders to get d. If your dt is small enough, you can assume the robot goes in straight lines and turns. Your gyro angle would then be your theta. Use vector addition from the initial pose to calculate your position on the field.

<d cos theta, d sin theta> + previous pose = current pose.

Some teams like 254 use differential geometry to represent the robot's movement as movement along an arc of constant curvature at each dt interval. More info can be found here: https://www.chiefdelphi.com/forums/s...6&postcount=15

Be mindful that this method of finding your position on the field is usually only accurate for the first 15 seconds or so. Wheel slip, encoder slip, and other factors will cause this approximation to deviate significantly after a while.
#5
07-22-2018, 11:17 PM
 retrodaredevil Registered User AKA: Josh Shannon FRC #1444 (Lightning 1444) Team Role: Programmer Join Date: Jul 2018 Rookie Year: 2018 Location: St. Louis Posts: 3
Re: Using an encoder and a gyro to find absolute displacement

Like Prateek said, to get the distance you just do
Code:
`(leftEncoder + rightEncoder) / 2`
And to make sure it stays straight, you can use the gyro and a very simple PID function like this:
Code:
```speed = 1 // 100%
turnAmount = (DESIRED_ANGLE - gyro) / -10 // in degrees // the PID part with P

leftSpeed = speed * (1 - (turnAmount < 0 ? -turnAmount : 0));
rightSpeed = speed * (1 - (turnAmount > 0 ?  turnAmount : 0));
// OR you can just do this:
leftSpeed = speed * (1 + min(turnAmount, 0));
rightSpeed = speed * (1 - max(turnAmount, 0));```
#6
07-26-2018, 04:31 PM
 gerthworm 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: 597
Re: Using an encoder and a gyro to find absolute displacement

Quote:
 Originally Posted by Prateek M Wheel slip, encoder slip, and other factors will cause this approximation to deviate significantly after a while.
Depending on how much slippage occurs, "a while" could be on the order of a few seconds. It does really depend.

I don't know of any team that builds control strategies around the assumption that they will know absolute position at any given time.

This isn't to say you shouldn't pursue how to get this answer - simply to make sure you level-set your expectations.

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum         FIRST E-Mail Blast Archive     Rumor Mill     Career     Robot Showcase Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         C/C++         Java         Python     Control System         FRC Control System         Sensors     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics     National Instruments LabVIEW and Data Acquisition         LabView and Data Acquisition Competition     Unsung FIRST Heroes     Awards         Chairman's Award     Rules/Strategy         Scouting         You Make The Call     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     District Events     Off-Season Events     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A         OCCRA Programming Other     Chit-Chat         Games/Trivia             Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         Western Region Robotics Forum         Southern California Regional Robotics Forum         The Blue Alliance             Video Archives     FIRST In the News...     FIRST Lego League         Lego Mindstorm Discussion     FIRST Tech Challenge     VEX         VEX Robotics Competition         VEX IQ     Televised Robotics     Math and Science         NASA Discussion ChiefDelphi.com Website     CD Forum Support     Extra Discussion

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

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

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Archive - Top