Fix segfaults in spline UI
I suspect that this actually started happening when Python upgrades
happened, since the previous logic was checking for zero-length
trajectories, but it looks like numpy may now manage zero-length arrays
differently than it did previousl.
Change-Id: Id4212d0c7ea6efcf47295841c92de3aad79072a5
diff --git a/frc971/control_loops/drivetrain/trajectory.cc b/frc971/control_loops/drivetrain/trajectory.cc
index ff60b4c..9c32483 100644
--- a/frc971/control_loops/drivetrain/trajectory.cc
+++ b/frc971/control_loops/drivetrain/trajectory.cc
@@ -735,6 +735,10 @@
// linearization for the infal point).
void Trajectory::CalculatePathGains() {
const std::vector<Eigen::Matrix<double, 3, 1>> xva_plan = PlanXVA(config_.dt);
+ if (xva_plan.empty()) {
+ LOG(ERROR) << "Plan is empty--unable to plan trajectory.";
+ return;
+ }
plan_gains_.resize(xva_plan.size());
// Set up reasonable gain matrices. Current choices of gains are arbitrary
diff --git a/frc971/control_loops/python/graph.py b/frc971/control_loops/python/graph.py
index 5f68444..3063bd1 100644
--- a/frc971/control_loops/python/graph.py
+++ b/frc971/control_loops/python/graph.py
@@ -43,7 +43,7 @@
mypoints.addConstraintsToTrajectory(traj)
traj.Plan()
XVA = traj.GetPlanXVA(dT)
- if len(XVA[0]) > 0:
+ if XVA is not None:
self.draw_x_axis(cr, start, height, zero, XVA, end)
self.drawVelocity(cr, XVA, start, height, skip, zero, end,
legend_entries)
diff --git a/frc971/control_loops/python/libspline.py b/frc971/control_loops/python/libspline.py
index 4e68221..9ba6f4f 100755
--- a/frc971/control_loops/python/libspline.py
+++ b/frc971/control_loops/python/libspline.py
@@ -251,6 +251,9 @@
libSpline.TrajectoryGetPlanXVAPtr(self.__trajectory,
int(dt * 1e9)))
XVALength = libSpline.TrajectoryGetVectorLength(XVAPtr)
+ if XVALength == 0:
+ libSpline.TrajectoryDeleteVector(XVAPtr)
+ return None
X = np.zeros(XVALength)
V = np.zeros(XVALength)
A = np.zeros(XVALength)