Improve Spline UI graph behavior for edge cases
If one of the multisplines fails to optimize, trying to put the cursor
on it will cause an out of bounds error
If the robot was still highlighted on the splines and you tried to move
the cursor from the graph, it wouldn't work.
Signed-off-by: Ravago Jones <ravagojones@gmail.com>
Change-Id: Ic8c37c5de07f6ef6d7a2b71971f34627e6ad2dba
diff --git a/frc971/control_loops/python/graph.py b/frc971/control_loops/python/graph.py
index 7d73a79..b85b996 100644
--- a/frc971/control_loops/python/graph.py
+++ b/frc971/control_loops/python/graph.py
@@ -47,6 +47,8 @@
if self.data is None:
return None
cursor_index = int(self.cursor / self.dt)
+ if cursor_index > self.data.size:
+ return None
# use the time to index into the position data
distance_at_cursor = self.data[0][cursor_index - 1]
multispline_index = int(self.data[5][cursor_index - 1])
diff --git a/frc971/control_loops/python/path_edit.py b/frc971/control_loops/python/path_edit.py
index 91f31d4..a0eb797 100755
--- a/frc971/control_loops/python/path_edit.py
+++ b/frc971/control_loops/python/path_edit.py
@@ -246,17 +246,7 @@
multispline, result = Multispline.nearest_distance(
self.multisplines, mouse)
- # if the mouse is close enough, draw the robot
- if result is not None and result.fun < 2:
- distance_spline = DistanceSpline(multispline.getLibsplines())
- x = result.x[0]
-
- # draw the robot to show its width
- self.draw_robot_at_point(cr, distance_spline, x)
-
- multispline_index = self.multisplines.index(multispline)
- self.graph.place_cursor(multispline_index, distance=result.x[0])
- elif self.graph.cursor is not None:
+ if self.graph.cursor is not None and self.graph.data is not None:
multispline_index, x = self.graph.find_cursor()
distance_spline = DistanceSpline(
self.multisplines[multispline_index].getLibsplines())
@@ -266,6 +256,15 @@
# clear the cursor each draw so it doesn't persist
# after you move off the spline
self.graph.cursor = None
+ elif result is not None and result.fun < 2:
+ distance_spline = DistanceSpline(multispline.getLibsplines())
+ x = result.x[0]
+
+ # draw the robot to show its width
+ self.draw_robot_at_point(cr, distance_spline, x)
+
+ multispline_index = self.multisplines.index(multispline)
+ self.graph.place_cursor(multispline_index, distance=result.x[0])
def export_json(self, file_name):
self.path_to_export = os.path.join(