-
Notifications
You must be signed in to change notification settings - Fork 3
Home
The core package strives to deliver structure and power to your team's robot code.
Robots are divided into three sections- a base, a component, and a command.
The RobotBase class is designed as a template for your own base class. To create your own base:
public class MyBase extends RobotBase
{
// Add more if needed
MyComponent component = new MyComponent();
@Override
public void init(HardwareMap HW)
{
hardware = HW; // It is critical that you write this!
// Initialize more if you have more
component.init(this);
}
}The base serves as a single object that you can pass in OpModes. It also serves as a central object in hardware mapping.
The RobotComponent class is designed to control the functionality of a single component of your robot(drivetrain, shooter, etc.). To create your own component:
public class MyComponent extends RobotComponent
{
// Standard hardware declarations go here
@Overrid
public void init(final RobotBase BASE)
{
super.init(BASE);
// Hardware map here
}
// Component functionality goes here
}The RobotCommand class serves as a wrapper for commands that wish to be executed on a separate thread or need the flexibility to be executed on either the main thread or a separate thread. To create a command:
class MyCommand extends RobotCommand
{
private boolean _stop = false;
// MUST be overwritten!
@Override
public void runSequentially()
{
// Command Actions
}
// May be not overwritten- if not overwritten, will execute runSequentially() on a separate thread.
@Override
public void runParallel()
{
if(t == null)
{
_stop = false;
t = new Thread(new Runnable()
{
@Override
public void run()
{
// Command Actions
}
}
t.start();
}
}
// MUST be overwritten!
@Override public void stop()
{
_stop = true;
}
}The HardwareMapper class serves to make hardware mapping easy, organized, and readable. To use:
public class MyComponent extends RobotComponent
{
DcMotor motor;
@Override void init(final RobotBase BASE)
{
super.init(BASE);
motor = mapper.mapMotor("motor" , DcMotorSimple.Direction.FORWARD);
}
}Note: we use LinearOpMode as opposed to OpMode
@TeleOp(name = "My TeleOp" , group = "Tests")
public class OpMyTeleOp extends LinearOpMode
{
private MyBase _base = new MyBase();
@Override
public void runOpMode() throws InterruptedException
{
_base.init(hardwareMap);
waitForStart();
while(opModeIsActive())
{
// Run components
}
}
}