Go to Post They really should put warning signs at all entrances: "WARNING! FIRST IS CONTAGIOUS!" - KenWittlief [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 02-03-2013, 11:31 PM
l0stboy l0stboy is offline
Registered User
FRC #4064 (InZombiacs)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: United States
Posts: 22
l0stboy is an unknown quantity at this point
Encoder Guidance Needed

Hello, my team is planning on using encoders, specifically the ones that were in FIRST Choice. I've looked though all the Java threads on them, but I can't make sense of how the Encoder class really works.

My team plans on using the encoder to move to desired set positions in autonomous and to prevent from going too fast.

For instance, I really don't know how the getDistancePerPulse() and how to use the other methods accordingly to get distance calculations. Samples code on setting up an encoder would be awesome!
__________________

Pedro
Ocala InZombiacs
Reply With Quote
  #2   Spotlight this post!  
Unread 02-03-2013, 11:42 PM
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Thumbs down Re: Encoder Guidance Needed

Quote:
Originally Posted by l0stboy View Post
Hello, my team is planning on using encoders, specifically the ones that were in FIRST Choice. I've looked though all the Java threads on them, but I can't make sense of how the Encoder class really works.

My team plans on using the encoder to move to desired set positions in autonomous and to prevent from going too fast.

For instance, I really don't know how the getDistancePerPulse() and how to use the other methods accordingly to get distance calculations. Samples code on setting up an encoder would be awesome!
Encoders work by detecting little sprockets on a wheel inside the encoder usually using optic sensors or anything along those lines. The encoders you have 360 of these bumps or sprockets meaning that every revolution of the shaft the encoder is mounted on, the encoder pulses 360 times. Using the libraries provided you can set the distance per pulse. Therefore by calculating how far, say your robot drives per revolution of the output shaft your encoder is mounted on, you can get how far your robot has travelled and how fast its moving.
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me

Last edited by Team3266Spencer : 02-03-2013 at 11:44 PM.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-04-2013, 04:27 AM
NotInControl NotInControl is offline
Controls Engineer
AKA: Kevin
FRC #2168 (Aluminum Falcons)
Team Role: Engineer
 
Join Date: Oct 2011
Rookie Year: 2004
Location: Groton, CT
Posts: 261
NotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond repute
Re: Encoder Guidance Needed

Quote:
Originally Posted by l0stboy View Post
Samples code on setting up an encoder would be awesome!
Here is some sample code on calculating distance per pulse and setting up an encoder. You would just need to place them in the proper locations of your code.

The code should be self explanatory, but if you have any questions, reply back.

Code:
        //DIO Port of Encoder
	public static final int rightDriveEncoderChannelA = 3;
	public static final int rightDriveEncoderChannelB = 4;


	//Wheel Radius
	public static final int driveWheelRadius=2;//wheel radius in inches
	public static final int pulsePerRotation = 360; //encoder pulse per rotation
	public static final double gearRatio = 1/1; //ratio between wheel and encoder
	public static final double driveEncoderPulsePerRot= pulsePerRotation*gearRatio; //pulse per rotation * gear ratio
	public static final double driveEncoderDistPerTick=(Math.PI*2*driveWheelRadius)/driveEncoderPulsePerRot;
	public static final int driveEncoderMinRate=10; 
	public static final int driveEncoderMinPeriod=10;
        public static final boolean rightDriveTrainEncoderReverse=false;



	//declare sensors
	Encoder rightEncoder;

         //instantiate encoder
        rightEncoder = new Encoder(rightDriveEncoderChannelA, rightDriveEncoderChannelB, rightDriveTrainEncoderReverse, CounterBase.EncodingType.k4X);
    	rightEncoder.setDistancePerPulse(driveEencoderDistPerTick);
    	rightEncoder.setMaxPeriod(driveEncoderMinPeriod);//min period before reported stopped
    	rightEncoder.setMinRate(driveEncoderMinRate);//min rate before reported stopped
    	rightEncoder.start();

Hope this helps,
Kev
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2016 Season] - World Championship Controls Award, District Controls Award, 3rd BlueBanner
-World Championship- #45 seed in Quals, World Championship Innovation in Controls Award - Curie
-NE Championship- #26 seed in Quals, winner(195,125,2168)
[2015 Season] - NE Championship Controls Award, 2nd Blue Banner
-NE Championship- #26 seed in Quals, NE Championship Innovation in Controls Award
-MA District Event- #17 seed in Quals, Winner(2168,3718,3146)
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - WPI Regional Winner - 1st Blue Banner

Last edited by NotInControl : 02-04-2013 at 02:55 PM.
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 07:47 AM.

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