Package robocode

Class RateControlRobot

  • All Implemented Interfaces:
    java.lang.Runnable, IAdvancedEvents, IAdvancedRobot, IBasicEvents, IBasicEvents2, IBasicEvents3, IBasicRobot, IInteractiveEvents, IInteractiveRobot, IPaintEvents, IPaintRobot, ITeamEvents, ITeamRobot

    public class RateControlRobot
    extends TeamRobot
    This advanced robot type allows you to set a rate for each of the robot's movements.

    You can set the rate for:

    • velocity - pixels per turn
    • robot turn - radians per turn
    • gun rotation - radians per turn
    • radar rotation - radians per turn
    When you set a rate for one of the above movements, the movement will continue the move by specified rate for ever, until the rate is changed. In order to move ahead or right, the rate must be set to a positive value. If a negative value is used instead, the movement will go back or to the left. In order to stop the movement, the rate must be set to 0.

    Note: When calling setVelocityRate(), setTurnRate(), setGunRotationRate(), setRadarRotationRate() and variants, Any previous calls to "movement" functions outside of RateControlRobot, such as setAhead(), setTurnLeft(), setTurnRadarRightRadians() and similar will be overridden when calling the execute() on this robot class.

    Look into the source code for the sample.VelociRobot in order to see how to use this robot type.

    Since:
    1.7.1.3
    Author:
    Joshua Galecki (original), Flemming N. Larsen (contributor)
    See Also:
    JuniorRobot, Robot, AdvancedRobot, TeamRobot, Droid, BorderSentry
    • Constructor Detail

      • RateControlRobot

        public RateControlRobot()
    • Method Detail

      • getVelocityRate

        public double getVelocityRate()
        Returns the speed the robot will move, in pixels per turn. Positive values means that the robot will move forward. Negative values means that the robot will move backwards. If the value is 0, the robot will stand still.
        Returns:
        The speed of the robot in pixels per turn
        See Also:
        setVelocityRate(double)
      • setTurnRate

        public void setTurnRate​(double turnRate)
        Sets the robot's clockwise (right) rotation per turn, in degrees.

        This call returns immediately, and will not execute until you call execute() or take an action that executes.

        Note that both positive and negative values can be given as input, where negative values means that the robot turns counterclockwise (left)

        Example:

           // Set the robot to turn right 10 degrees per turn
           setTurnRate(10);
        
           // Set the robot to turn left 4 degrees per turn
           // (overrides the previous order)
           setTurnRate(-5);
        
           ...
           // Executes the last setTurnRate()
           execute();
         
        Parameters:
        turnRate - angle of the clockwise rotation, in degrees.
        See Also:
        getTurnRate(), setVelocityRate(double), setGunRotationRate(double), setRadarRotationRate(double), AdvancedRobot.setTurnRight(double), AdvancedRobot.setTurnLeft(double)
      • getTurnRate

        public double getTurnRate()
        Gets the robot's clockwise rotation per turn, in degrees. Positive values means that the robot will turn to the right. Negative values means that the robot will turn to the left. If the value is 0, the robot will not turn.
        Returns:
        Angle of the clockwise rotation, in degrees.
        See Also:
        setTurnRate(double)
      • setTurnRateRadians

        public void setTurnRateRadians​(double turnRate)
        Sets the robot's clockwise (right) rotation per turn, in radians.

        This call returns immediately, and will not execute until you call execute() or take an action that executes.

        Note that both positive and negative values can be given as input, where negative values means that the robot turns counterclockwise (left)

        Example:

           // Set the robot to turn right pi / 32 radians per turn
           setTurnRateRadians(Math.PI / 32);
        
           // Set the robot to turn left pi / 20 radians per turn
           // (overrides the previous order)
           setTurnRateRadians(-Math.PI / 20);
        
           ...
           // Executes the last setTurnRateRadians()
           execute();
         
        Parameters:
        turnRate - angle of the clockwise rotation, in radians.
        See Also:
        setVelocityRate(double), setGunRotationRateRadians(double), setRadarRotationRateRadians(double), AdvancedRobot.setTurnRightRadians(double), AdvancedRobot.setTurnLeftRadians(double)
      • getTurnRateRadians

        public double getTurnRateRadians()
        Gets the robot's clockwise rotation per turn, in radians. Positive values means that the robot will turn to the right. Negative values means that the robot will turn to the left. If the value is 0, the robot will not turn.
        Returns:
        Angle of the clockwise rotation, in radians.
        See Also:
        getTurnRateRadians()
      • setGunRotationRate

        public void setGunRotationRate​(double gunRotationRate)
        Sets the gun's clockwise (right) rotation per turn, in degrees.

        This call returns immediately, and will not execute until you call execute() or take an action that executes.

        Note that both positive and negative values can be given as input, where negative values means that the gun turns counterclockwise (left)

        Example:

           // Set the gun to turn right 15 degrees per turn
           setGunRotationRate(15);
        
           // Set the gun to turn left 9 degrees per turn
           // (overrides the previous order)
           setGunRotationRate(-9);
        
           ...
           // Executes the last setGunRotationRate()
           execute();
         
        Parameters:
        gunRotationRate - angle of the clockwise rotation, in degrees.
        See Also:
        getGunRotationRate(), setVelocityRate(double), setTurnRate(double), setRadarRotationRate(double), AdvancedRobot.setTurnGunRight(double), AdvancedRobot.setTurnGunLeft(double)
      • getGunRotationRate

        public double getGunRotationRate()
        Gets the gun's clockwise rotation per turn, in degrees. Positive values means that the gun will turn to the right. Negative values means that the gun will turn to the left. If the value is 0, the gun will not turn.
        Returns:
        Angle of the clockwise rotation, in degrees.
        See Also:
        setGunRotationRate(double)
      • setGunRotationRateRadians

        public void setGunRotationRateRadians​(double gunRotationRate)
        Sets the gun's clockwise (right) rotation per turn, in radians.

        This call returns immediately, and will not execute until you call execute() or take an action that executes.

        Note that both positive and negative values can be given as input, where negative values means that the gun turns counterclockwise (left)

        Example:

           // Set the gun to turn right pi / 16 radians per turn
           setGunRotationRateRadians(Math.PI / 16);
        
           // Set the gun to turn left pi / 12 radians per turn
           // (overrides the previous order)
           setGunRotationRateRadians(-Math.PI / 12);
        
           ...
           // Executes the last setGunRotationRateRadians()
           execute();
         
        Parameters:
        gunRotationRate - angle of the clockwise rotation, in radians.
        See Also:
        getGunRotationRateRadians(), setVelocityRate(double), setTurnRateRadians(double), setRadarRotationRateRadians(double), AdvancedRobot.setTurnGunRightRadians(double), AdvancedRobot.setTurnGunLeftRadians(double)
      • getGunRotationRateRadians

        public double getGunRotationRateRadians()
        Gets the gun's clockwise rotation per turn, in radians. Positive values means that the gun will turn to the right. Negative values means that the gun will turn to the left. If the value is 0, the gun will not turn.
        Returns:
        Angle of the clockwise rotation, in radians.
        See Also:
        setGunRotationRateRadians(double)
      • setRadarRotationRate

        public void setRadarRotationRate​(double radarRotationRate)
        Sets the radar's clockwise (right) rotation per turn, in degrees.

        This call returns immediately, and will not execute until you call execute() or take an action that executes.

        Note that both positive and negative values can be given as input, where negative values means that the radar turns counterclockwise (left)

        Example:

           // Set the radar to turn right 45 degrees per turn
           setRadarRotationRate(45);
        
           // Set the radar to turn left 15 degrees per turn
           // (overrides the previous order)
           setRadarRotationRate(-15);
        
           ...
           // Executes the last setRadarRotationRate()
           execute();
         
        Parameters:
        radarRotationRate - angle of the clockwise rotation, in degrees.
        See Also:
        getRadarRotationRate(), setVelocityRate(double), setTurnRate(double), setGunRotationRate(double), AdvancedRobot.setTurnRadarRight(double), AdvancedRobot.setTurnRadarLeft(double)
      • getRadarRotationRate

        public double getRadarRotationRate()
        Gets the radar's clockwise rotation per turn, in degrees. Positive values means that the radar will turn to the right. Negative values means that the radar will turn to the left. If the value is 0, the radar will not turn.
        Returns:
        Angle of the clockwise rotation, in degrees.
        See Also:
        setRadarRotationRate(double)
      • setRadarRotationRateRadians

        public void setRadarRotationRateRadians​(double radarRotationRate)
        Sets the radar's clockwise (right) rotation per turn, in radians.

        This call returns immediately, and will not execute until you call execute() or take an action that executes.

        Note that both positive and negative values can be given as input, where negative values means that the radar turns counterclockwise (left)

        Example:

           // Set the radar to turn right pi / 4 radians per turn
           setRadarRotationRateRadians(Math.PI / 4);
        
           // Set the radar to turn left pi / 8 radians per turn
           // (overrides the previous order)
           setRadarRotationRateRadians(-Math.PI / 8);
        
           ...
           // Executes the last setRadarRotationRateRadians()
           execute();
         
        Parameters:
        radarRotationRate - angle of the clockwise rotation, in radians.
        See Also:
        getRadarRotationRateRadians(), setVelocityRate(double), setTurnRateRadians(double), setGunRotationRateRadians(double), AdvancedRobot.setTurnRadarRightRadians(double), AdvancedRobot.setTurnRadarLeftRadians(double)
      • getRadarRotationRateRadians

        public double getRadarRotationRateRadians()
        Gets the radar's clockwise rotation per turn, in radians. Positive values means that the radar will turn to the right. Negative values means that the radar will turn to the left. If the value is 0, the radar will not turn.
        Returns:
        Angle of the clockwise rotation, in radians.
        See Also:
        setRadarRotationRateRadians(double)
      • execute

        public void execute()
        Executes any pending actions, or continues executing actions that are in process. This call returns after the actions have been started.

        Note that advanced robots must call this function in order to execute pending set* calls like e.g. setVelocityRate(), setFire(), setTurnRate() etc. Otherwise, these calls will never get executed.

        Any previous calls to "movement" functions outside of RateControlRobot, such as setAhead(), setTurnLeft(), setTurnRadarLeftRadians() etc. will be overridden when this method is called on this robot class.

        In this example the robot will move while turning:

           setVelocityRate(6);
           setTurnRate(7);
        
           while (true) {
               execute();
           }
         
        Overrides:
        execute in class AdvancedRobot