Go to Post Learn the subjects that interest you, but at the same time know how it relate to real life situations, and how it is applied. - Ryan Dognaux [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 02-01-2016, 11:51 AM
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,712
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Sub-Class CANTalon to represent 3 motors

Quote:
Originally Posted by wazateer1 View Post
Hi everybody,

This year our team is going with a 6-motor drive train, and our programming team came across the problem of RobotDrive only having two motor and four motor constructors. We only have a tank drive, but I personally like using RobotDrive because of the ease of switching between Tank drive and arcade drive. I saw an old post from 2010 mentioning adding a whole new constructor to the RobotDrive file itself, but I wanted to take a different approach.

Would there be anything wrong with writing our own sub-class of CANTalon (or any class that implemented SpeedController, we are just using CANTalons), whose constructor creates three instances of CANTalons, and overrides .set() by calling .set() on each of the Talons, then constructing RobotDrive with two objects of this class, one for each side of the drive train?

Code outline (not guaranteed to compile )

Code:
public class ThreeMotorGearbox extends CANTalon {
    public CANTalon talon1, talon2, talon3;

    public ThreeMotorGearbox(int talon1id, int talon2id, int talon3id) {
        super(talon1id); //We will be overriding all the important methods, anyway)
        talon1 = new CANTalon(talon1id);
        talon2 = new CANTalon(talon2id);
        talon3 = new CANTalon(talon3id);
    }

    @Override
    public void set(double speed) {
        talon1.set(speed);
        talon2.set(speed);
        talon3.set(speed);
    }
}

//Somewhere in the code
public ThreeMotorGearbox leftSide, rightSide;
public RobotDrive driveTrain;

leftSide = new ThreeMotorGearbox(1,2,3);
rightSide = new ThreeMotorGearbox(4,5,6);
driveTrain = new RobotDrive(leftSide, rightSide);
You'd probably be better just implementing the SpeedController class.

Edit: SpeedController

Last edited by notmattlythgoe : 02-01-2016 at 12:07 PM.
Reply With Quote
 


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:28 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