Hi CD, I was wondering how to make a new class that implements the obejcts and methods from the RobotDrive. Right now all the code, which runs works fine, is all in one file. Which is not very neat so I am trying to create seperate classes for everything such as the arm ,etc. Since we used mecanum we had to invert the motors and set the pwm channels and everything which took up a lot of space, so, I want to make something like this: (just as an example)
DriveTrainMecanum DriveSystem = new DriveTrainMecanum(1,2,3,4);
In which DriveTrainMecanum implements all the methods and objects from RobotDrive but it also does the inverting of the motors and everything else. This is what i have so far but its saying “no suitable constructor” :S How do i fix this:
This is what i have written so far:
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.SimpleRobot;
public class DriveTrain extends RobotDrive {
//This is going to be set by the user but iam just making it for now
Jaguar frontLeft = new Jaguar(1);
Jaguar frontRight = new Jaguar(2);
Jaguar rearLeft = new Jaguar(3);
Jaguar rearRight = new Jaguar(4);
public DriveTrainMecanum(int cone, int ctwo, int cthree, int cfour){
}
When subclassing you need to call a super constructor with the proper arguments. This has a few impacts. First of all, in your constructor, you need to call super(cone, ctwo, cthree, cfour). You should also not need your own instance variables to keep track of those jaguars, since RobotDrive already does.
If my train of thought was a little confusing let me know. Here is how I would modify the code.
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.SimpleRobot;
public class DriveTrain extends RobotDrive {
public DriveTrainMecanum(int cone, int ctwo, int cthree, int cfour){
super(cone, ctwo, cthree, cfour);
}
Personally, I always just deal with the PWM class. I don’t even bother with anything higher level than that. It just simplifies things by writing everything from scratch.
If that were simpler, there would not be any other classes on top of it. It’s bad form to make your project more complicated for other team members and call it “simpler”. If you want to increase the amount you code you write, simply admit your desire to your team and others who may be reading this. Please don’t mislead others with claims like this.
Using the PWM class is the least simple way to control your robot drive base.
I think what he meant was that when you write it all yourself you assure yourself it works exactly as you need it to. You have the greatest understanding of your code.