Refactor constants
Everything is layed out so you can actually read them (kind of) now.
Change-Id: I7e042c2257a8271c08fa94d46bfd2ea846c90c38
diff --git a/y2017/constants.cc b/y2017/constants.cc
index e636f95..05eca31 100644
--- a/y2017/constants.cc
+++ b/y2017/constants.cc
@@ -25,126 +25,86 @@
namespace y2017 {
namespace constants {
-// ///// Mutual constants between robots. /////
const int Values::kZeroingSampleSize;
-constexpr double Values::kDrivetrainEncoderRatio, Values::kShooterEncoderRatio,
- Values::kIntakeEncoderRatio, Values::kIntakePotRatio,
- Values::kHoodEncoderRatio, Values::kHoodPotRatio,
- Values::kTurretEncoderRatio, Values::kTurretPotRatio,
- Values::kIndexerEncoderRatio, Values::kIntakeEncoderIndexDifference,
- Values::kIndexerEncoderIndexDifference,
- Values::kTurretEncoderIndexDifference, Values::kHoodEncoderIndexDifference;
-constexpr ::frc971::constants::Range Values::kIntakeRange, Values::kHoodRange,
- Values::kTurretRange;
+constexpr double Values::kDrivetrainEncoderRatio;
+
+constexpr double Values::kShooterEncoderRatio;
+
+constexpr double Values::kIntakeEncoderRatio, Values::kIntakePotRatio,
+ Values::kIntakeEncoderIndexDifference;
+constexpr ::frc971::constants::Range Values::kIntakeRange;
+
+constexpr double Values::kHoodEncoderRatio, Values::kHoodPotRatio,
+ Values::kHoodEncoderIndexDifference;
+constexpr ::frc971::constants::Range Values::kHoodRange;
+
+constexpr double Values::kTurretEncoderRatio, Values::kTurretPotRatio,
+ Values::kTurretEncoderIndexDifference;
+constexpr ::frc971::constants::Range Values::kTurretRange;
+
+constexpr double Values::kIndexerEncoderRatio,
+ Values::kIndexerEncoderIndexDifference;
namespace {
+
const uint16_t kCompTeamNumber = 971;
const uint16_t kPracticeTeamNumber = 9971;
-// ///// Dynamic constants. /////
-
const Values *DoGetValuesForTeam(uint16_t team) {
+ Values *const r = new Values();
+ Values::Intake *const intake = &r->intake;
+ Values::Turret *const turret = &r->turret;
+ Values::Hood *const hood = &r->hood;
+
+ r->drivetrain_max_speed = 5;
+
+ intake->zeroing.average_filter_size = Values::kZeroingSampleSize;
+ intake->zeroing.index_difference = Values::kIntakeEncoderIndexDifference;
+ intake->zeroing.measured_index_position = 0;
+ intake->zeroing.allowable_encoder_error = 0.3;
+
+ turret->zeroing.average_filter_size = Values::kZeroingSampleSize;
+ turret->zeroing.index_difference = Values::kTurretEncoderIndexDifference;
+ turret->zeroing.measured_index_position = 0;
+ turret->zeroing.allowable_encoder_error = 0.3;
+
+ hood->zeroing.average_filter_size = Values::kZeroingSampleSize;
+ hood->zeroing.index_difference = Values::kHoodEncoderIndexDifference;
+ hood->zeroing.measured_index_position = 0.1;
+ hood->zeroing.allowable_encoder_error = 0.3;
+
switch (team) {
- case 1: // for tests
- return new Values{
- 5.0, // drivetrain max speed
-
- // Intake
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize,
- Values::kIntakeEncoderIndexDifference, 0.0, 0.3},
- },
-
- // Turret
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize,
- Values::kTurretEncoderIndexDifference, 0.0, 0.3},
- },
-
- // Hood
- {
- // Pot Offset
- 0.1,
- {Values::kZeroingSampleSize, Values::kHoodEncoderIndexDifference,
- 0.1, 0.3},
- },
- 0.0, // down error
- "practice",
- };
+ // A set of constants for tests.
+ case 1:
+ intake->pot_offset = 0;
+ turret->pot_offset = 0;
+ hood->pot_offset = 0.1;
+ r->down_error = 0;
+ r->vision_name = "test";
break;
case kCompTeamNumber:
- return new Values{
- 5.0, // drivetrain max speed
-
- // Intake
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize,
- Values::kIntakeEncoderIndexDifference, 0.0, 0.3},
- },
-
- // Turret
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize,
- Values::kTurretEncoderIndexDifference, 0.0, 0.3},
- },
-
- // Hood
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize, Values::kHoodEncoderIndexDifference,
- 0.0, 0.3},
- },
- 0.0, // down error
- "competition",
- };
+ intake->pot_offset = 0;
+ turret->pot_offset = 0;
+ hood->pot_offset = 0.1;
+ r->down_error = 0;
+ r->vision_name = "competition";
break;
case kPracticeTeamNumber:
- return new Values{
- 5.0, // drivetrain max speed
-
- // Intake
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize,
- Values::kIntakeEncoderIndexDifference, 0.0, 0.3},
- },
-
- // Turret
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize,
- Values::kTurretEncoderIndexDifference, 0.0, 0.3},
- },
-
- // Hood
- {
- // Pot Offset
- 0.0,
- {Values::kZeroingSampleSize, Values::kHoodEncoderIndexDifference,
- 0.0, 0.3},
- },
- 0.0, // down error
- "practice",
- };
+ intake->pot_offset = 0;
+ turret->pot_offset = 0;
+ hood->pot_offset = 0.1;
+ r->down_error = 0;
+ r->vision_name = "practice";
break;
default:
LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
}
+
+ return r;
}
const Values *DoGetValues() {
diff --git a/y2017/constants.h b/y2017/constants.h
index 92df517..20fcb56 100644
--- a/y2017/constants.h
+++ b/y2017/constants.h
@@ -9,90 +9,97 @@
namespace y2017 {
namespace constants {
-// Has all of the numbers that change for both robots and makes it easy to
-// retrieve the values for the current one.
+// Has all of our "constants", except the ones that come from other places. The
+// ones which change between robots are put together with a workable way to
+// retrieve the values for the current robot.
// Everything is in SI units (volts, radians, meters, seconds, etc).
// Some of these values are related to the conversion between raw values
// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
+//
+// All ratios are from the encoder shaft to the output units.
-// This structure contains current values for all of the things that change.
struct Values {
- // ///// Mutual constants between robots. /////
// TODO(constants): Update/check these with what we're using this year.
- static const int kZeroingSampleSize = 200;
-
- // The ratio from the encoder shaft to the drivetrain wheels.
-
- static constexpr double kDrivetrainEncoderRatio = 1.0 ;
-
- // Ratios for our subsystems.
- static constexpr double kShooterEncoderRatio = 32.0 / 48.0; //Encoder rotation to shooter wheel revolution
- static constexpr double kIntakeEncoderRatio = (16 * 0.25) * (20 / 40) / (2.0 * numpy.pi) * 0.0254; //Encoder rotation per Meter(inch per radian) of movement
- static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * numpy.pi) * 0.0254; //Pot Rotation per Meter(inch per radian) of movement
- static constexpr double kHoodEncoderRatio = 20.0 / 345.0; //Encoder rotation to Hood rotation
- static constexpr double kHoodPotRatio = 20.0 / 345.0; //Pot Rotation per Hood rotation
- static constexpr double kTurretEncoderRatio = 16.0 / 92.0; //Encoder rotation toTurret rotation
- static constexpr double kTurretPotRatio = 16.0 / 92.0; //Pot Rotation per Turret rotation
- static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0); //Encoder rotation to Inner indexer rotation
-
- // Difference in radians between index pulses.
- static constexpr double kIntakeEncoderIndexDifference =
- 2.0 * M_PI * kIntakeEncoderRatio;
- static constexpr double kIndexerEncoderIndexDifference =
- 2.0 * M_PI * kIndexerEncoderRatio;
- static constexpr double kTurretEncoderIndexDifference =
- 2.0 * M_PI * kTurretEncoderRatio;
- static constexpr double kHoodEncoderIndexDifference =
- 2.0 * M_PI * kHoodEncoderRatio;
-
- static constexpr ::frc971::constants::Range kIntakeRange{
- // Lower hard stop in meters(inches)
- -0.600 * 0.0254,
- // Upper hard stop
- 8.655 * 0.0254,
- // Lower soft stop
- 0.000,
- // Upper soft stop
- 8.530 * 0.0254};
- static constexpr ::frc971::constants::Range kHoodRange{
- // Lower hard stop in radians
- -1.0 / 345.0 * 2.0 * M_PI,
- // Upper hard stop in radians
- 39.0 / 345.0 * 2.0 * M_PI,
- // Lower soft stop in radians
- 0.0,
- // Upper soft stop in radians
- (39.0 - 1.0) / 345.0 * 2.0 * M_PI};
- static constexpr ::frc971::constants::Range kTurretRange{
- // Lower hard stop in radians
- -460.0 / 2.0 * M_PI / 180.0,
- // Upper hard stop in radians
- 460.0 / 2.0 * M_PI / 180.0,
- // Lower soft stop in radians
- -450.0 / 2.0 * M_PI / 180.0,
- // Upper soft stop in radians
- 450.0 / 2.0 * M_PI / 180.0};
- // ///// Dynamic constants. /////
- double drivetrain_max_speed;
-
struct Intake {
double pot_offset;
::frc971::constants::PotAndIndexPulseZeroingConstants zeroing;
};
- Intake intake;
struct Turret {
double pot_offset;
::frc971::constants::PotAndIndexPulseZeroingConstants zeroing;
};
- Turret turret;
struct Hood {
double pot_offset;
::frc971::constants::PotAndIndexPulseZeroingConstants zeroing;
};
+
+ static const int kZeroingSampleSize = 200;
+
+ // TODO(Brian): This isn't all the way to the output yet.
+ static constexpr double kDrivetrainEncoderRatio = 1.0 ;
+
+ static constexpr double kShooterEncoderRatio = 32.0 / 48.0;
+
+ static constexpr double kIntakeEncoderRatio =
+ (16.0 * 0.25) * (20.0 / 40.0) / (2.0 * M_PI) * 0.0254;
+ static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * M_PI) * 0.0254;
+ static constexpr double kIntakeEncoderIndexDifference =
+ 2.0 * M_PI * kIntakeEncoderRatio;
+
+ static constexpr ::frc971::constants::Range kIntakeRange{
+ // Lower hard stop in meters (from inches).
+ -0.600 * 0.0254,
+ // Upper hard stop in meters (from inches).
+ 8.655 * 0.0254,
+ // Lower soft stop in meters (from inches).
+ 0.000,
+ // Upper soft stop in meters (from inches).
+ 8.530 * 0.0254};
+
+ static constexpr double kHoodEncoderRatio = 20.0 / 345.0;
+ static constexpr double kHoodPotRatio = 20.0 / 345.0;
+ static constexpr double kHoodEncoderIndexDifference =
+ 2.0 * M_PI * kHoodEncoderRatio;
+
+ static constexpr ::frc971::constants::Range kHoodRange{
+ // Lower hard stop in radians.
+ -1.0 / 345.0 * 2.0 * M_PI,
+ // Upper hard stop in radians.
+ 39.0 / 345.0 * 2.0 * M_PI,
+ // Lower soft stop in radians.
+ 0.0,
+ // Upper soft stop in radians.
+ (39.0 - 1.0) / 345.0 * 2.0 * M_PI};
+
+ static constexpr double kTurretEncoderRatio = 16.0 / 92.0;
+ static constexpr double kTurretPotRatio = 16.0 / 92.0;
+ static constexpr double kTurretEncoderIndexDifference =
+ 2.0 * M_PI * kTurretEncoderRatio;
+
+ static constexpr ::frc971::constants::Range kTurretRange{
+ // Lower hard stop in radians.
+ -460.0 / 2.0 * M_PI / 180.0,
+ // Upper hard stop in radians.
+ 460.0 / 2.0 * M_PI / 180.0,
+ // Lower soft stop in radians.
+ -450.0 / 2.0 * M_PI / 180.0,
+ // Upper soft stop in radians.
+ 450.0 / 2.0 * M_PI / 180.0};
+
+ static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0);
+ static constexpr double kIndexerEncoderIndexDifference =
+ 2.0 * M_PI * kIndexerEncoderRatio;
+
+ double drivetrain_max_speed;
+
+ Intake intake;
+
+ Turret turret;
+
Hood hood;
double down_error;