JaciBrunning / Pathfinder

Cross-Platform, Multi-Use Motion Profiling and Trajectory Generation
MIT License
255 stars 78 forks source link

Segfault when trying to save a trajectory in CSV or raw format #37

Open vampjaz opened 6 years ago

vampjaz commented 6 years ago

Trying to make code that saves the trajectory to a file and then reads from that file as a cache. I discovered that the Pathfinder.writeToFile and Pathfinder.writeToCSV methods both cause a segfault during the call to the C++ library. This is running on the roboRio. Here is the crash log.

The path generated just fine, but after, when we try to save it, it crashes.

        Waypoint[] points = new Waypoint[] {
            new Waypoint(-4, -1, Pathfinder.d2r(-45)),
            new Waypoint(-2, -2, 0),
            new Waypoint(0, 0, 0) 
        };

        Trajectory.Config config = 
                new Trajectory.Config(
                        Trajectory.FitMethod.HERMITE_CUBIC, 
                        Trajectory.Config.SAMPLES_HIGH, 
                        0.05, 
                        RobotMap.MAX_VELOCITY, 
                        2.0, 
                        60.0);

        File saveFile = new File(RobotMap.TRAJECTORY_CACHE);
        if(saveFile.exists() && !saveFile.isDirectory()) {
            log.add("trajectory file already found, usng cached paths", LOG_LEVEL);
            trajectory = Pathfinder.readFromFile(saveFile);
        } else {
            log.add("trajectory file not found, generating new path", LOG_LEVEL);
            trajectory = Pathfinder.generate(points, config);
            log.add("saving path to cache", LOG_LEVEL);
            Pathfinder.writeToFile(saveFile,trajectory);
        }
JaciBrunning commented 6 years ago

Does the parent folder you're trying to save to exist?

vampjaz commented 6 years ago

The path we specified was just a filename, so I assume that it would be placed in the same folder as the executing program. Would you recommend an absolute path instead of a relative one?

JaciBrunning commented 6 years ago

The files are relative to the executing directory of the program. I would recommend instead using a relative path