<commit_before>package com.m3rcuriel.controve.control.trajectory;

import com.m3rcuriel.controve.util.CsvWriter;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

import static org.junit.Assert.assertEquals;

public class TrajectoryFollowerTest {

  CsvWriter writer;

  @Test
  public void test() {
    int netcycle = 0;
    writer = null;
    try {
      File dir = new File("logs/");
      if (!dir.exists()) {
        dir.mkdirs();
      }
      writer = new CsvWriter(new File("logs/traj.log.csv"), "Time", "Position", "Velocity",
          "Acceleration", "Command");
    } catch (IOException e) {
      e.printStackTrace();
    }

    TrajectoryFollower follower = new TrajectoryFollower();
    TrajectoryFollower.TrajectoryConfig config = new TrajectoryFollower.TrajectoryConfig();
    config.dt = 0.005;
    config.maxAcceleration = 180.0;
    config.maxVelocity = 60.0;
    TrajectoryFollower.TrajectorySetpoint setpoint = new TrajectoryFollower.TrajectorySetpoint();
    setpoint.acceleration = 0;
    setpoint.velocity = 0;
    setpoint.position = 0;
    follower.initialize(0.1, 0.0, 0.0, 1.0, 0.0, config);
    follower.setGoal(setpoint, 100.0);

    int cycles = 0;
    while (!follower.isFinishedTrajectory()) {
      loop(follower, setpoint, config.dt, netcycle);
      cycles++;
      netcycle++;
    }

    follower.calculate(setpoint.position, setpoint.velocity, config.dt);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Took " + cycles + " cycles; " + cycles * config.dt + " seconds");
    assertEquals(setpoint.position, 100.0, 1E-3);
    assertEquals(setpoint.velocity, 0.0, 1E-3);

    follower.setGoal(setpoint, 0.0);
    cycles = 0;
    while (!follower.isFinishedTrajectory()) {
      loop(follower, setpoint, config.dt, netcycle);
      cycles++;
      netcycle++;
    }
    follower.calculate(setpoint.position, setpoint.velocity, config.dt);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Took " + cycles + " cycles; " + cycles * config.dt + " seconds");
    assertEquals(setpoint.position, 0.0, 1E-3);
    assertEquals(setpoint.velocity, 0.0, 1E-3);

    setpoint.position = 0.0;
    setpoint.velocity = 60.0;
    setpoint.acceleration = 0;
    follower.setGoal(setpoint, 2.0);
    cycles = 0;
    while (!follower.isFinishedTrajectory()) {
      loop(follower, setpoint, config.dt, netcycle);
      cycles++;
      netcycle++;
    }
    follower.calculate(setpoint.position, setpoint.velocity, config.dt);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Took " + cycles + " cycles; " + cycles * config.dt + " seconds");
    assertEquals(setpoint.position, 2.0, 1E-3);
    assertEquals(setpoint.velocity, 0.0, 1E-3);

  }

  private void loop(TrajectoryFollower follower, TrajectoryFollower.TrajectorySetpoint setpoint,
      double dt, double netcycle) {
    double command = follower.calculate(setpoint.position, setpoint.velocity, dt);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Result: " + setpoint + "; Command: " + command);
    writer.writeLine(netcycle * dt, setpoint.position, setpoint.velocity, setpoint.acceleration,
        command);
  }

}<commit_msg>Fixed calls in TrajectoryFollowerTest.java<commit_after>package com.m3rcuriel.controve.control.trajectory;

import static org.junit.Assert.assertEquals;
import com.m3rcuriel.controve.util.CsvWriter;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class TrajectoryFollowerTest {

  CsvWriter writer;

  @Test
  public void test() {
    int netcycle = 0;
    writer = null;
    try {
      File dir = new File("logs/");
      if (!dir.exists()) {
        dir.mkdirs();
      }
      writer = new CsvWriter(new File("logs/traj.log.csv"), "Time", "Position", "Velocity",
          "Acceleration", "Command");
    } catch (IOException e) {
      e.printStackTrace();
    }

    TrajectoryFollower follower = new TrajectoryFollower();
    TrajectoryFollower.TrajectoryConfig config = new TrajectoryFollower.TrajectoryConfig();
    config.dt = 0.005;
    config.maxAcceleration = 180.0;
    config.maxVelocity = 60.0;
    TrajectoryFollower.TrajectorySetpoint setpoint = new TrajectoryFollower.TrajectorySetpoint();
    setpoint.acceleration = 0;
    setpoint.velocity = 0;
    setpoint.position = 0;
    follower.initialize(0.1, 0.0, 0.0, 1.0, 0.0, config);
    follower.setGoal(setpoint, 100.0);

    int cycles = 0;
    while (!follower.isFinishedTrajectory()) {
      loop(follower, setpoint, config.dt, netcycle);
      cycles++;
      netcycle++;
    }

    follower.calculate(setpoint.position, setpoint.velocity);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Took " + cycles + " cycles; " + cycles * config.dt + " seconds");
    assertEquals(setpoint.position, 100.0, 1E-3);
    assertEquals(setpoint.velocity, 0.0, 1E-3);

    follower.setGoal(setpoint, 0.0);
    cycles = 0;
    while (!follower.isFinishedTrajectory()) {
      loop(follower, setpoint, config.dt, netcycle);
      cycles++;
      netcycle++;
    }
    follower.calculate(setpoint.position, setpoint.velocity);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Took " + cycles + " cycles; " + cycles * config.dt + " seconds");
    assertEquals(setpoint.position, 0.0, 1E-3);
    assertEquals(setpoint.velocity, 0.0, 1E-3);

    setpoint.position = 0.0;
    setpoint.velocity = 60.0;
    setpoint.acceleration = 0;
    follower.setGoal(setpoint, 2.0);
    cycles = 0;
    while (!follower.isFinishedTrajectory()) {
      loop(follower, setpoint, config.dt, netcycle);
      cycles++;
      netcycle++;
    }
    follower.calculate(setpoint.position, setpoint.velocity);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Took " + cycles + " cycles; " + cycles * config.dt + " seconds");
    assertEquals(setpoint.position, 2.0, 1E-3);
    assertEquals(setpoint.velocity, 0.0, 1E-3);

  }

  private void loop(TrajectoryFollower follower, TrajectoryFollower.TrajectorySetpoint setpoint,
      double dt, double netcycle) {
    double command = follower.calculate(setpoint.position, setpoint.velocity);
    setpoint = follower.getCurrentSetpoint();
    System.out.println("Result: " + setpoint + "; Command: " + command);
    writer.writeLine(netcycle * dt, setpoint.position, setpoint.velocity, setpoint.acceleration,
        command);
  }

}
{'fraction_non_alphanumeric': 0.1345584799875409, 'fraction_numerical': 0.021803457405388568, 'mean_word_length': 3.4381478921907394, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6724232', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2072, 'n_words': 397}