Go to Post "We don't build the robots, we build the robot builders." - [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-19-2016, 12:19 PM
bensen19r bensen19r is offline
Registered User
FRC #4125
 
Join Date: Feb 2016
Location: Oregon
Posts: 4
bensen19r is an unknown quantity at this point
Post Encoders

Hello, I would like to know how to do various things with encoders. If you would be so kind as to help, I would very much appreciate it!
Here are the things that I must learn to do.

1.) Get the encoders to work
2.) Be able to use them for autonomous and to go a set amount of distance per rotation

Thank You so much for your help!
Reply With Quote
  #2   Spotlight this post!  
Unread 02-19-2016, 02:22 PM
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 102
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Encoders

The first step is to wire up your encoders and make sure that you can access the information they provide in your code.

The following code snippet provides an example of how to construct an quadrature Encoder object and register it with the LiveWindow system. Once your robot program is compiled and deployed, you should then be able to select Test mode instead of Teleop on the driver station and see the values being reported by the encoder.

You will need to adjust the DIO port constants to match where you plugged in your encoder cables.

The following assumes that you have a two channel (quadrature encoder) that has two PWM cables that you plugged into DIO ports on the roboRIO (you did not specify much information about your robot - so this was a guess).

NOTE: I don't have access to a robot to try out this sample code below, so you may need to make some adjustments.

Code:
    // The digital I/O ports you plug your cables into on the roboRIO
    // IMPORTANT: You MUST CHANGE these values to match the digital input
    // ports you plugged your encoder into on the robotRIO!
    private static final int DIO_LEFT_ENCODER_A_CHAN = 0;
    private static final int DIO_LEFT_ENCODER_B_CHAN = 1;
    
    // Once you are able to see counts, you can push your robot
    // a fixed distance and enter the distance you pushed it below
    // and the number of counts your encoder reported for the distance
    private double DIST_MEASURED = 1.0;
    private double COUNTS_MEASURED = 1.0;
    
    // Computes the distance per count value for the encoder from
    // the measure values
    private double DIST_PER_COUNT = DIST_MEASURED / COUNTS_MEASURED;
    
    // Encoder attached to the left side motors
    Encoder leftDriveEncoder;
    
    public void robotInit() {

    	// Construct a new instance of the encoder for left side of drive
    	leftDriveEncoder = new Encoder(DIO_LEFT_ENCODER_A_CHAN, DIO_LEFT_ENCODER_B_CHAN);
    	leftDriveEncoder.setDistancePerPulse(DIST_PER_COUNT);

    	// Add it to LiveWindow monitoring for "Test" mode viewing
    	LiveWindow.addSensor("Drive", "Left Encoder", leftDriveEncoder);


       // Rest of your robotInit() code
    }
Hope that helps get you started enough that you can move on to the next step of driving a fixed distance.
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 08:59 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