Skip to content

HardwareAndMethods

Kyle Hollars edited this page Feb 14, 2021 · 1 revision

The HardwareAndMethods class is the most important in our project. It contains all of the methods used to control the robot and to get sensor data. To use it, just create a new instance of HardwareAndMethods in your teleop:

    private HardwareAndMethods robot = new HardwareAndMethods();

We call ours robot in the wiki and in all of our OpModes

Variable Declarations

The variable declaration section does exactly what it says on the tin, it declares variables. We declare these variables at the beginning of the file that way the methods can access them later. Most of these define hardware variables. They are all set to null because we cannot yet set them to any piece of hardware (that happens in the init() method) but they must be declared outside of any method so that they can be accessed by any method.

List of Hardware variables:

You can add, remove, or rename any of the following variables, but for these are the components of our generic robot.

  • 4 Mecanum wheels
  • 1 Servo
  • One imu sensor
  • A forward and sideways encoder (see wiki)
  • A distance sensor
    //Motors
    DcMotor leftFront = null;
    DcMotor leftBack = null;
    DcMotor rightFront = null;
    DcMotor rightBack = null;
    public float speedMod = 1f; //The speed multiplier for the motors

    //Servos
    Servo servo1 = null;

    //Sensors
    DcMotor forwardEncoder = null;
    DcMotor sidewaysEncoder = null;

    BNO055IMU imu; //https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/overview
    BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();

    DistanceSensor distance = null;

    ColorSensor colorSensor = null;
    float hsvValuesSensor[] = {0F, 0F, 0F}; //Color sensor Hue Saturation Value;; one for each ColorSensor
    final double COLOR_SCALE_FACTOR = 255;

    HardwareMap hwMap = null;
    private ElapsedTime runtime = new ElapsedTime();

If you add or want to rename any hardware, you must declare the hardware variable/change the variable's name in this section

You may also see that there are a few non-hardware variables declared here. These variables are used to store sensor output, or modify the hardware in some way. TODO: create wiki pages about the various hardware and variables


Methods

Constructor

TODO: add information about constructor

init()

This function should always be placed in the init() function of an OpMode. This is where the variables declared earlier are given values. You must first give each hardware component names in the Robot Controller or Driver Controller apps (see: Configuring Robot TODO: create Configuring Robot)

mecanum()

The mecanum method is the main way that we control the robot's motion. It takes 3 float arguments, x, y, and r. As you might imagine, these variables determine the speed at which each of the 4 mecanum wheels should turn. Because DcMotors only take values between 1 and -1, we use Range.clip() to prevent any of the values passed to setPower() from being greater than 1 or less than -1. For more information on how mecanum wheels work, see FRC Seamonsters-2605's mecanum wheel simulator.

map()

This simple function takes an input value, a minimum & maximum input value, and a minimum & maximum output value, and returns an output value. This is useful for turning input data that falls into one range into output data that falls into another. It can also be used to convert between units of measurements. For example, in the Skystone competition we used this function to convert from ticks to a lift height.

Getter Methods

getImuAngle() TODO: what does it do?
getOdometryString() For telemetry purposes, returns a String "x: ___, y: ___" where the value after "x: " is the distance that the sideways encoder has traveled, in ticks, and the value after "y: " is the distance that the forward encoder has traveled.
getOdometryX() Returns an integer value of the distance the sideways encoder has traveled in ticks.
getOdometryY() Returns an integer value of the distance the forward encoder has traveled in ticks.
getWheelsAreBusy() Returns `true` if any of the wheels are turning, otherwise returns `false`

Clone this wiki locally