Class Sensor

java.lang.Object
me.autobot.lib.robot.Device
me.autobot.lib.robot.Sensor
All Implemented Interfaces:
Logger
Direct Known Subclasses:
CollisionSensor

public class Sensor extends Device
A device that's used to sense the environment around the robot.
  • Constructor Details

    • Sensor

      public Sensor(int identifier, int sensorChannels)
      Creates a new sensor with the given address and number of sensor channels.
      Parameters:
      identifier - The identifier of the sensor. Could be any number, should be unique to all other sensors on the robot.
      sensorChannels - The number of output channels the sensor has.
  • Method Details

    • getSensor

      public static Sensor getSensor(int identifier, int robotAddr)
      Gets the sensor object with the specific identifier and robot address.
      Parameters:
      identifier - The identifier of the sensor.
      robotAddr - The address of the robot.
      Returns:
      The sensor object with the specific identifier and robot address.
    • connectToI2C

      public void connectToI2C(int address, int bus, int pin)
      Connects the sensor to the I2C bus.
      Parameters:
      pin - The pin to connect the sensor to.
      address - The address of the sensor.
      bus - The bus to connect the sensor to.
    • connectToSerial

      public void connectToSerial(String port)
      Connects the sensor via Serial
      Parameters:
      port - The port to connect to.
    • changeUpdateInterval

      protected void changeUpdateInterval(long interval)
      Changes the update interval of the sensor for the subscribers.
      Parameters:
      interval - The new update interval of the sensor subscribers.
    • getSensorValues

      public double[] getSensorValues()
      Returns the raw sensor values.
      Returns:
      The raw sensor values.
    • getValues

      public double[] getValues()
      Returns the processed sensor values.
      Returns:
      The processed sensor values.
    • getAddress

      public int getAddress()
      Returns the I2C address of the sensor hub.
      Returns:
      The I2C address of the sensor hub.
    • getBus

      public int getBus()
      Returns the I2C bus of the sensor hub.
      Returns:
      The I2C bus of the sensor hub.
    • getIdentifier

      public int getIdentifier()
      Returns the identifier of the sensor.
      Returns:
      The identifier of the sensor.
    • simulateValues

      public void simulateValues(double[] values)
      Plugs in fake sensor values for simulation.
      Parameters:
      values - The values to simulate.
    • getRelativePosition

      public Vector3d getRelativePosition()
      Gets the relative position to the center of the robot.
      Returns:
      The relative position to the center of the robot.
    • getRelativeRotation

      public Rotation3d getRelativeRotation()
      Gets the relative rotation to the center of the robot.
      Returns:
      The relative rotation to the center of the robot.
    • attachRelativePosition

      public void attachRelativePosition(Vector3d relativePosition)
      Attaches the relative position of the sensor to the center of the robot.
      Parameters:
      relativePosition - The relative position of the sensor to the center of the robot.
    • attachRelativePosition

      public void attachRelativePosition(Vector3d relativePosition, Rotation3d relativeRotation)
      Attaches the relative position and rotation of the sensor to the center of the robot.
      Parameters:
      relativePosition - The relative position of the sensor to the center of the robot.
      relativeRotation - The relative rotation of the sensor to the center of the robot.
    • setSensorValues

      protected void setSensorValues(double... values)
      Set the sensor values.
      Parameters:
      values - The values to set the sensor to.
    • setSensorValue

      public void setSensorValue(int index, double value)
      Set a specific sensor value.
      Parameters:
      index - The index of the sensor value to set.
      value - The value to set the sensor to.
    • subscribe

      public void subscribe(WSClient client)
      Subscribes a client to the sensor to recieve updates.
      Parameters:
      client - The client to subscribe.
    • unsubscribe

      public void unsubscribe(WSClient client)
      Unsubscribes a client from the sensor.
      Parameters:
      client - The client to unsubscribe.
    • setBusAndAddress

      protected void setBusAndAddress(int bus, int address)
      Sets the Bus and Address of the sensor (for I2C communication).
      Parameters:
      bus - The bus to set the sensor to.
      address - The address to set the sensor to.
    • getParentIdentification

      public byte getParentIdentification()
      Returns the address/identifier of the parent robot.
      Returns:
      The address/identifier of the parent robot.