Go to Post What no one knows is that I’m actually wearing fishnet stockings under this gown… as soon as they finish taking all of these darn photos I’m going to show Dave and Amanda who really has the best legs in FIRST!!! - MissInformation [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 20-11-2011, 16:06
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
extending CANJaguar subclass

I am trying to add methods to help with reading our robots actual speed off of a CANJaguar in fps. The issue I am having now is that it is not building becasue it needs a constructor, but if I am inheriting the class shouldn't they already exist. What i want to be able to do is when i call a CANJaguar object, e.g. leftMotor.getFps(), it will return the fps data to me. This is my code so far.

Any help is greatly appreciated.

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
 */
public class fps extends CANJaguar {

    final static double PI = Math.PI;
    private double WheelSize;
     /**
     * 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;
        }
}
and this is my current compiler output

Code:
init:
clean:
init:
clean:
Created dir: C:\Users\kyle\Documents\NetBeansProjects\fpstest\build
Compiling 2 source files to C:\Users\kyle\Documents\NetBeansProjects\fpstest\build
C:\Users\kyle\Documents\NetBeansProjects\fpstest\src\edu\wpi\first\wpilibj\fps.java:13: error: no suitable constructor found for CANJaguar()
public class fps extends CANJaguar {
    constructor CANJaguar.CANJaguar(int,ControlMode) is not applicable
      (actual and formal argument lists differ in length)
    constructor CANJaguar.CANJaguar(int) is not applicable
      (actual and formal argument lists differ in length)
1 error
C:\Users\kyle\sunspotfrcsdk\ant\compile.xml:48: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 8 seconds)
Reply With Quote
  #2   Spotlight this post!  
Unread 20-11-2011, 21:15
rrossbach rrossbach is offline
Registered User
AKA: Ron R
FRC #2607 (RoboVikings)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Warrington PA
Posts: 90
rrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to behold
Re: extending CANJaguar subclass

Quote:
Originally Posted by rudun View Post
The issue I am having now is that it is not building becasue it needs a constructor, but if I am inheriting the class shouldn't they already exist.
In this case you need to explicitly define at least one constructor for your subclass (fps).

Why? Because if you don't specify a constructor in a subclass, Java makes a default one for you that doesn't take any arguments. But that default no-argument constructor expects to call the no-argument constructor for all of the superclasses (CANJaguar in your case). CANJaguar doesn't have a no-argument constructor, only the two constructors CANJaguar(int, ControlMode) and CANJaguar(int). That's what the compiler error message is telling you - that CANJaguar has "no suitable constructor" for a default no-argument subclass constructor to call.

So you need to do something like this:

Code:
public class fps extends CANJaguar {
   
   public fps(int id) throws Exception {
         super(id);
   }

...
}
Hope that helps!

- Ron
Team #2607 controls mentor
__________________

FIRST Mid-Atlantic Volunteer
FRC Team #2607 Mentor
Reply With Quote
  #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
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 22:17.

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