Package me.autobot.lib.robot
Class Robot
java.lang.Object
me.autobot.lib.robot.Robot
- All Implemented Interfaces:
Logger
The general robot class.
This can be extended to create a robot with sensors and motors.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclock()
Gets the clock of the robot.static void
Creates the telemetry topics.static void
Stops the current robot.Gets all the devices of the robot.byte
Gets the identification of the robot.static Robot
Gets the first robot / only robot if only one robot is created (for multi-robot simulations).long
Gets the loop time.Gets all the motors of the robot.Gets all robot classes.Gets all the robots.Gets all the sensors of the robot.long
Gets the time elapsed since the robot was created.protected void
loop()
Loop method.static void
Pauses the current robot.static void
Publishes the status of the robot to Topicaprotected void
Registers all the devices of the robot.static void
Removes all inactive clients from the telemetry list.static void
Resumes the current robot.void
setLoopTime
(long loopTime) Sets the loop time.void
setPaused
(boolean paused) Pauses the robot.protected void
setup()
Setup method.static void
start()
Starts all the robots (adds them to the editable list available for selection).static void
Starts a singular robot.static void
startRobot
(int index) Starts a robot by index.static void
Starts the simulation for all robots.protected void
stop()
Stop method.void
stopLoop()
Cancels the loop timer.static void
subscribeToStatus
(WSClient client, boolean subscribe) Subscribes a WSClient to the status of the robot.static void
subscribeToTelemetry
(WSClient client, boolean subscribe) Deprecated.protected void
Switches all sensors to simulation mode.
-
Constructor Details
-
Robot
public Robot()Creates a new, basic robot. This robot has no sensors or motors. To create a robot with sensors and motors, extend this class and add the sensors and motors.
-
-
Method Details
-
start
public static void start()Starts all the robots (adds them to the editable list available for selection). -
start
Starts a singular robot.- Parameters:
robot
- The robot to start.
-
startRobot
public static void startRobot(int index) Starts a robot by index.- Parameters:
index
- The index of the robot to start.
-
disableRobot
public static void disableRobot()Stops the current robot. -
pauseRobot
public static void pauseRobot()Pauses the current robot. -
resumeRobot
public static void resumeRobot()Resumes the current robot. -
subscribeToStatus
Subscribes a WSClient to the status of the robot.- Parameters:
client
- The client to subscribe.subscribe
- Whether to subscribe or unsubscribe.
-
publishStatus
public static void publishStatus()Publishes the status of the robot to Topica -
removeAllInactiveTelemetryClients
public static void removeAllInactiveTelemetryClients()Removes all inactive clients from the telemetry list. -
createTelemetryTopics
public static void createTelemetryTopics()Creates the telemetry topics. -
subscribeToTelemetry
Deprecated.Subscribes a WSClient to the telemetry of the robot.- Parameters:
client
- The client to subscribe.subscribe
- Whether to subscribe or unsubscribe.- See Also:
-
startSimulation
public static void startSimulation()Starts the simulation for all robots. -
getRobots
Gets all the robots.- Returns:
- An array list of all the robots.
-
getRobotClasses
Gets all robot classes.- Returns:
- An array list of all robot classes.
-
getInstance
Gets the first robot / only robot if only one robot is created (for multi-robot simulations). If there is only one controlling robot, this will return that robot.- Returns:
- A robot instance.
-
getIdentification
public byte getIdentification()Gets the identification of the robot. This is a unique identifier for the robot, used generally for communication with multiple simulated robots. If you have only one robot, you can generally ignore this, as the value will be 0x00.- Returns:
- The identification of the robot.
-
setPaused
public void setPaused(boolean paused) Pauses the robot.- Parameters:
paused
- Whether the robot should be paused.
-
switchDevicesToSimulation
protected void switchDevicesToSimulation()Switches all sensors to simulation mode. This method is called when the simulation starts. It is not recommended to call this method manually.- See Also:
-
setup
protected void setup()Setup method. This method is called when the robot is created. Override this method with:@Override protected void setup() { //your code here //this code will be executed when the robot is created }
-
loop
protected void loop()Loop method. This method is called every loop of the simulation. Override this method with:@Override protected void loop() { //your code here //this code will be executed every loop of the simulation }
-
stop
protected void stop()Stop method. This method is called when the robot is stopped. Override this method with:@Override protected void stop() { //your code here //this code will be executed when the robot is stopped }
-
getSensors
Gets all the sensors of the robot. -
getMotors
Gets all the motors of the robot. -
getDevices
Gets all the devices of the robot.- Returns:
- An array list of all the devices of the robot.
- See Also:
-
registerAllDevices
protected void registerAllDevices()Registers all the devices of the robot. This should be called after assigning all the devices to the robot, but BEFORE connecting them to I2C. TODO: Deprecate this method and replace it with a default behavior. -
stopLoop
public void stopLoop()Cancels the loop timer. Will stop the loop method from being called in the future. -
setLoopTime
public void setLoopTime(long loopTime) Sets the loop time.- Parameters:
loopTime
- The time between each loop.
-
getLoopTime
public long getLoopTime()Gets the loop time.- Returns:
- The time between each loop.
-
getTimeElapsed
public long getTimeElapsed()Gets the time elapsed since the robot was created.- Returns:
- The time elapsed in milliseconds.
-
clock
Gets the clock of the robot.- Returns:
- The clock of the robot.
-