View Single Post
  #3   Spotlight this post!  
Unread 21-11-2011, 18:51
rudun's Avatar
rudun rudun is offline
Registered User
FRC #0496 (Royals)
Team Role: Coach
 
Join Date: Jan 2009
Rookie Year: 2005
Location: Babylon
Posts: 43
rudun is an unknown quantity at this point
Re: extending CANJaguar subclass

Thanks Ron. It now works, and even my math which is always a culprit in slowing me down was right. Here is what the whole thing is to anyone intrested in using the encoder on the Jaguar to calculate fps.

Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import edu.wpi.first.wpilibj.can.JaguarCANProtocol;


/**
 *
 * @author rudun, 1203
 */
public class FPS extends CANJaguar{

    final static double PI = Math.PI;
    private double WheelSize;
    
    public FPS(int id) throws CANTimeoutException {
        super(id);
   }
     /**
     * Get the speed of your robot.
     *
     * @return The speed of the robot in fps.
     */
    public double getFps() throws CANTimeoutException {
        byte[] dataBuffer = new byte[8];
        byte dataSize;
        double rpms;

        dataSize = getTransaction(JaguarCANProtocol.LM_API_STATUS_SPD, dataBuffer);
        if (dataSize == 4) {
            rpms = unpackFXP16_16(dataBuffer);
        } else {
            rpms = 0.0;
        }
        
        double fps = 0;
        fps = (rpms *(WheelSize * PI))/(60 * 12);
        return fps;
    }
    
    public void setWheelSize(double WheelSizeInInches) {
        WheelSize = WheelSizeInInches;
        }
}
Reply With Quote