full test of the zeroing
diff --git a/frc971/constants.cc b/frc971/constants.cc
index 4fea843..bf07022 100755
--- a/frc971/constants.cc
+++ b/frc971/constants.cc
@@ -41,9 +41,7 @@
const double shooter_zeroing_off_speed = 0.0;
const double shooter_zeroing_speed = 0.1;
-const Values *DoGetValues() {
- uint16_t team = ::aos::network::GetTeamNumber();
- LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
+const Values *DoGetValuesForTeam(uint16_t team) {
switch (team) {
case 1: // for tests
return new Values{
@@ -154,6 +152,12 @@
}
}
+const Values *DoGetValues() {
+ uint16_t team = ::aos::network::GetTeamNumber();
+ LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
+ return DoGetValuesForTeam(team);
+}
+
} // namespace
const Values &GetValues() {
@@ -161,5 +165,9 @@
return *once.Get();
}
+const Values &GetValuesForTeam(uint16_t team_number) {
+ return *(DoGetValuesForTeam(team_number));
+}
+
} // namespace constants
} // namespace frc971
diff --git a/frc971/constants.h b/frc971/constants.h
index 3416a39..d933e29 100755
--- a/frc971/constants.h
+++ b/frc971/constants.h
@@ -103,6 +103,7 @@
// Creates (once) a Values instance and returns a reference to it.
const Values &GetValues();
+const Values &GetValuesForTeam(uint16_t team_number);
} // namespace constants
} // namespace frc971
diff --git a/frc971/control_loops/shooter/shooter.cc b/frc971/control_loops/shooter/shooter.cc
index 8f435fb..164b9f9 100755
--- a/frc971/control_loops/shooter/shooter.cc
+++ b/frc971/control_loops/shooter/shooter.cc
@@ -172,9 +172,11 @@
// Use the controller without the spring if the latch is set and the
// plunger is back
shooter_.set_controller_index(1);
+ LOG(DEBUG, "Using controller 1\n");
} else {
// Otherwise use the controller with the spring.
shooter_.set_controller_index(0);
+ LOG(DEBUG, "Using controller 0\n");
}
if (shooter_.controller_index() != last_controller_index) {
shooter_.RecalculatePowerGoal();
@@ -568,10 +570,12 @@
if (position) {
last_position_ = *position;
- LOG(DEBUG,
- "pos > absolute: %f velocity: %f state= %d\n",
+ LOG(DEBUG, "pos > absolute: %f velocity: %f state= %d l= %d pp= %d, pd= %d "
+ "p= %d b=%d\n",
shooter_.absolute_position(), shooter_.absolute_velocity(),
- state_);
+ state_, position->latch, position->pusher_proximal.current,
+ position->pusher_distal.current,
+ position->plunger, brake_piston_);
}
if (position) {
last_distal_posedge_count_ = position->pusher_distal.posedge_count;
diff --git a/frc971/control_loops/shooter/shooter_lib_test.cc b/frc971/control_loops/shooter/shooter_lib_test.cc
index 74cb0ec..bc9c7b4 100755
--- a/frc971/control_loops/shooter/shooter_lib_test.cc
+++ b/frc971/control_loops/shooter/shooter_lib_test.cc
@@ -83,7 +83,8 @@
// (encoder, hall effect).
void SetPhysicalSensors(control_loops::ShooterGroup::Position *position) {
const frc971::constants::Values &values = constants::GetValues();
- position->position = GetPosition();
+
+ position->position = GetPosition();
LOG(DEBUG, "Physical shooter at {%f}\n", GetAbsolutePosition());
@@ -134,14 +135,31 @@
}
}
- // Sends out the position queue messages.
void SendPositionMessage() {
+ // the first bool is false
+ SendPositionMessage(false, false, false, false);
+ }
+
+ // Sends out the position queue messages.
+ // if the first bool is false then this is
+ // just the default state, otherwise will force
+ // it into a state using the passed values
+ void SendPositionMessage(bool use_passed, bool plunger_in,
+ bool latch_in, bool brake_in) {
const frc971::constants::Values &values = constants::GetValues();
::aos::ScopedMessagePtr<control_loops::ShooterGroup::Position> position =
shooter_queue_group_.position.MakeMessage();
SetPhysicalSensors(position.get());
+ if (use_passed) {
+ position->plunger = plunger_in;
+ plunger_latched_ = latch_in && plunger_in;
+ position->latch = latch_in;
+ latch_piston_state_ = latch_in;
+ brake_piston_state_ = brake_in;
+ }
+
position->latch = latch_piston_state_;
// Handle pusher distal hall effect
@@ -272,6 +290,7 @@
};
class ShooterTest : public ::testing::Test {
+
protected:
::aos::common::testing::GlobalCoreInstance my_core;
@@ -602,10 +621,53 @@
EXPECT_EQ(ShooterMotor::STATE_READY, shooter_motor_.state());
}
+class ShooterZeroingTest : public ShooterTest,
+ public ::testing::WithParamInterface<
+ ::std::tr1::tuple<bool, bool, bool, double>> {};
+
+TEST_P(ShooterZeroingTest, AllDisparateStartingZero) {
+ bool latch = ::std::tr1::get<0>(GetParam());
+ bool brake = ::std::tr1::get<1>(GetParam());
+ bool plunger_back = ::std::tr1::get<2>(GetParam());
+ double start_pos = ::std::tr1::get<3>(GetParam());
+ // flag to initialize test
+ printf("@@@@ l= %d b= %d p= %d s= %.3f\n",
+ latch, brake, plunger_back, start_pos);
+ bool init = false;
+ Reinitialize(start_pos);
+ shooter_queue_group_.goal.MakeWithBuilder().shot_power(0.25).Send();
+ for (int i = 0; i < 200; ++i) {
+ shooter_motor_plant_.SendPositionMessage(!init, plunger_back, latch, brake);
+ init = true;
+ shooter_motor_.Iterate();
+ shooter_motor_plant_.Simulate();
+ SendDSPacket(true);
+ }
+ // EXPECT_NEAR(0.0, shooter_motor_.GetPosition(), 0.01);
+ double pos = shooter_motor_plant_.GetAbsolutePosition();
+ ASSERT_NEAR(shooter_queue_group_.goal->shot_power, pos, 0.05);
+ ASSERT_EQ(ShooterMotor::STATE_READY, shooter_motor_.state());
+}
+
+INSTANTIATE_TEST_CASE_P(
+ ShooterZeroingTest, ShooterZeroingTest,
+ ::testing::Combine(
+ ::testing::Bool(), ::testing::Bool(), ::testing::Bool(),
+ ::testing::Values(
+ 0.05, constants::GetValuesForTeam(971).shooter.upper_limit - 0.05,
+ HallEffectMiddle(constants::GetValuesForTeam(971)
+ .shooter.pusher_proximal),
+ HallEffectMiddle(constants::GetValuesForTeam(971)
+ .shooter.pusher_distal),
+ constants::GetValuesForTeam(971).shooter.latch_max_safe_position -
+ 0.001)));
+
// TODO(austin): Slip the encoder somewhere.
// TODO(austin): Test all the timeouts...
+// TODO(austin): Starting all the way up just failed?? that seems tlike same state as starting anywhere up??
+
} // namespace testing
} // namespace control_loops
} // namespace frc971