Thread: Java help
View Single Post
  #2   Spotlight this post!  
Unread 16-10-2016, 13:42
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: 297
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: Java help

WPILib resources:
Screensteps
API Reference (Java)
API Reference (C++)

Using the command based architecture, you need to first create a subsystem that the motor belongs to
Code:
public class MyMotorSubsystem extends Subsystem {
  CANSomething myMotor;
  public MyMotorSubsystem {
    myMotor = new CANSomething(RobotMap.CAN_ID_MY_MOTOR);
  }
  public void setMotor(double value) {
    myMotor.set(value);
  }
}
Then you need a command to run the motor.
Code:
public class CommandBase extends Command {
  public static MyMotorSubsystem myMotorSubsystem;
  public static void init() {
    myMotorSubsystem = new MyMotorSubsystem();
  }
}

public class RunMotorCommand extends CommandBase {
  JoystickButton runMotorButton;
  public RunMotorCommand(JoystickButton runMotorButton) {
    this.runMotorButton = runMotorButton;
    runMotorButton.whenPressed(this);
  }
  void initialize() {
    requires(myMotorSubsystem);
  }
  void run() {
    myMotorSubsystem->setMotor(1.0);
  }
  void isFinished() {
    return runMotorButton.get();
  }
  void end() {
    myMotorSubsystem->setMotor(0.0);
  }
  void interrupted() {
    myMotorSubsystem->setMotor(0.0);
  }
}
Then you need to create an instance of the command
Code:
// somewhere in OI.java
new RunMotorCommand(new JoystickButton(myJoystick, something));
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote