Skip to content

Instantly share code, notes, and snippets.

@techtide
Created February 10, 2018 11:15
Show Gist options
  • Save techtide/3a0583f28ad7184f9c58185dcd944139 to your computer and use it in GitHub Desktop.
Save techtide/3a0583f28ad7184f9c58185dcd944139 to your computer and use it in GitHub Desktop.
package org.usfirst.frc.team1797.robot.utils;
import java.io.File;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.usfirst.frc.team1797.robot.Robot;
import org.usfirst.frc.team1797.robot.commands.auto.AutoRunner;
import org.usfirst.frc.team1797.robot.commands.auto.AutoRunner.Routines;
import jaci.pathfinder.Pathfinder;
import jaci.pathfinder.Trajectory;
/**
*
*/
public class TrajectoryManager {
public List<File> folder;
private HashMap<String, File> trajectories;
private String filePath = "/home/lvuser/trajectories/";
public TrajectoryManager() {
// TODO Auto-generated constructor stub
trajectories = new HashMap<>();
File x = new File(filePath);
folder = Arrays.asList(x.listFiles());
System.out.println("Folder: " + folder);
/*
* The CSV files need to be on the roboRIO, and need to include the alliance number and direction (at the end).
* For instance, it could be "BASELINECURVED2L"; the title also needs to be in all capitals.
*/
for(File f : folder) {
trajectories.put(f.getName(), f);
System.out.println(f.getName() + " : " + f);
}
System.out.println("TRAJECTORIES" + trajectories);
}
public Trajectory getTrajectoryFromFile(String trajectoryName) {
System.out.println("get trajectory from file: " + Pathfinder.readFromCSV(trajectories.get(trajectoryName + ".csv")));
return Pathfinder.readFromCSV(trajectories.get(trajectoryName + ".csv"));
}
// uncomment for writing files, etc
public void waypointCSVToTrajectory(File waypointCSV) {
Trajectory trajectory = Pathfinder.readFromCSV(waypointCSV);
Trajectory traj = new PathfinderUtils(trajectory, Robot.DRIVE_TRAIN.leftEncoder, Robot.DRIVE_TRAIN.rightEncoder).getInitialTrajectory();
File f = new File("/home/lvuser/trajectories/" + waypointCSV.getName() + ".csv");
Pathfinder.writeToCSV(f, traj);
System.out.println("File has been written as: " + f.getName() + ", at the location: " + f.getAbsolutePath() + ".");
}
/*public void saveTrajectoryCSV(File trajectoryCSV) {
File f = new File("/trajectorycsv/");
File folder[] = f.listFiles();
for(File file : folder) {
Files.copy("", out);
}
} */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment