Fixed constants and moved them out of control_loop.py
diff --git a/frc971/control_loops/python/control_loop.py b/frc971/control_loops/python/control_loop.py
index 51ce0ff..bda178e 100644
--- a/frc971/control_loops/python/control_loop.py
+++ b/frc971/control_loops/python/control_loop.py
@@ -10,7 +10,7 @@
self.formatToType['%f'] = "double";
self.formatToType['%d'] = "int";
def __str__ (self):
- return str("\nstatic const %s %s = "+ self.formatt +";\n") % \
+ return str("\nstatic constexpr %s %s = "+ self.formatt +";\n") % \
(self.formatToType[self.formatt], self.name, self.value)
@@ -39,9 +39,14 @@
['} // namespace %s' % name for name in reversed(self._namespaces)])
self._constant_list = []
- if (write_constants):
- self._constant_list.append(Constant("kMaxExtension", "%f", 0.32385));
- self._constant_list.append(Constant("kSpringConstant", "%f", 0.28));
+
+ def AddConstant(self, constant):
+ """Adds a constant to write.
+
+ Args:
+ constant: Constant, the constant to add to the header.
+ """
+ self._constant_list.append(constant)
def _TopDirectory(self):
return self._namespaces[0]
diff --git a/frc971/control_loops/python/shooter.py b/frc971/control_loops/python/shooter.py
index 6b8c224..69f2599 100755
--- a/frc971/control_loops/python/shooter.py
+++ b/frc971/control_loops/python/shooter.py
@@ -30,6 +30,9 @@
self.Kt = self.stall_torque / self.stall_current
# Spring constant for the springs, N/m
self.Ks = 2800.0
+ # Maximum extension distance (Distance from the 0 force point on the
+ # spring to the latch position.)
+ self.max_extension = 0.32385
# Gear ratio multiplied by radius of final sprocket.
self.G = 10.0 / 40.0 * 20.0 / 54.0 * 24.0 / 54.0 * 20.0 / 84.0 * 16.0 * (3.0 / 8.0) / (2.0 * numpy.pi) * 0.0254
@@ -236,8 +239,12 @@
sprung_shooter = SprungShooterDeltaU()
shooter = ShooterDeltaU()
loop_writer = control_loop.ControlLoopWriter("Shooter", [sprung_shooter,
- shooter],
- write_constants=True)
+ shooter])
+
+ loop_writer.AddConstant(control_loop.Constant("kMaxExtension", "%f",
+ sprung_shooter.max_extension))
+ loop_writer.AddConstant(control_loop.Constant("kSpringConstant", "%f",
+ sprung_shooter.Ks))
if argv[1][-3:] == '.cc':
loop_writer.Write(argv[2], argv[1])
else: