View Single Post
  #3   Spotlight this post!  
Unread 04-02-2013, 04:27
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 : 04-02-2013 at 14:55.
Reply With Quote