Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Running Commands (http://www.chiefdelphi.com/forums/showthread.php?t=134444)

antonyebert 12-02-2015 17:20

Running Commands
 
Okay so, I pretty much have my entire program done (except for the autonomous), and tried to test it out on our robot. I got everything hooked up, all the lights were on on the robot, and the driver station was giving me the go ahead. Once I hit enable though, nothing happens. I'm thinking there's a problem with my program, namely in making all of the code I wrote actually run.

In the Robot.java class (the one that has all of the Scheduler.getinstance.run() lines), do I need to run my commands for teleop and autonomous there? Or do I just leave it as is? And, if I do need to run my commands from there, how do I go about doing that? (I know how to call and run a method from an alternate class, but not the entire alternate class itself)


package org.usfirst.frc4993.Mater;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

import org.usfirst.frc4993.Mater.commands.*;
import org.usfirst.frc4993.Mater.subsystems.*;


public class Robot extends IterativeRobot

Command autonomousCommand;

public static OI oi;

public static DriveTrain driveTrain;
public static Arms arms;




public void robotInit() {
RobotMap.init();

driveTrain = new DriveTrain();
arms = new Arms();

oi = new OI();

autonomousCommand = new AutonomousDrive();
autonomousCommand = new AutonoumousLift();

}

public void disabledInit(){

}

public void disabledPeriodic() {
Scheduler.getInstance().run();
}

public void autonomousInit() {
if (autonomousCommand != null) autonomousCommand.start();
}

public void autonomousPeriodic() {
Scheduler.getInstance().run();
}

public void teleopInit() {
if (autonomousCommand != null) autonomousCommand.cancel();
}

public void teleopPeriodic() {
Scheduler.getInstance().run();
}

public void testPeriodic() {
LiveWindow.run();
}
}

cstelter 12-02-2015 17:58

Re: Running Commands
 
Quote:

Originally Posted by antonyebert (Post 1442781)
Okay so, I pretty much have my entire program done (except for the autonomous), and tried to test it out on our robot. I got everything hooked up, all the lights were on on the robot, and the driver station was giving me the go ahead. Once I hit enable though, nothing happens. I'm thinking there's a problem with my program, namely in making all of the code I wrote actually run.

In the Robot.java class (the one that has all of the Scheduler.getinstance.run() lines), do I need to run my commands for teleop and autonomous there? Or do I just leave it as is? And, if I do need to run my commands from there, how do I go about doing that? (I know how to call and run a method from an alternate class, but not the entire alternate class itself)

from the looks of your code, if you select Autonomous and enable, it should run your AutonomousLift command only.

If nothing is happening also in Teleop when you enable, you likely don't have a default command for your drivetrain subsystem. I'm presuming DriveTrain extends Subsystem. If so, you can add something like this:

Code:

public class DriveTrain extends Subsystem {
        ...

        public void initDefaultCommand() {
            setDefaultCommand(new DriveWithJoystick());
        }
        ...
}

That presumes you have a command like DriveWithJoystick that you by default want to control your DriveTrain. Be sure that both DriveWithJoystick or equivalent has requires(driveTrain) as well as AutonomousDrive(). Scheduler has to interrupt the default command to schedule AutonomousDrive().


See notes in red below that I have injected into your code:

Code:

package org.usfirst.frc4993.Mater;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

import org.usfirst.frc4993.Mater.commands.*;
import org.usfirst.frc4993.Mater.subsystems.*;


public class Robot extends IterativeRobot

    Command autonomousCommand;

    public static OI oi;
 
    public static DriveTrain driveTrain;
    public static Arms arms;

    //  I think this is what you were going for below in RobotInit
    private class AutonomousSequence extends CommandGroup {
        public AutonomousSequence() {
            addSequential(new AutonomousDrive());
            addSequential(new AutonomousLift());
        }
    }

   
  public void robotInit() {
    RobotMap.init();
     
        driveTrain = new DriveTrain();
        arms = new Arms();

        oi = new OI();
       
      autonomousCommand = new AutonomousDrive();
      //WARNING-- Next Line will forget about AutonomousDrive and
        //reassign autonomousCommand to be a new instance of AutonomousLift,
        //causing autonomous to run *only* AutonomousLift()

      autonomousCommand = new AutonoumousLift();
      //I suspect you want to create a new thing like the CommandGroup above
        //But instead of a private class in Robot,
        //        it should be a public class in its own AutonomousSequence.java file
        // Then the following line can replace the above to assignments

      autonomousCommand = new AutonomousSequence();

        //Then again, perhaps you couldn't make AutonomousDrive()
        //work so you intentionally reassigned AutonomousLift.  I'm doing a lot of guesswork here.

    }

    public void disabledInit(){

    }

    public void disabledPeriodic() {
        Scheduler.getInstance().run();
    }

    public void autonomousInit() {
        if (autonomousCommand != null) autonomousCommand.start();
    }

    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

    public void teleopInit() {
        if (autonomousCommand != null) autonomousCommand.cancel();
    }

    public void teleopPeriodic() {
        Scheduler.getInstance().run();
    }

    public void testPeriodic() {
        LiveWindow.run();
    }
}

If you can upload your code to github or bitbucket, then we can assist better with less guesswork.

antonyebert 13-02-2015 16:41

Re: Running Commands
 
Thank you for the help! I'll look into posting my code on github or bitbucket for further help after making the changes you recommended.

antonyebert 14-02-2015 01:02

Re: Running Commands
 
So, I have my entire program uploaded onto GitHub here:
https://github.com/KenzieShay/FRC-2015/tree/SideBranch

After fixing the errors that Craig pointed out, I finally got the robot to respond to the Drive Station, but it was only reacting to one joystick instead of the two of them. The wheels would both go (although it opposite directions :confused: ) when I moved the one joystick, but nothing would happen when I moved the other. I tried switching the order of the joysticks around in the driver station usb port tab, and the same thing happened, but with the joystick that was previously useless (so pretty much which ever joystick is in the 0 order of the drive station works).

I tried to fix that, and now all I get are error messages from the drive station. I feel like there is most likely a simple answer, but I'm so inexperienced, I'll probably never figure it out in time. :ahh:


All times are GMT -5. The time now is 11:45.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi