Class Robot

java.lang.Object
me.autobot.lib.robot.Robot
All Implemented Interfaces:
Logger
Direct Known Subclasses:
LidarBot, LogitechTest, MainBot, NNBot, ServoBot, TestBot

public class Robot extends Object implements Logger
The general robot class. This can be extended to create a robot with sensors and motors.
  • 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

      public static void start(Robot robot)
      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

      public static void subscribeToStatus(WSClient client, boolean subscribe)
      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 public static void subscribeToTelemetry(WSClient client, boolean subscribe)
      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

      public static ArrayList<Robot> getRobots()
      Gets all the robots.
      Returns:
      An array list of all the robots.
    • getRobotClasses

      public static ArrayList<Class<? extends Robot>> getRobotClasses()
      Gets all robot classes.
      Returns:
      An array list of all robot classes.
    • getInstance

      public static Robot 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

      public ArrayList<Sensor> getSensors()
      Gets all the sensors of the robot.
      Returns:
      An array list of all the sensors of the robot.
      See Also:
    • getMotors

      public ArrayList<Motor> getMotors()
      Gets all the motors of the robot.
      Returns:
      An array list of all the motors of the robot.
      See Also:
    • getDevices

      public ArrayList<Device> 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

      public Clock clock()
      Gets the clock of the robot.
      Returns:
      The clock of the robot.