How to Program the RoboRio - MDHSRobotics/TeamWiki GitHub Wiki

Home / Tutorials

How to Program the RoboRio

Set up Development Environment

In order to be able to program a RoboRio, you need a development workstation with appropriate tools. We are currently using Java as the programming language for the robot. Tools you will need are listed in the FRC documentation.

Java basics

Check out the information on the FRC Java Programming page. They provide good information on Java Basics, understanding the Robot base class and how to get started.

Create Season Specific Project

Each season will require a unique fit to purpose robot. A project must be created for each season. Instead of starting from scratch, a base project, MaterBot, was created that encapsulate common tasks, adds additional features and improves configuration and logging.

Design Robot Subsystems

First, review [Control System Contepts](Control System Contepts). A robot will have a number of actuators, motors and sensors needed to achieve the objectives of the mission. These are organized in subsystems. A robot typically has 1 drive subsystem. A robot can have additional subsystems based on robot needs. For example, a robot could have an arm subsystem and lift subsystem. For each subsystem, determine the following:

  • motors & servos needed by the subsystem
  • actuators, e.g. pneumatic linear actuator, needed by the subsystem
  • sensors, e.g. contact switches, distance sensors, etc., used by the subsystem
  • settings needed by the subsystem, e.g. limits, thresholds, gain settings, etc.

Create a document in the project created for the robot detailing the subsystems needed for the robot.

Implement Robot

To implement your robot, you will likely have to implement custom subsystems and commands specific to your purpose.

Implementing a custom Subsystem

To implement a custom subsystem, create a class that extends MDSubsystem. Below is an example:

public class CoreSubsystem extends MDSubsystem {

	public CoreSubsystem(MDRobotBase robot, String name) {
		super(robot, name);
		setCore(true);
	}

	@Override
	protected void initDefaultCommand() {
	}

	@Override
	protected void setUp() {
		if(getConfigSettings().containsKey("name")){
			getRobot().setName(getConfigSettings().get("name").getString());
		}
		if(getConfigSettings().containsKey("autoCommand")){
			getRobot().setAutoCommand(getConfigSettings().get("autoCommand").getString());
		}
	}

	@Override
	public void settingChangeListener(ConfigSetting changedSetting) {
		if(getConfigSettings()!=null && getConfigSettings().containsKey("autoCommand")){
			getRobot().setAutoCommand(getConfigSettings().get("autoCommand").getString());
		}	
		if(getConfigSettings()!=null && getConfigSettings().containsKey("name")){
			getRobot().setName(getConfigSettings().get("name").getString());
		}	
	}
}

After your class is implemented, add it to the robot and configure it in the configure() method of the Robot class.

		add( new CoreSubsystem(this, "core")
				 .add("name",new StringConfigSetting("MaterBot"))
				 .add("autoCommand",new StringConfigSetting("AutonomousCommand1"))
				 .configure()
		);

Implementing a custom Command

To implement a custom command create a class that extends MDCommand. Below is an example:

public class MDPrintCommand extends MDCommand {
	
	
	private String message;

	public MDPrintCommand(MDRobotBase robot, String name, String message) {
		super(robot,name);
		this.setMessage(message);
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	} 
	
	@Override
	protected void execute() {
		super.execute();
		log("execute", message);
	}

}

After your Command class is implemented, add it to the robot. For example, in the case where a command is to be called from a joystick button, configure it in the configureOI() method of the OI class:

		add(new MDJoystick(getRobot(), "joystick1", 0)
			.whenPressed("A",3,new MDPrintCommand(getRobot(),"A Command","A Command message"))
			.whileHeld("leftBumper",6,new MDPrintCommand(getRobot(),"Left Bumper Command","Left Bumper Command message"))
			.configure()
		);

see [Understanding MaterBot](Understanding MaterBot) for more information about MaterBot and how to configure a robot.