Add interpolation table to y2017 constants
The next patch will make use of this for determining the actual hood
and turret angles.
Change-Id: I9f956306b5795652148cdfbbe588c598d9c72a43
diff --git a/frc971/shooter_interpolation/BUILD b/frc971/shooter_interpolation/BUILD
index bbef440..3509040 100644
--- a/frc971/shooter_interpolation/BUILD
+++ b/frc971/shooter_interpolation/BUILD
@@ -6,6 +6,7 @@
srcs = [
'interpolation.cc',
],
+ visibility = ['//visibility:public'],
)
cc_test(
diff --git a/frc971/shooter_interpolation/interpolation.cc b/frc971/shooter_interpolation/interpolation.cc
index 71989ff..f558acd 100644
--- a/frc971/shooter_interpolation/interpolation.cc
+++ b/frc971/shooter_interpolation/interpolation.cc
@@ -21,9 +21,9 @@
} // namespace
InterpolationTable::InterpolationTable(
- ::std::vector<::std::pair<double, ShotParams>> interpolation_table) {
- interpolation_table_ = ::std::move(interpolation_table);
- ::std::sort(interpolation_table_.begin(), interpolation_table_.end(),
+ const ::std::vector<::std::pair<double, ShotParams>> &table)
+ : table_(table) {
+ ::std::sort(table_.begin(), table_.end(),
[](const ::std::pair<double, ShotParams> &a,
const ::std::pair<double, ShotParams> &b) {
return a.first < b.first;
@@ -33,14 +33,13 @@
ShotParams InterpolationTable::GetShooterData(double distance) {
// Points to to the smallest item such that it->first >= dist, or end() if no
// such item exists.
- auto it =
- std::lower_bound(interpolation_table_.begin(), interpolation_table_.end(),
- distance, [](const ::std::pair<double, ShotParams> &a,
- double dist) { return a.first < dist; });
- if (it == interpolation_table_.begin()) {
+ auto it = ::std::lower_bound(table_.begin(), table_.end(), distance,
+ [](const ::std::pair<double, ShotParams> &a,
+ double dist) { return a.first < dist; });
+ if (it == table_.begin()) {
return it->second;
- } else if (it == interpolation_table_.end()) {
- return interpolation_table_.back().second;
+ } else if (it == table_.end()) {
+ return table_.back().second;
} else {
auto x_a2 = it;
auto x_a1 = it - 1;
diff --git a/frc971/shooter_interpolation/interpolation.h b/frc971/shooter_interpolation/interpolation.h
index a40993a..c66b6cc 100644
--- a/frc971/shooter_interpolation/interpolation.h
+++ b/frc971/shooter_interpolation/interpolation.h
@@ -15,8 +15,9 @@
class InterpolationTable {
public:
+ InterpolationTable() = default;
InterpolationTable(
- ::std::vector<::std::pair<double, ShotParams>> interpolation_table);
+ const ::std::vector<::std::pair<double, ShotParams>> &table);
// Uses the interpolation table to calculate the optimal shooter angle and
// power for a shot
@@ -24,7 +25,7 @@
private:
// Contains the list of angle entries in the interpolation table
- ::std::vector<::std::pair<double, ShotParams>> interpolation_table_;
+ ::std::vector<::std::pair<double, ShotParams>> table_;
};
} // namespace shooter_interpolation
diff --git a/y2017/BUILD b/y2017/BUILD
index a6a0f0b..11b965e 100644
--- a/y2017/BUILD
+++ b/y2017/BUILD
@@ -15,6 +15,7 @@
'//aos/common:mutex',
'//aos/common:once',
'//frc971:constants',
+ '//frc971/shooter_interpolation:interpolation',
'//y2017/control_loops/drivetrain:polydrivetrain_plants',
'//y2017/control_loops/superstructure/column:column_plants',
'//y2017/control_loops/superstructure/hood:hood_plants',
diff --git a/y2017/constants.cc b/y2017/constants.cc
index 536a072..d0e5c6f 100644
--- a/y2017/constants.cc
+++ b/y2017/constants.cc
@@ -64,6 +64,7 @@
Values::Intake *const intake = &r->intake;
Values::Hood *const hood = &r->hood;
Values::Column *const column = &r->column;
+ auto shot_interpolation_table = &r->shot_interpolation_table;
r->drivetrain_max_speed = 5;
@@ -85,6 +86,15 @@
hood->zeroing.index_difference = Values::kHoodEncoderIndexDifference;
hood->zeroing.known_index_pulse = 0;
+ // TODO(phil): Should these be different per robot?
+ *shot_interpolation_table =
+ ::frc971::shooter_interpolation::InterpolationTable(
+ {// { distance_to_target, { shot_angle, shot_power }},
+ {100.1, {20.0 * M_PI / 180.0, 335.0}},
+ {150.2, {35.0 * M_PI / 180.0, 384.0}},
+ {200.3, {40.0 * M_PI / 180.0, 417.0}},
+ });
+
switch (team) {
// A set of constants for tests.
case 1:
diff --git a/y2017/constants.h b/y2017/constants.h
index 1d6eede..c6aa70c 100644
--- a/y2017/constants.h
+++ b/y2017/constants.h
@@ -5,6 +5,7 @@
#include <math.h>
#include "frc971/constants.h"
+#include "frc971/shooter_interpolation/interpolation.h"
#include "y2017/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
#include "y2017/control_loops/superstructure/column/column_plant.h"
@@ -125,6 +126,8 @@
const char *vision_name;
double vision_error;
+
+ ::frc971::shooter_interpolation::InterpolationTable shot_interpolation_table;
};
// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and