OCCRA
Go to Post I'm gonna laugh when the GDC numbers the first official game hint #3. - Racer26 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 07-18-2018, 11:40 AM
jakebacker44 jakebacker44 is offline
Registered User
FRC #4761 (Robockets)
Team Role: Programmer
 
Join Date: Sep 2016
Rookie Year: 2016
Location: Reading
Posts: 4
jakebacker44 is an unknown quantity at this point
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!
Reply With Quote
  #2   Spotlight this post!  
Unread 07-18-2018, 12:06 PM
iwilcove's Avatar
iwilcove iwilcove is offline
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
iwilcove is on a distinguished road
Re: Using an encoder and a gyro to find absolute displacement

What exactly is being asked here?
__________________
DV8
Reply With Quote
  #3   Spotlight this post!  
Unread 07-18-2018, 12:39 PM
WillNess's Avatar
WillNess WillNess is offline
FRC #4944 (The Hi Fives)
Team Role: College Student
 
Join Date: Apr 2014
Rookie Year: 2014
Location: United States
Posts: 191
WillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant futureWillNess has a brilliant future
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
Reply With Quote
  #4   Spotlight this post!  
Unread 07-18-2018, 12:59 PM
Prateek M's Avatar
Prateek M Prateek M is online now
Kotlin Master Race
FRC #5190 (Green Hope Falcons)
Team Role: Programmer
 
Join Date: May 2018
Rookie Year: 2018
Location: Cary, North Carolina
Posts: 27
Prateek M is on a distinguished road
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 07-22-2018, 11:17 PM
retrodaredevil retrodaredevil is offline
Registered User
AKA: Josh Shannon
FRC #1444 (Lightning 1444)
Team Role: Programmer
 
Join Date: Jul 2018
Rookie Year: 2018
Location: St. Louis
Posts: 3
retrodaredevil is an unknown quantity at this point
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));
Reply With Quote
  #6   Spotlight this post!  
Unread 07-26-2018, 04:31 PM
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: 597
gerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond repute
Re: Using an encoder and a gyro to find absolute displacement

Quote:
Originally Posted by Prateek M View Post
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.
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 10:31 AM.

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


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