Make Galactic Search Splines
Change-Id: Ifbc272d67ab9a0324872970f960ffa469102056d
diff --git a/frc971/control_loops/python/constants.py b/frc971/control_loops/python/constants.py
index af5d3ff..cb0de5b 100644
--- a/frc971/control_loops/python/constants.py
+++ b/frc971/control_loops/python/constants.py
@@ -109,6 +109,13 @@
FIELD = FIELDS["2021 Galactic Search BRed"]
+def get_json_folder(field):
+ if field.year == 2020 or field.year == 2021:
+ return "y2020/actors/splines"
+ else:
+ return "frc971/control_loops/python/spline_jsons"
+
+
def pxToM(p):
return p * FIELD.width / SCREEN_SIZE
diff --git a/frc971/control_loops/python/path_edit.py b/frc971/control_loops/python/path_edit.py
index 7620ff5..2031416 100755
--- a/frc971/control_loops/python/path_edit.py
+++ b/frc971/control_loops/python/path_edit.py
@@ -332,8 +332,12 @@
self.index_of_edit, self.spline_edit, self.x, self.y, difs)
def export_json(self, file_name):
- self.path_to_export = os.path.join(self.module_path,
- "spline_jsons/" + file_name)
+ self.path_to_export = os.path.join(
+ self.module_path, # position of the python
+ "../../..", # root of the repository
+ get_json_folder(FIELD), # path from the root
+ file_name # selected file
+ )
if file_name[-5:] != ".json":
print("Error: Filename doesn't end in .json")
else:
@@ -346,8 +350,13 @@
json.dump(multi_spline, points_file)
def import_json(self, file_name):
- self.path_to_export = os.path.join(self.module_path,
- "spline_jsons/" + file_name)
+ self.path_to_export = os.path.join(
+ self.module_path, # position of the python
+ "../../..", # root of the repository
+ get_json_folder(FIELD), # path from the root
+ file_name # selected file
+ )
+
if file_name[-5:] != ".json":
print("Error: Filename doesn't end in .json")
else:
@@ -360,7 +369,7 @@
# if people messed with the spline json,
# it might not be the right length
# so give them a nice error message
- try: # try to salvage as many segments of the spline as possible
+ try: # try to salvage as many segments of the spline as possible
self.points.fromMultiSpline(multi_spline)
except IndexError:
# check if they're both 6+5*(k-1) long
@@ -368,9 +377,13 @@
x_len = len(multi_spline["spline_x"])
y_len = len(multi_spline["spline_x"])
if x_len is not expected_length:
- print("Error: spline x values were not the expected length; expected {} got {}".format(expected_length, x_len))
+ print(
+ "Error: spline x values were not the expected length; expected {} got {}"
+ .format(expected_length, x_len))
elif y_len is not expected_length:
- print("Error: spline y values were not the expected length; expected {} got {}".format(expected_length, y_len))
+ print(
+ "Error: spline y values were not the expected length; expected {} got {}"
+ .format(expected_length, y_len))
print("SPLINES LOADED")
diff --git a/y2020/actors/splines/spline_blue_a.json b/y2020/actors/splines/spline_blue_a.json
index 733d516..28c90f4 100644
--- a/y2020/actors/splines/spline_blue_a.json
+++ b/y2020/actors/splines/spline_blue_a.json
@@ -1 +1 @@
-{"spline_count": 1, "spline_x": [0, 0.4, 0.4, 0.6, 0.6, 1.0], "spline_y": [0, 0, 0.05, 0.1, 0.15, 0.15], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 1}, {"constraint_type": "LATERAL_ACCELERATION", "value": 1}, {"constraint_type": "VOLTAGE", "value": 2}]}
+{"spline_count": 3, "spline_x": [-3.8589564582257236, -2.706301079868285, -1.8662093637009298, -1.3063849916064052, -0.4873721348786154, -0.00625139624225228, 0.4748693423941108, 0.6180979629390473, -0.009563129519629676, 0.15372038836518587, 0.6260651875645665, 1.0984099867639472, 1.879816067277893, 2.9980503292871896, 3.5245728709323347, 4.3991472026730385], "spline_y": [-1.6780186596074382, -1.8082232817342458, -1.892411108600207, -1.749871279377583, -1.9347886872094529, -1.488971578802944, -1.0431544703964353, 0.03339715424845213, -0.09653840876807873, 0.6210084137719525, 0.8305055244382749, 1.0400026351045972, 0.7414500338972108, -0.9412994536092459, -1.2421690381262913, -1.7536811563791324], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 3.0}, {"constraint_type": "LATERAL_ACCELERATION", "value": 2.0}, {"constraint_type": "VOLTAGE", "value": 4.0}]}
diff --git a/y2020/actors/splines/spline_blue_b.json b/y2020/actors/splines/spline_blue_b.json
index 733d516..7ef0494 100644
--- a/y2020/actors/splines/spline_blue_b.json
+++ b/y2020/actors/splines/spline_blue_b.json
@@ -1 +1 @@
-{"spline_count": 1, "spline_x": [0, 0.4, 0.4, 0.6, 0.6, 1.0], "spline_y": [0, 0, 0.05, 0.1, 0.15, 0.15], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 1}, {"constraint_type": "LATERAL_ACCELERATION", "value": 1}, {"constraint_type": "VOLTAGE", "value": 2}]}
+{"spline_count": 3, "spline_x": [-4.150494304057981, -3.3986216889688787, -2.2755236069860536, -0.7710065615315085, -0.3059309707515497, 0.07081943278667355, 0.4475698363248968, 0.7359950526213844, 0.6477528893336757, 0.9985598447184914, 1.5433015318310954, 2.0880432189436995, 2.826719637784092, 2.54224882166839, 3.098134168388431, 4.279168364217459], "spline_y": [-1.8370325937822833, -1.7225587047230115, -1.4951960691341684, -1.2591343681398501, -1.052224068633781, -0.746549088407154, -0.44087410818052697, -0.03643444723334266, 0.4353676213035902, 0.7416545188210228, 0.7718694725351886, 0.8020844262493543, 0.5562274361602532, -0.9685113232825411, -0.8008121610278923, -1.6595312237700157], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 3.0}, {"constraint_type": "LATERAL_ACCELERATION", "value": 2.0}, {"constraint_type": "VOLTAGE", "value": 4.0}]}
diff --git a/y2020/actors/splines/spline_red_a.json b/y2020/actors/splines/spline_red_a.json
index 733d516..5de7e30 100644
--- a/y2020/actors/splines/spline_red_a.json
+++ b/y2020/actors/splines/spline_red_a.json
@@ -1 +1 @@
-{"spline_count": 1, "spline_x": [0, 0.4, 0.4, 0.6, 0.6, 1.0], "spline_y": [0, 0, 0.05, 0.1, 0.15, 0.15], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 1}, {"constraint_type": "LATERAL_ACCELERATION", "value": 1}, {"constraint_type": "VOLTAGE", "value": 2}]}
+{"spline_count": 3, "spline_x": [-3.5430995125258264, -2.833856622869318, -2.2671351126678716, -1.5517361505681804, -1.0942218895273754, -0.7058266076962806, -0.3174313258651858, 0.0018449767561987526, -0.7213536245803214, -0.46077833241864685, 0.08654170971074387, 0.6338617518401346, 1.4679265439372415, 1.8681219896048553, 2.4377923876549588, 4.128750484245868], "spline_y": [1.345144878292872, 0.563397477079029, -0.10274521807205578, -0.6578218499806299, -0.8755060450025827, -0.6711287448347107, -0.4667514446668389, 0.15968735069085743, 0.5673580271823342, 1.1876484375, 1.4852908501743287, 1.7829332628486574, 1.7579276778796489, 1.8390174812758264, 1.9139266125387395, 1.8437913586324897], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 3.0}, {"constraint_type": "LATERAL_ACCELERATION", "value": 2.0}, {"constraint_type": "VOLTAGE", "value": 4.0}]}
diff --git a/y2020/actors/splines/spline_red_b.json b/y2020/actors/splines/spline_red_b.json
index 733d516..ab5ec8f 100644
--- a/y2020/actors/splines/spline_red_b.json
+++ b/y2020/actors/splines/spline_red_b.json
@@ -1 +1 @@
-{"spline_count": 1, "spline_x": [0, 0.4, 0.4, 0.6, 0.6, 1.0], "spline_y": [0, 0, 0.05, 0.1, 0.15, 0.15], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 1}, {"constraint_type": "LATERAL_ACCELERATION", "value": 1}, {"constraint_type": "VOLTAGE", "value": 2}]}
+{"spline_count": 2, "spline_x": [-3.392645926339286, -2.154575892857143, -1.9643174545865811, -1.8674530715821605, -1.4586490399672885, -0.7749665868973982, -0.09128413382750789, 0.8672767406974007, 0.3081139946408683, 0.39452214556653653, 4.533722882231405], "spline_y": [1.5839347098214285, 0.8960059988839286, 0.540389038357809, -0.3293477472090389, -0.755995497807628, -0.7561097332951151, -0.7562239687826022, -0.3298046891589874, 1.1545971581813754, 1.2564632146958519, 1.674700392037384], "constraints": [{"constraint_type": "LONGITUDINAL_ACCELERATION", "value": 3}, {"constraint_type": "LATERAL_ACCELERATION", "value": 2}, {"constraint_type": "VOLTAGE", "value": 4.0}]}