<commit_before>// The DriveTask collects together methods that control the robot movement
class DriveTask {

  final Robot robot;
  boolean gamepadEnabled = false; // Stays disabled until "A" button is pressed

  public DriveTask(Robot r) {
    robot = r;
  }


  void init() {
  }


  void start() {
    setStartingPower();
  }


  void stop() {
    robot.drive.stop();
  }


  void loop() {
    driveTaskLoop1();
  }


  void deinit() {
  }


  void setStartingPower() {
    //r.stop();
    double pFwd = 0.5;
    double pStrafe = 0.5;
    double pTurn = 0.2;
    MeccanumDrive d = robot.drive;

    d.setPowerFL(pFwd + pStrafe + pTurn);
    d.setPowerFR(pFwd - pStrafe - pTurn);
    d.setPowerBL(pFwd - pStrafe + pTurn);
    d.setPowerBR(pFwd + pStrafe - pTurn);
  }


  void driveTaskLoop1() {
    GamepadInterface gp = robot.gamepad;
    if (!gamepadEnabled && gp.a()) {
      gamepadEnabled = true;
    }

    if (!gamepadEnabled) {
      return; // ***** EARLY RETURN ******
    }
    
    if (robot.gamepad.right_bumper()) {         //right bumper makes the robot spin clockwise
      setPowerAll(0.5, -0.5, 0.5, -0.5); // FL FR BL BR
    } else if (robot.gamepad.left_bumper()) {    //left bumper makes the robot spin counterclockwise
      setPowerAll(-0.5, 0.5, -0.5, 0.5);
    } else {
      setPowerAll(0, 0, 0, 0);
    }
  }


  void setPowerAll(double pFL, double pFR, double pBL, double pBR) {
    MeccanumDrive d = robot.drive;
    d.setPowerFL(pFL);
    d.setPowerFR(pFR);
    d.setPowerBL(pBL);
    d.setPowerBR(pBR);
  }
}<commit_msg>Attempt to add analog turn, forward and strafe joystick control<commit_after>// The DriveTask collects together methods that control the robot movement
class DriveTask {

  final Robot robot;
  boolean gamepadEnabled = false; // Stays disabled until "A" button is pressed

  public DriveTask(Robot r) {
    robot = r;
  }


  void init() {
  }


  void start() {
    setStartingPower();
  }


  void stop() {
    robot.drive.stop();
  }


  void loop() {
    driveTaskLoop1();
  }


  void deinit() {
  }


  void setStartingPower() {
    //r.stop();
    double pFwd = 0.5;
    double pStrafe = 0.5;
    double pTurn = 0.2;
    MeccanumDrive d = robot.drive;

    d.setPowerFL(pFwd + pStrafe + pTurn);
    d.setPowerFR(pFwd - pStrafe - pTurn);
    d.setPowerBL(pFwd - pStrafe + pTurn);
    d.setPowerBR(pFwd + pStrafe - pTurn);
  }


  void driveTaskLoop1() {
    GamepadInterface gp = robot.gamepad;
    if (!gamepadEnabled && gp.a()) {
      gamepadEnabled = true;
    }

    if (!gamepadEnabled) {
      return; // ***** EARLY RETURN ******
    }

    if (gp.right_bumper()) {         //right bumper makes the robot spin clockwise
      setPowerAll(0.5, -0.5, 0.5, -0.5); // FL FR BL BR
    } else if (gp.left_bumper()) {    //left bumper makes the robot spin counterclockwise
      setPowerAll(-0.5, 0.5, -0.5, 0.5);
    } else {
      double fwd  = gp.right_stick_y();
      double turn  = gp.left_stick_x();
      double strafe = gp.right_stick_x();
      setHybridPower(fwd, turn, strafe);
    }
  }

  // Sets the power to each of the 4 motors of the meccanum drive given
  // the incoming request to go forward, turn and strafe by amounts
  // ranging within [-1, 1]
  void setHybridPower(double fwd, double turn, double strafe) {
    // Let's clip anyways, incase we get faulty input
    fwd = clipInput(fwd);
    turn = clipInput(turn);
    strafe = clipInput(turn);

    double pFL = fwd + strafe + turn;
    double pFR = fwd - strafe - turn;
    double pBL = fwd - strafe + turn;
    double pBR =fwd + strafe - turn;

    // m is the max absolute value of the individual motor power amounts. If it is too small, we stop all motors.
    double m = Math.max(Math.max(Math.abs(pFL), Math.abs(pFR)), Math.max(Math.abs(pBL), Math.abs(pBR)));
    if (m<0.1) {
      setPowerAll(0, 0, 0, 0);
    } else {
      // Scale everything so no magnitude exeeds 1
      double scale = Math.max(1/m, 1);
      pFL *= scale;
      pFR *= scale;
      pBL *= scale;
      pBR *= scale;
      setPowerAll(0, 0, 0, 0);
    }
  }

  // Clips input to be within [-1, 1]
  double clipInput(double in) {
    return Math.max(Math.min(in, 1), -1);
  }


  void setPowerAll(double pFL, double pFR, double pBL, double pBR) {
    MeccanumDrive d = robot.drive;
    d.setPowerFL(pFL);
    d.setPowerFR(pFR);
    d.setPowerBL(pBL);
    d.setPowerBR(pBR);
  }
}
{'fraction_non_alphanumeric': 0.13284804367606914, 'fraction_numerical': 0.01637852593266606, 'mean_word_length': 2.4217898832684823, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4433375', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1580, 'n_words': 434}