Skip to content

Controller

deshi-dw edited this page Oct 8, 2019 · 1 revision

Controllers

Controllers are used to control one or more Components.

Controller Structure

IController
| void activate(Settings settings);
| void deactivate();
| void update();

update - Called once each periodic update and should be used for updating each component the controller uses.

activate - Called when the robot is first active. A Settings is used to supplied the controller with external settings. This method should be used to initialize all values in the controller.

deactivate - Called when the robot deactivates. This method should be used to stop any tasks that are running and run any deactivation procedures for that controller.

Defining a Controller

public class ArmController extends IController {
    public ArmController() { ... }
    
    public void activate(Settings settings) { ... }
    public void deactivate() { ... }
    public void update() { ... }
}

The controllers constructor method can be used to add components from the arguments. This is demonstrated in the "Using a Controller" section.

Using a Controller

public class ArmController extends IController {
    private Arm arm;
    private Xbox xbox;
    
    private double rotateSpeed = 1.0;
    
    public ArmController(Arm arm, Xbox xbox) {
        this.arm = arm;
        this.controller = controller;
    }
    
    public void activate(Settings settings) {
        rotateSpeed = Settings.get<Double>("ArmRotSpd");
    }
    public void deactivate() {
        arm.Stop();
    }
    
    public void update() {
        arm.rotate(xbox.Get(Xbox.Axis.RightX) * rotateSpeed);
    }
}

The ArmController doesn't need to have any extra methods besides the ones implemented by IController. If a method needs to be implemented, it should always be done through components and not controllers.

Clone this wiki locally