Last active
February 10, 2018 13:48
-
-
Save techtide/ee246ff8876291c74f1a8dee684546c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.usfirst.frc.team1797.robot.utils; | |
import java.io.File; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import org.usfirst.frc.team1797.robot.commands.auto.AutoRunner.Routine; | |
import jaci.pathfinder.Pathfinder; | |
import jaci.pathfinder.Trajectory; | |
/* | |
* Created by techtide/greenie/ab for Phoenix 1797 of ASL Robotics. | |
*/ | |
public class TrajectoryUtils { | |
private HashMap<String, Trajectory> fileTrajectoryMap; | |
private String path = "/home/lvuser/"; | |
public TrajectoryUtils() { | |
fileTrajectoryMap = new HashMap<>(); | |
initialiseFileTrajectoryMap(); | |
} | |
public void initialiseFileTrajectoryMap() { | |
// Instantiates and reads all files into a map based on the format of "File/routine name":Trajectory. | |
File folderPath = new File(path + "trajectories/"); | |
File[] folder = folderPath.listFiles(); | |
for(File file : folder) { | |
fileTrajectoryMap.put(file.getName(), Pathfinder.readFromCSV(file)); | |
} | |
System.out.println("[TrajectoryManager: initFileTrajectoryMap] The files in the trajectory hashmap are: " | |
+ fileTrajectoryMap); | |
} | |
public Trajectory csvToTrajectory(Routine routineToRun, char direction) { | |
// File f = new File(path + "trajectories/" + routineToRun.name() + direction + ".csv"); | |
// System.out.println("[TrajectoryManager: csvToTrajectory] The file's name is: " + f.getName()); | |
// return Pathfinder.readFromCSV(f); | |
System.out.println("CSV FILE NAME: "+ routineToRun.name().toUpperCase() + direction + ".csv"); | |
return fileTrajectoryMap.get(routineToRun.name().toUpperCase() + direction + ".csv"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment