Go to Post wonder if the April peak for 'frisbee launcher' was from the GDC... - cbudrecki [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 01-02-2016, 11:49
wazateer1 wazateer1 is offline
Registered User
FRC #3506 (YETI Robotics)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2013
Location: Charlotte, NC
Posts: 30
wazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to behold
Sub-Class CANTalon to represent 3 motors

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);
Reply With Quote
  #2   Spotlight this post!  
Unread 01-02-2016, 11:51
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,715
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 : 01-02-2016 at 12:07.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-02-2016, 11:52
lethc's Avatar
lethc lethc is offline
#gkccurse
AKA: Becker Lethcoe
FRC #1806 (S.W.A.T.)
Team Role: Alumni
 
Join Date: Nov 2012
Rookie Year: 2013
Location: Smithville, MO
Posts: 119
lethc will become famous soon enough
Quote:
Originally Posted by notmattlythgoe View Post
You'd probably be better just extending the MotorController class.
Why?
__________________
2016: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Semifinalists, IRI Quarterfinalists
2015: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Quarterfinalists, IRI Winners
2014: Central Illinois Regional Quarterfinalists, Greater Kansas City Regional Finalists, Newton Semifinalists
2013: Greater Kansas City Regional Winners, Oklahoma Regional Winners, Galileo Quarterfinalists
Reply With Quote
  #4   Spotlight this post!  
Unread 01-02-2016, 12:07
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,715
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 lethc View Post
Why?
The SpeedController is the base interface for all of the motor controllers. This way you know you are implementing all of the stuff that needs implemented. Really it should just be calling the same method that you're implementing for each of the CANTalons.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-02-2016, 12:20
wazateer1 wazateer1 is offline
Registered User
FRC #3506 (YETI Robotics)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2013
Location: Charlotte, NC
Posts: 30
wazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to behold
Re: Sub-Class CANTalon to represent 3 motors

Quote:
Originally Posted by lethc View Post
Why?
I thought the same at first (when I started writing this), and figured I could use super for most of the functions I needed. But I realized as I was writing this that each function that will get called and actually DOES anything needs to be @Overrid and pointed to all three Talons. Unless there is a function in CANTalon that simply IDENTIFIES the CANTalons, that doesn't DO anything that needs to be overridden (eg public String getType() {return "CANTalon"}, it would be simpler. He has a point, there is no reason TO implement CANTalons unless there is said identifying function


Quote:
Originally Posted by notmattlythgoe View Post
The SpeedController is the base interface for all of the motor controllers. This way you know you are implementing all of the stuff that needs implemented. Really it should just be calling the same method that you're implementing for each of the CANTalons.
CANTalon does implement SpeedController, by extending it my class inherits all the functions, plus the way CANTalons identify themselves

Ultimately, it comes to not having to call the super constructor, and I will go with notmattlythgoe that directly implementing SpeedController is better
Reply With Quote
  #6   Spotlight this post!  
Unread 01-02-2016, 12:57
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liason
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 82
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Sub-Class CANTalon to represent 3 motors

If anyone is looking to group together multiple motors under a single Motor object (i.e. three drivetrain motors under one object like OP's code), I'd like to point to a library of 1902's that has a class called MotorGroup. It works like so:

Code:
MotorGroup leftDrive = new MotorGroup(CANTalon.class, 0, 1, 2);
leftDrive.setPower(1);

MotorGroup rightDrive = new MotorGroup(new CANTalon(3), new CANTalon(4));
rightDrive.setPower(-0.5);
MotorGroup is very flexible because it takes any type of Motor and can contain as many motors as you want, so it should help eliminate having to make awkward wrapper classes or mass-call SpeedController.set().

The link to the source file (and the rest of the repo) can be found here.

To get completely back on-topic and to answer the original question, that wrapper class should work fine. My only suggestion would be to not extend CANTalon.

Disclaimer: MotorGroup relies on other parts of the library to exist, so it does not work as-is without changing it not use BCNLib classes.
__________________


2016 Roles: Manipulator, Strategy Co-Lead, Programmer
2016 Orlando Regional: Quarterfinalist (Captain w/ 1557, 5557 and 4352)
2016 Rocket City Regional: Quarterfinalist (w/ 283 and 34), Regional Chairman's Award Winner
2016 Championship: N/A (had fun and was inspired, that's what counts)
-------------
2015 Role: Programmer
2015 GSCR: Quarterfinalist (w/ 4189 and 4026), Regional Chairman's Award Winner
2015 Orlando Regional: Semifinalist (w/ 456 and 86), Imagery Award Winner
2015 Championship: Pit Safety Award Winner

Last edited by Oromus : 01-02-2016 at 13:03.
Reply With Quote
  #7   Spotlight this post!  
Unread 01-02-2016, 13:03
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 322
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Sub-Class CANTalon to represent 3 motors

CanTalons have a Follower mode, where set() takes the CAN ID of a talon to constantly copy speed from. That way, you only need to pass 2 "master" talons to RobotDrive and have the rest copy those.
Reply With Quote
  #8   Spotlight this post!  
Unread 01-02-2016, 13:23
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 521
ozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant future
Re: Sub-Class CANTalon to represent 3 motors

Quote:
Originally Posted by euhlmann View Post
CanTalons have a Follower mode, where set() takes the CAN ID of a talon to constantly copy speed from. That way, you only need to pass 2 "master" talons to RobotDrive and have the rest copy those.
+1. Check out section 16.33 in talon srx software reference manual.
http://www.ctr-electronics.com/talon...ical_resources
Reply With Quote
  #9   Spotlight this post!  
Unread 01-02-2016, 13:23
wazateer1 wazateer1 is offline
Registered User
FRC #3506 (YETI Robotics)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2013
Location: Charlotte, NC
Posts: 30
wazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to behold
Re: Sub-Class CANTalon to represent 3 motors

Quote:
Originally Posted by Oromus View Post
If anyone is looking to group together multiple motors under a single Motor object (i.e. three drivetrain motors under one object like OP's code), I'd like to point to a library of 1902's that has a class called MotorGroup. It works like so:

Code:
MotorGroup leftDrive = new MotorGroup(CANTalon.class, 0, 1, 2);
leftDrive.setPower(1);

MotorGroup rightDrive = new MotorGroup(new CANTalon(3), new CANTalon(4));
rightDrive.setPower(-0.5);
MotorGroup is very flexible because it takes any type of Motor and can contain as many motors as you want, so it should help eliminate having to make awkward wrapper classes or mass-call SpeedController.set().

The link to the source file (and the rest of the repo) can be found here.

To get completely back on-topic and to answer the original question, that wrapper class should work fine. My only suggestion would be to not extend CANTalon.

Disclaimer: MotorGroup relies on other parts of the library to exist, so it does not work as-is without changing it not use BCNLib classes.
The only problem with that is RobotDrive does not know to call .setPower, it only every calls .set() assuming any class that implements SpeedController uses that method
Reply With Quote
  #10   Spotlight this post!  
Unread 01-02-2016, 13:25
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liason
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 82
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Sub-Class CANTalon to represent 3 motors

Quote:
Originally Posted by wazateer1 View Post
The only problem with that is RobotDrive does not know to call .setPower, it only every calls .set() assuming any class that implements SpeedController uses that method
Yup, that's because MotorGroup is part of an overall wrapper/utility library that effectively creates it's own, better versions of WPILib's classes. To get MotorGroup to work with WPI's RobotDrive, you just make it implement SpeedController instead of extending Motor and rename a few functions.
__________________


2016 Roles: Manipulator, Strategy Co-Lead, Programmer
2016 Orlando Regional: Quarterfinalist (Captain w/ 1557, 5557 and 4352)
2016 Rocket City Regional: Quarterfinalist (w/ 283 and 34), Regional Chairman's Award Winner
2016 Championship: N/A (had fun and was inspired, that's what counts)
-------------
2015 Role: Programmer
2015 GSCR: Quarterfinalist (w/ 4189 and 4026), Regional Chairman's Award Winner
2015 Orlando Regional: Semifinalist (w/ 456 and 86), Imagery Award Winner
2015 Championship: Pit Safety Award Winner
Reply With Quote
  #11   Spotlight this post!  
Unread 01-02-2016, 13:26
wazateer1 wazateer1 is offline
Registered User
FRC #3506 (YETI Robotics)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2013
Location: Charlotte, NC
Posts: 30
wazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to behold
Re: Sub-Class CANTalon to represent 3 motors

Quote:
Originally Posted by euhlmann View Post
CanTalons have a Follower mode, where set() takes the CAN ID of a talon to constantly copy speed from. That way, you only need to pass 2 "master" talons to RobotDrive and have the rest copy those.
Would that be more "reliable" then setting them all in code?

Last edited by wazateer1 : 01-02-2016 at 13:48.
Reply With Quote
  #12   Spotlight this post!  
Unread 01-02-2016, 14:13
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 521
ozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant future
Re: Sub-Class CANTalon to represent 3 motors

The slave/follower features of the Talon SRX are reliable. Many teams were successful using this feature last season. You can read more about it in the Talon SRX Software Reference manual.

Check out section 16.33 for a specific example of a solution to your OP.
http://www.ctr-electronics.com/talon...ical_resources
Reply With Quote
  #13   Spotlight this post!  
Unread 01-02-2016, 15:32
wazateer1 wazateer1 is offline
Registered User
FRC #3506 (YETI Robotics)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2013
Location: Charlotte, NC
Posts: 30
wazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to behold
Thanks all!
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 10:52.

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