Package me.autobot.lib.robot
Class Sensor
java.lang.Object
me.autobot.lib.robot.Device
me.autobot.lib.robot.Sensor
- All Implemented Interfaces:
Logger
- Direct Known Subclasses:
CollisionSensor
A device that's used to sense the environment around the robot.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionSensor
(int identifier, int sensorChannels) Creates a new sensor with the given address and number of sensor channels. -
Method Summary
Modifier and TypeMethodDescriptionvoid
attachRelativePosition
(Vector3d relativePosition) Attaches the relative position of the sensor to the center of the robot.void
attachRelativePosition
(Vector3d relativePosition, Rotation3d relativeRotation) Attaches the relative position and rotation of the sensor to the center of the robot.protected void
changeUpdateInterval
(long interval) Changes the update interval of the sensor for the subscribers.void
connectToI2C
(int address, int bus, int pin) Connects the sensor to the I2C bus.void
connectToSerial
(String port) Connects the sensor via Serialint
Returns the I2C address of the sensor hub.int
getBus()
Returns the I2C bus of the sensor hub.int
Returns the identifier of the sensor.byte
Returns the address/identifier of the parent robot.Gets the relative position to the center of the robot.Gets the relative rotation to the center of the robot.static Sensor
getSensor
(int identifier, int robotAddr) Gets the sensor object with the specific identifier and robot address.double[]
Returns the raw sensor values.double[]
Returns the processed sensor values.protected void
setBusAndAddress
(int bus, int address) Sets the Bus and Address of the sensor (for I2C communication).void
setSensorValue
(int index, double value) Set a specific sensor value.protected void
setSensorValues
(double... values) Set the sensor values.void
simulateValues
(double[] values) Plugs in fake sensor values for simulation.void
Subscribes a client to the sensor to recieve updates.void
unsubscribe
(WSClient client) Unsubscribes a client from the sensor.Methods inherited from class me.autobot.lib.robot.Device
emergencyStop, emergencyStopAll, enableSimulation, getCurrent, getParent, getProperties, getProperty, getVoltage, inSimulation, registerDevice, setParent, setProperty
-
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
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
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
Gets the relative position to the center of the robot.- Returns:
- The relative position to the center of the robot.
-
getRelativeRotation
Gets the relative rotation to the center of the robot.- Returns:
- The relative rotation to the center of the robot.
-
attachRelativePosition
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
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
Subscribes a client to the sensor to recieve updates.- Parameters:
client
- The client to subscribe.
-
unsubscribe
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.
-