![]() |
Custom RobotDrive
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){ } } |
Re: Custom RobotDrive
The easiest way to to this would be to remove the need for RobotDrive, and just copy the methods you need from that class to your custom class.
|
Re: Custom RobotDrive
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); } } |
Re: Custom RobotDrive
Quote:
|
Re: Custom RobotDrive
Quote:
http://docs.oracle.com/javase/tutori...ndI/super.html |
Re: Custom RobotDrive
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.
|
Re: Custom RobotDrive
Quote:
Using the PWM class is the least simple way to control your robot drive base. Joe |
Re: Custom RobotDrive
Quote:
|
Re: Custom RobotDrive
Quote:
|
Re: Custom RobotDrive
Quote:
|
| All times are GMT -5. The time now is 11:22. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi