Converted Eigen << to direct assignment.
For a Cortex-M4, this results in significantly fewer instructions.
I have no idea why.
Change-Id: Ic398bdf240302d941d9ffb12f4eaa081ecd36080
diff --git a/frc971/control_loops/drivetrain/drivetrain.cc b/frc971/control_loops/drivetrain/drivetrain.cc
index 5757b58..651976e 100644
--- a/frc971/control_loops/drivetrain/drivetrain.cc
+++ b/frc971/control_loops/drivetrain/drivetrain.cc
@@ -140,7 +140,7 @@
// z accel is down
// x accel is the front of the robot pointed down.
Eigen::Matrix<double, 1, 1> Y;
- Y << angle;
+ Y(0, 0) = angle;
down_estimator_.Correct(Y);
}
@@ -148,7 +148,7 @@
"New IMU value from ADIS16448, rate is %f, angle %f, fused %f, bias "
"%f\n",
rate, angle, down_estimator_.X_hat(0, 0), down_estimator_.X_hat(1, 0));
- down_U_ << rate;
+ down_U_(0, 0) = rate;
}
down_estimator_.UpdateObserver(down_U_);
@@ -256,7 +256,8 @@
// Voltage error.
Eigen::Matrix<double, 2, 1> U;
- U << last_left_voltage_, last_right_voltage_;
+ U(0, 0) = last_left_voltage_;
+ U(1, 0) = last_right_voltage_;
last_left_voltage_ = left_voltage;
last_right_voltage_ = right_voltage;
diff --git a/frc971/control_loops/python/control_loop.py b/frc971/control_loops/python/control_loop.py
index 951a114..d6bd85f 100644
--- a/frc971/control_loops/python/control_loop.py
+++ b/frc971/control_loops/python/control_loop.py
@@ -244,18 +244,10 @@
"""
ans = [' Eigen::Matrix<double, %d, %d> %s;\n' % (
matrix.shape[0], matrix.shape[1], matrix_name)]
- first = True
for x in xrange(matrix.shape[0]):
for y in xrange(matrix.shape[1]):
- element = matrix[x, y]
- if first:
- ans.append(' %s << ' % matrix_name)
- first = False
- else:
- ans.append(', ')
- ans.append(str(element))
+ ans.append(' %s(%d, %d) = %s;\n' % (matrix_name, x, y, repr(matrix[x, y])))
- ans.append(';\n')
return ''.join(ans)
def DumpPlantHeader(self):