Go to Post The problem with random numbers is you never know. - GregT [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
  #1   Spotlight this post!  
Unread 03-23-2016, 10:24 PM
AlexanderTheOK AlexanderTheOK is offline
Guy
no team
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Los Angeles
Posts: 146
AlexanderTheOK is just really niceAlexanderTheOK is just really niceAlexanderTheOK is just really niceAlexanderTheOK is just really nice
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 {
    final String defaultAuto = "Default";
    final String customAuto = "My Auto";
    String autoSelected;
    SendableChooser chooser;
    
    TestTalon A = new TestTalon(2),
    		B = new TestTalon(3),
    		C = new TestTalon(0),
    		D = new TestTalon(1);
    
    RobotDrive drive = new RobotDrive(A,B,C,D);
    
    Joystick xbox = new Joystick(0);
	
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
        chooser = new SendableChooser();
        chooser.addDefault("Default Auto", defaultAuto);
        chooser.addObject("My Auto", customAuto);
        SmartDashboard.putData("Auto choices", chooser);
    }
    
	/**
	 * This autonomous (along with the chooser code above) shows how to select between different autonomous modes
	 * using the dashboard. The sendable chooser code works with the Java SmartDashboard. If you prefer the LabVIEW
	 * Dashboard, remove all of the chooser code and uncomment the getString line to get the auto name from the text box
	 * below the Gyro
	 *
	 * You can add additional auto modes by adding additional comparisons to the switch structure below with additional strings.
	 * If using the SendableChooser make sure to add them to the chooser code above as well.
	 */
    public void autonomousInit() {
    	autoSelected = (String) chooser.getSelected();
//		autoSelected = SmartDashboard.getString("Auto Selector", defaultAuto);
		System.out.println("Auto selected: " + autoSelected);
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
    	switch(autoSelected) {
    	case customAuto:
        //Put custom auto code here   
            break;
    	case defaultAuto:
    	default:
    	//Put default auto code here
            break;
    	}
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic()
    {
     double move = xbox.getRawAxis(1);
     double rotate = xbox.getRawAxis(4);
           
     drive.arcadeDrive(move, rotate);
     
    }
    
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
    
    }
    
}
TestTalon.java:

Code:
public class TestTalon extends Talon
{
	
	public TestTalon(int channel) {
		super(channel);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void set(double value)
	{
		System.out.println("TestTalon running");
		super.set(value);
		
	}
}
The idea here is that we should be seeing "TestTalon running" being printed to the riolog four times every loop of the function. Nothing is sent to the riolog, moreover, the robot continues to drive fine, indicating that it's running the Talon code but not the code from our extension.

Is there something that we're missing about how java handles inheritance or is there something strange going on with the WPILibs?

Last edited by AlexanderTheOK : 03-23-2016 at 10:26 PM. Reason: slightly more pertinent info.
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 07:25 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