Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Robot won't drive. Help with "command based" programming (http://www.chiefdelphi.com/forums/showthread.php?t=133460)

Shaffer 24-01-2015 16:02

Robot won't drive. Help with "command based" programming
 
Here's our code, including our subsystem (cassie), our command (dothedrive), and our Robot file. It just won't drive no matter what we do. We have one joystick and mecanum drive.

public class cassie extends Subsystem
{

public SpeedController leftfront = RobotMap.cassieleftfront;
public SpeedController rightfront = RobotMap.cassierightfront;
public SpeedController leftrear = RobotMap.cassieleftrear;
public SpeedController rightrear = RobotMap.cassierightrear;
public RobotDrive wholecassie = RobotMap.cassiewholecassie;


public void initDefaultCommand()
{

}

public void takeJoyStickInput(Joystick joy1)
{
wholecassie.mecanumDrive_Cartesian(joy1.getRawAxis (1), joy1.getRawAxis(2), joy1.getRawAxis(0),0);

}

public void stop()
{
wholecassie.mecanumDrive_Cartesian(0, 0, 0,0);
}

}


public class dothedrive extends Command
{

public dothedrive()
{

requires(Robot.cassie);
}


protected void initialize()
{
}

protected void execute()
{
Robot.cassie.takeJoyStickInput(Robot.oi.getSidewin der());
}


protected boolean isFinished()
{
return false;
}

protected void end()
{
Robot.cassie.stop();

}


protected void interrupted()
{
}
}



public class Robot extends IterativeRobot
{

Command autonomousCommand;

public static OI oi;

public static cassie cassie;
public static lift lift;
public static grip grip;
public static vision vision;

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

cassie = new cassie();
lift = new lift();
grip = new grip();
vision = new vision();


oi = new OI();
autonomousCommand = new AutonomousCommand();
}

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();
wholecassie.dothedrive(); //this is the line that I'm confused on

}

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

Jalerre 24-01-2015 17:52

Re: Robot won't drive. Help with "command based" programming
 
I believed the line you are concerned about should be
Code:

Scheduler.getInstance().add(teleopCommand);
Substitute teleopCommand with the drive command that you want to run. That command should be instantiated in robotInit. Also the line should be in teleopInit.

Camilo86 24-01-2015 21:07

Re: Robot won't drive. Help with "command based" programming
 
If you were to make the command dothedrive the default command for the cassie subsystem, you wouldn't have to specifically call it in the Robot class as long as you have an object of the subsystem there. You can do this by adding this line inside your initDefaultCommand() inside your cassie subsystem

Code:

setDefaultCommand(new dothedrive());
It is best to add a default command inside your subsystem than calling all the commands from the Robot class

Shaffer 25-01-2015 13:32

Re: Robot won't drive. Help with "command based" programming
 
Thank you! I will try these solutions.


All times are GMT -5. The time now is 22:24.

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