Automatically generate claw constants.
Change-Id: I35d15b34e6ae8349b009cd636d5e3962f1c6af5c
diff --git a/frc971/control_loops/python/BUILD b/frc971/control_loops/python/BUILD
index df7d48b..747b49c 100644
--- a/frc971/control_loops/python/BUILD
+++ b/frc971/control_loops/python/BUILD
@@ -5,5 +5,7 @@
srcs = [
'control_loop.py',
'controls.py',
+ 'polytope.py',
+ 'libcdd.py',
],
)
diff --git a/frc971/control_loops/python/polytope.py b/frc971/control_loops/python/polytope.py
index e08a160..0b65e38 100644
--- a/frc971/control_loops/python/polytope.py
+++ b/frc971/control_loops/python/polytope.py
@@ -10,7 +10,7 @@
__author__ = 'Austin Schuh (austin.linux@gmail.com)'
-import libcdd
+from frc971.control_loops.python import libcdd
import numpy
import string
import sys
diff --git a/y2014/control_loops/claw/BUILD b/y2014/control_loops/claw/BUILD
index a91462d..6f77d7a 100644
--- a/y2014/control_loops/claw/BUILD
+++ b/y2014/control_loops/claw/BUILD
@@ -25,6 +25,22 @@
],
)
+genrule(
+ name = 'genrule_claw',
+ visibility = ['//visibility:private'],
+ cmd = '$(location //y2014/control_loops/python:claw) $(OUTS)',
+ tools = [
+ '//y2014/control_loops/python:claw',
+ ],
+ tags = [
+ 'local',
+ ],
+ outs = [
+ 'claw_motor_plant.h',
+ 'claw_motor_plant.cc',
+ ],
+)
+
cc_library(
name = 'claw_lib',
srcs = [
diff --git a/y2014/control_loops/claw/claw.cc b/y2014/control_loops/claw/claw.cc
index 7322b1e..1c93cf5 100644
--- a/y2014/control_loops/claw/claw.cc
+++ b/y2014/control_loops/claw/claw.cc
@@ -372,7 +372,7 @@
has_bottom_claw_goal_(false),
bottom_claw_goal_(0.0),
bottom_claw_(this),
- claw_(MakeClawLoop()),
+ claw_(::y2014::control_loops::claw::MakeClawLoop()),
was_enabled_(false),
doing_calibration_fine_tune_(false),
capped_goal_(false),
diff --git a/y2014/control_loops/claw/claw_lib_test.cc b/y2014/control_loops/claw/claw_lib_test.cc
index 9eb173e..0bf287f 100644
--- a/y2014/control_loops/claw/claw_lib_test.cc
+++ b/y2014/control_loops/claw/claw_lib_test.cc
@@ -17,6 +17,8 @@
namespace control_loops {
namespace testing {
+using ::y2014::control_loops::claw::MakeClawPlant;
+
typedef enum {
TOP_CLAW = 0,
BOTTOM_CLAW,
diff --git a/y2014/control_loops/claw/claw_motor_plant.cc b/y2014/control_loops/claw/claw_motor_plant.cc
deleted file mode 100644
index acba8d0..0000000
--- a/y2014/control_loops/claw/claw_motor_plant.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "y2014/control_loops/claw/claw_motor_plant.h"
-
-#include <vector>
-
-#include "frc971/control_loops/state_feedback_loop.h"
-
-namespace frc971 {
-namespace control_loops {
-
-StateFeedbackPlantCoefficients<4, 2, 2> MakeClawPlantCoefficients() {
- Eigen::Matrix<double, 4, 4> A;
- A << 1.0, 0.0, 0.00909331035298, 0.0, 0.0, 1.0, -6.04514323962e-05, 0.00903285892058, 0.0, 0.0, 0.824315642255, 0.0, 0.0, 0.0, -0.0112975266368, 0.813018115618;
- Eigen::Matrix<double, 4, 2> B;
- B << 0.000352527133889, 0.0, -0.000352527133889, 0.000376031064118, 0.0683072794628, 0.0, -0.0683072794628, 0.0726998350615;
- Eigen::Matrix<double, 2, 4> C;
- C << 1, 0, 0, 0, 1, 1, 0, 0;
- Eigen::Matrix<double, 2, 2> D;
- D << 0, 0, 0, 0;
- Eigen::Matrix<double, 2, 1> U_max;
- U_max << 12.0, 12.0;
- Eigen::Matrix<double, 2, 1> U_min;
- U_min << -12.0, -12.0;
- return StateFeedbackPlantCoefficients<4, 2, 2>(A, B, C, D, U_max, U_min);
-}
-
-StateFeedbackController<4, 2, 2> MakeClawController() {
- Eigen::Matrix<double, 4, 2> L;
- L << 1.72431564225, 2.70472958703e-16, -1.72431564225, 1.71301811562, 65.9456997026, 1.03478906105e-14, -65.9456997026, 64.4642687194;
- Eigen::Matrix<double, 2, 4> K;
- K << 106.138028875, 0.0, 4.20012492658, 0.0, 99.5038407367, 99.7251230882, 3.77683310096, 3.78980738032;
- Eigen::Matrix<double, 4, 4> A_inv;
- A_inv << 1.0, 0.0, -0.0110313451387, 0.0, 0.0, 1.0, -7.89348747778e-05, -0.0111102800135, 0.0, 0.0, 1.21312753118, 0.0, 0.0, 0.0, 0.016857361889, 1.22998489307;
- return StateFeedbackController<4, 2, 2>(L, K, A_inv, MakeClawPlantCoefficients());
-}
-
-StateFeedbackPlant<4, 2, 2> MakeClawPlant() {
- ::std::vector< ::std::unique_ptr<StateFeedbackPlantCoefficients<4, 2, 2>>> plants(1);
- plants[0] = ::std::unique_ptr<StateFeedbackPlantCoefficients<4, 2, 2>>(new StateFeedbackPlantCoefficients<4, 2, 2>(MakeClawPlantCoefficients()));
- return StateFeedbackPlant<4, 2, 2>(&plants);
-}
-
-StateFeedbackLoop<4, 2, 2> MakeClawLoop() {
- ::std::vector< ::std::unique_ptr<StateFeedbackController<4, 2, 2>>> controllers(1);
- controllers[0] = ::std::unique_ptr<StateFeedbackController<4, 2, 2>>(new StateFeedbackController<4, 2, 2>(MakeClawController()));
- return StateFeedbackLoop<4, 2, 2>(&controllers);
-}
-
-} // namespace control_loops
-} // namespace frc971
diff --git a/y2014/control_loops/claw/claw_motor_plant.h b/y2014/control_loops/claw/claw_motor_plant.h
deleted file mode 100644
index c7de33a..0000000
--- a/y2014/control_loops/claw/claw_motor_plant.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef Y2014_CONTROL_LOOPS_CLAW_CLAW_MOTOR_PLANT_H_
-#define Y2014_CONTROL_LOOPS_CLAW_CLAW_MOTOR_PLANT_H_
-
-#include "frc971/control_loops/state_feedback_loop.h"
-
-namespace frc971 {
-namespace control_loops {
-static constexpr double kClawMomentOfInertiaRatio = 0.933333;
-
-
-StateFeedbackPlantCoefficients<4, 2, 2> MakeClawPlantCoefficients();
-
-StateFeedbackController<4, 2, 2> MakeClawController();
-
-StateFeedbackPlant<4, 2, 2> MakeClawPlant();
-
-StateFeedbackLoop<4, 2, 2> MakeClawLoop();
-
-} // namespace control_loops
-} // namespace frc971
-
-#endif // Y2014_CONTROL_LOOPS_CLAW_CLAW_MOTOR_PLANT_H_
diff --git a/y2014/control_loops/python/BUILD b/y2014/control_loops/python/BUILD
index 232d128..ee99aa4 100644
--- a/y2014/control_loops/python/BUILD
+++ b/y2014/control_loops/python/BUILD
@@ -7,5 +7,27 @@
],
deps = [
'//frc971/control_loops/python:controls',
+ ],
+)
+
+py_library(
+ name = 'polydrivetrain',
+ srcs = [
+ 'polydrivetrain.py',
+ 'drivetrain.py',
+ ],
+ deps = [
+ '//frc971/control_loops/python:controls',
+ ],
+)
+
+py_binary(
+ name = 'claw',
+ srcs = [
+ 'claw.py',
+ ],
+ deps = [
+ ':polydrivetrain',
+ '//frc971/control_loops/python:controls',
]
)
diff --git a/y2014/control_loops/python/claw.py b/y2014/control_loops/python/claw.py
index b5ea6a1..f1fcae3 100755
--- a/y2014/control_loops/python/claw.py
+++ b/y2014/control_loops/python/claw.py
@@ -1,9 +1,9 @@
#!/usr/bin/python
-import control_loop
-import controls
-import polytope
-import polydrivetrain
+from frc971.control_loops.python import control_loop
+from frc971.control_loops.python import controls
+from frc971.control_loops.python import polytope
+from y2014.control_loops.python import polydrivetrain
import numpy
import sys
from matplotlib import pylab
@@ -478,8 +478,10 @@
if len(argv) != 3:
print "Expected .h file name and .cc file name for the claw."
else:
+ namespaces = ['y2014', 'control_loops', 'claw']
claw = Claw("Claw")
- loop_writer = control_loop.ControlLoopWriter("Claw", [claw])
+ loop_writer = control_loop.ControlLoopWriter("Claw", [claw],
+ namespaces=namespaces)
loop_writer.AddConstant(control_loop.Constant("kClawMomentOfInertiaRatio",
"%f", claw.J_top / claw.J_bottom))
if argv[1][-3:] == '.cc':
diff --git a/y2014/control_loops/python/drivetrain.py b/y2014/control_loops/python/drivetrain.py
index 14a3ecb..1372c25 100755
--- a/y2014/control_loops/python/drivetrain.py
+++ b/y2014/control_loops/python/drivetrain.py
@@ -28,7 +28,7 @@
# Torque constant
self.Kt = self.stall_torque / self.stall_current
# Control loop time step
- self.dt = 0.005
+ self.dt = 0.010
# State feedback matrices
self.A_continuous = numpy.matrix(
diff --git a/y2014/control_loops/python/polydrivetrain.py b/y2014/control_loops/python/polydrivetrain.py
index a2c63fa..b066c75 100755
--- a/y2014/control_loops/python/polydrivetrain.py
+++ b/y2014/control_loops/python/polydrivetrain.py
@@ -2,10 +2,10 @@
import numpy
import sys
-import polytope
-import drivetrain
-import control_loop
-import controls
+from frc971.control_loops.python import polytope
+from y2014.control_loops.python import drivetrain
+from frc971.control_loops.python import control_loop
+from frc971.control_loops.python import controls
from matplotlib import pylab
__author__ = 'Austin Schuh (austin.linux@gmail.com)'