![]() |
Extending the Talon Class and using with RobotDrive
We have a class that is an extension of the Talon class. It adds some functions such as current limiting.
As it extends the Talon class, which implements SpeedController, it would be reasoned that we should be able to pass our "Custom Talons" to other classes such as the RobotDrive class. Unfortunately, it seems that when passing out extension of Talon, robotDrive doesn't seem to call the overridden set function. For the sake of making our code easier to read we've put only the pertinent parts into a separate project and reproduced the bug there. Here is that code from an iterative robot project. Robot.java: Code:
public class Robot extends IterativeRobot {Code:
public class TestTalon extends TalonIs there something that we're missing about how java handles inheritance or is there something strange going on with the WPILibs? |
Re: Extending the Talon Class and using with RobotDrive
Quote:
That latter method has a second parameter to handle the CANJaguar "sync group" - when not using a sync group it's just set to 0; and since you're not extending CANJaguar you can safely ignore it. So, just override the set(double, int) method, rather than set(double), and it should work. Hope that helps! |
Re: Extending the Talon Class and using with RobotDrive
wow... We completely would not have noticed that, especially since that set method is considered deprecated in the Talon class.
So thanks an actual metric tonne, because it works now. |
Re: Extending the Talon Class and using with RobotDrive
Quote:
Just an uneducated question from a Java/Eclipse rookie. Tim |
Re: Extending the Talon Class and using with RobotDrive
Quote:
This allows the RobotDrive class to say "i want a speedcontroller but i dont care which one." very useful but it needs to be used carefully. This is where things get tricky for me, so if im wrong someone will need to correct me. The issue in this case is that jaguars have "syncgroups" and regular talons dont. However the speed controller interface defines the set method that uses syncgroups, so every class extending it now has to at least define it, whether or not it is actually something it uses or not. I mean, imagine if you passed a talon into the drive code, and it tried to use that set method, and it just wasnt there. So instead of rewriting everything that used motor controllers to make it choose whether or not to use sync groups based on what kind of controller it was, they left the original "set(speed,syncgroup)" method in for classes that didnt use syncgroups (such as the talon), and had it do the same thing that set(speed) did and ignore the syncgroup variable. Call it deprecated and be done with it. Drive code can still give the talons a syncgroup and you can just ignore the deprecated method when writing your own code. nothing is technically wrong. I feel that a better way to write this however would be to have the deprecated method simply call the new one and throw out the syncgroup, instead of copy pasting the code. This means that no matter what happens, both functions have to do the same thing for classes without syncgroups so extending either function works, otherwise you get confused teams. |
| All times are GMT -5. The time now is 07:25 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi