Remove Potentiometer from Intake Pivot
Changed the intake pivot from a pot and absolute
encoder subsystem to just an absolute encoder subsystem
Signed-off-by: Niko Sohmers <nikolai@sohmers.com>
Change-Id: I9440cc1716420ca22c776db22e7694f2c1448aeb
diff --git a/y2024/constants.h b/y2024/constants.h
index 8eac0c9..1d0f5d3 100644
--- a/y2024/constants.h
+++ b/y2024/constants.h
@@ -59,13 +59,6 @@
return (16.0 / 64.0) * (18.0 / 62.0);
}
- static constexpr double kIntakePivotPotRatio() { return 16.0 / 64.0; }
-
- static constexpr double kIntakePivotPotRadiansPerVolt() {
- return kIntakePivotPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) *
- (2 * M_PI /*radians*/);
- }
-
static constexpr double kMaxIntakePivotEncoderPulsesPerSecond() {
return control_loops::superstructure::intake_pivot::kFreeSpeed /
(2.0 * M_PI) *
@@ -102,6 +95,12 @@
subsystem_params;
double potentiometer_offset;
};
+
+ struct AbsoluteEncoderConstants {
+ ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
+ ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
+ subsystem_params;
+ };
};
// Creates and returns a Values instance for the constants.
diff --git a/y2024/constants/7971.json b/y2024/constants/7971.json
index 9e6bafb..d2e766a 100644
--- a/y2024/constants/7971.json
+++ b/y2024/constants/7971.json
@@ -3,15 +3,12 @@
{
"robot": {
- "intake_constants": {
- {% set _ = intake_pivot_zero.update(
- {
- "measured_absolute_position" : 0.0
- }
- ) %}
- "zeroing_constants": {{ intake_pivot_zero | tojson(indent=2)}},
- "potentiometer_offset": 0.0
- },
+ {% set _ = intake_pivot_zero.update(
+ {
+ "measured_absolute_position" : 0.0
+ }
+ ) %}
+ "intake_constants": {{ intake_pivot_zero | tojson(indent=2)}},
"climber_constants": {
{% set _ = climber_zero.update(
{
diff --git a/y2024/constants/971.json b/y2024/constants/971.json
index 641783f..9ab6ad6 100644
--- a/y2024/constants/971.json
+++ b/y2024/constants/971.json
@@ -8,15 +8,12 @@
}
],
"robot": {
- "intake_constants": {
- {% set _ = intake_pivot_zero.update(
- {
- "measured_absolute_position" : 0.0
- }
- ) %}
- "zeroing_constants": {{ intake_pivot_zero | tojson(indent=2)}},
- "potentiometer_offset": 0.0
- },
+ {% set _ = intake_pivot_zero.update(
+ {
+ "measured_absolute_position" : 0.0
+ }
+ ) %}
+ "intake_constants": {{ intake_pivot_zero | tojson(indent=2)}},
"climber_constants": {
{% set _ = climber_zero.update(
{
diff --git a/y2024/constants/9971.json b/y2024/constants/9971.json
index 9e6bafb..d2e766a 100644
--- a/y2024/constants/9971.json
+++ b/y2024/constants/9971.json
@@ -3,15 +3,12 @@
{
"robot": {
- "intake_constants": {
- {% set _ = intake_pivot_zero.update(
- {
- "measured_absolute_position" : 0.0
- }
- ) %}
- "zeroing_constants": {{ intake_pivot_zero | tojson(indent=2)}},
- "potentiometer_offset": 0.0
- },
+ {% set _ = intake_pivot_zero.update(
+ {
+ "measured_absolute_position" : 0.0
+ }
+ ) %}
+ "intake_constants": {{ intake_pivot_zero | tojson(indent=2)}},
"climber_constants": {
{% set _ = climber_zero.update(
{
diff --git a/y2024/constants/constants.fbs b/y2024/constants/constants.fbs
index 40d609f..2aaac3e 100644
--- a/y2024/constants/constants.fbs
+++ b/y2024/constants/constants.fbs
@@ -71,9 +71,8 @@
}
table RobotConstants {
- intake_constants:PotAndAbsEncoderConstants (id: 0);
+ intake_constants:frc971.zeroing.AbsoluteEncoderZeroingConstants (id: 0);
climber_constants:PotAndAbsEncoderConstants (id: 1);
-
}
// Common table for constants unrelated to the robot
diff --git a/y2024/constants/test_data/test_team.json b/y2024/constants/test_data/test_team.json
index 9e6bafb..d2e766a 100644
--- a/y2024/constants/test_data/test_team.json
+++ b/y2024/constants/test_data/test_team.json
@@ -3,15 +3,12 @@
{
"robot": {
- "intake_constants": {
- {% set _ = intake_pivot_zero.update(
- {
- "measured_absolute_position" : 0.0
- }
- ) %}
- "zeroing_constants": {{ intake_pivot_zero | tojson(indent=2)}},
- "potentiometer_offset": 0.0
- },
+ {% set _ = intake_pivot_zero.update(
+ {
+ "measured_absolute_position" : 0.0
+ }
+ ) %}
+ "intake_constants": {{ intake_pivot_zero | tojson(indent=2)}},
"climber_constants": {
{% set _ = climber_zero.update(
{
diff --git a/y2024/control_loops/superstructure/superstructure.cc b/y2024/control_loops/superstructure/superstructure.cc
index 18db6d6..1d7c5b5 100644
--- a/y2024/control_loops/superstructure/superstructure.cc
+++ b/y2024/control_loops/superstructure/superstructure.cc
@@ -31,9 +31,8 @@
joystick_state_fetcher_(
event_loop->MakeFetcher<aos::JoystickState>("/aos")),
transfer_goal_(TransferRollerGoal::NONE),
- intake_pivot_(
- robot_constants_->common()->intake_pivot(),
- robot_constants_->robot()->intake_constants()->zeroing_constants()),
+ intake_pivot_(robot_constants_->common()->intake_pivot(),
+ robot_constants_->robot()->intake_constants()),
climber_(
robot_constants_->common()->climber(),
robot_constants_->robot()->climber_constants()->zeroing_constants()) {
@@ -153,7 +152,7 @@
const frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal
*intake_pivot_goal = &intake_pivot_goal_buffer.message();
- const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus>
+ const flatbuffers::Offset<AbsoluteEncoderProfiledJointStatus>
intake_pivot_status_offset = intake_pivot_.Iterate(
intake_pivot_goal, position->intake_pivot(),
output != nullptr ? &output_struct.intake_pivot_voltage : nullptr,
diff --git a/y2024/control_loops/superstructure/superstructure.h b/y2024/control_loops/superstructure/superstructure.h
index 88db2e2..f85e0fc 100644
--- a/y2024/control_loops/superstructure/superstructure.h
+++ b/y2024/control_loops/superstructure/superstructure.h
@@ -21,6 +21,11 @@
class Superstructure
: public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
public:
+ using AbsoluteEncoderSubsystem =
+ ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
+ ::frc971::zeroing::AbsoluteEncoderZeroingEstimator,
+ ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>;
+
using PotAndAbsoluteEncoderSubsystem =
::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
@@ -30,7 +35,7 @@
std::shared_ptr<const constants::Values> values,
const ::std::string &name = "/superstructure");
- inline const PotAndAbsoluteEncoderSubsystem &intake_pivot() const {
+ inline const AbsoluteEncoderSubsystem &intake_pivot() const {
return intake_pivot_;
}
@@ -56,8 +61,9 @@
aos::Alliance alliance_ = aos::Alliance::kInvalid;
TransferRollerGoal transfer_goal_;
- PotAndAbsoluteEncoderSubsystem intake_pivot_;
+ AbsoluteEncoderSubsystem intake_pivot_;
PotAndAbsoluteEncoderSubsystem climber_;
+
DISALLOW_COPY_AND_ASSIGN(Superstructure);
};
diff --git a/y2024/control_loops/superstructure/superstructure_lib_test.cc b/y2024/control_loops/superstructure/superstructure_lib_test.cc
index 8020a4d..4b4ac8d 100644
--- a/y2024/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2024/control_loops/superstructure/superstructure_lib_test.cc
@@ -33,11 +33,16 @@
using DrivetrainStatus = ::frc971::control_loops::drivetrain::Status;
typedef Superstructure::PotAndAbsoluteEncoderSubsystem
PotAndAbsoluteEncoderSubsystem;
+typedef Superstructure::AbsoluteEncoderSubsystem AbsoluteEncoderSubsystem;
using PotAndAbsoluteEncoderSimulator =
frc971::control_loops::SubsystemSimulator<
frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus,
PotAndAbsoluteEncoderSubsystem::State,
constants::Values::PotAndAbsEncoderConstants>;
+using AbsoluteEncoderSimulator = frc971::control_loops::SubsystemSimulator<
+ frc971::control_loops::AbsoluteEncoderProfiledJointStatus,
+ AbsoluteEncoderSubsystem::State,
+ constants::Values::AbsoluteEncoderConstants>;
class SuperstructureSimulation {
public:
@@ -57,21 +62,14 @@
new CappedTestPlant(intake_pivot::MakeIntakePivotPlant()),
PositionSensorSimulator(simulated_robot_constants->robot()
->intake_constants()
- ->zeroing_constants()
->one_revolution_distance()),
{.subsystem_params =
{simulated_robot_constants->common()->intake_pivot(),
- simulated_robot_constants->robot()
- ->intake_constants()
- ->zeroing_constants()},
- .potentiometer_offset = simulated_robot_constants->robot()
- ->intake_constants()
- ->potentiometer_offset()},
+ simulated_robot_constants->robot()->intake_constants()}},
frc971::constants::Range::FromFlatbuffer(
simulated_robot_constants->common()->intake_pivot()->range()),
simulated_robot_constants->robot()
->intake_constants()
- ->zeroing_constants()
->measured_absolute_position(),
dt_),
climber_(new CappedTestPlant(climber::MakeClimberPlant()),
@@ -127,9 +125,9 @@
::aos::Sender<Position>::Builder builder =
superstructure_position_sender_.MakeBuilder();
- frc971::PotAndAbsolutePosition::Builder intake_pivot_builder =
- builder.MakeBuilder<frc971::PotAndAbsolutePosition>();
- flatbuffers::Offset<frc971::PotAndAbsolutePosition> intake_pivot_offset =
+ frc971::AbsolutePosition::Builder intake_pivot_builder =
+ builder.MakeBuilder<frc971::AbsolutePosition>();
+ flatbuffers::Offset<frc971::AbsolutePosition> intake_pivot_offset =
intake_pivot_.encoder()->GetSensorValues(&intake_pivot_builder);
frc971::PotAndAbsolutePosition::Builder climber_builder =
@@ -151,7 +149,7 @@
transfer_beambreak_ = triggered;
}
- PotAndAbsoluteEncoderSimulator *intake_pivot() { return &intake_pivot_; }
+ AbsoluteEncoderSimulator *intake_pivot() { return &intake_pivot_; }
PotAndAbsoluteEncoderSimulator *climber() { return &climber_; }
@@ -166,7 +164,7 @@
bool transfer_beambreak_;
- PotAndAbsoluteEncoderSimulator intake_pivot_;
+ AbsoluteEncoderSimulator intake_pivot_;
PotAndAbsoluteEncoderSimulator climber_;
bool first_ = true;
@@ -223,6 +221,8 @@
superstructure_status_fetcher_.Fetch();
superstructure_output_fetcher_.Fetch();
+ ASSERT_FALSE(superstructure_status_fetcher_->estopped());
+
ASSERT_TRUE(superstructure_goal_fetcher_.get() != nullptr) << ": No goal";
ASSERT_TRUE(superstructure_status_fetcher_.get() != nullptr)
<< ": No status";
@@ -389,7 +389,6 @@
// Give it a lot of time to get there.
RunFor(chrono::seconds(15));
-
VerifyNearGoal();
}
@@ -435,7 +434,7 @@
WaitUntilZeroed();
RunFor(chrono::seconds(2));
- EXPECT_EQ(PotAndAbsoluteEncoderSubsystem::State::RUNNING,
+ EXPECT_EQ(AbsoluteEncoderSubsystem::State::RUNNING,
superstructure_.intake_pivot().state());
EXPECT_EQ(PotAndAbsoluteEncoderSubsystem::State::RUNNING,
diff --git a/y2024/control_loops/superstructure/superstructure_position.fbs b/y2024/control_loops/superstructure/superstructure_position.fbs
index cd12da0..1c81332 100644
--- a/y2024/control_loops/superstructure/superstructure_position.fbs
+++ b/y2024/control_loops/superstructure/superstructure_position.fbs
@@ -5,7 +5,7 @@
table Position {
// Values of the encoder and potentiometer at the intake pivot
- intake_pivot:frc971.PotAndAbsolutePosition (id: 0);
+ intake_pivot:frc971.AbsolutePosition (id: 0);
// Values of the encoder and potentiometer at the turret
turret:frc971.PotAndAbsolutePosition (id: 1);
diff --git a/y2024/control_loops/superstructure/superstructure_status.fbs b/y2024/control_loops/superstructure/superstructure_status.fbs
index cd727ac..24b0e17 100644
--- a/y2024/control_loops/superstructure/superstructure_status.fbs
+++ b/y2024/control_loops/superstructure/superstructure_status.fbs
@@ -39,7 +39,7 @@
intake_roller_state:IntakeRollerState (id: 2);
// Estimated angle and angular velocitiy of the intake.
- intake_pivot_state:frc971.control_loops.PotAndAbsoluteEncoderProfiledJointStatus (id: 3);
+ intake_pivot_state:frc971.control_loops.AbsoluteEncoderProfiledJointStatus (id: 3);
// State of transfer rollers
transfer_roller_state:TransferRollerState (id: 4);
diff --git a/y2024/wpilib_interface.cc b/y2024/wpilib_interface.cc
index 4a6c00b..c2114de 100644
--- a/y2024/wpilib_interface.cc
+++ b/y2024/wpilib_interface.cc
@@ -77,10 +77,6 @@
constexpr double kMaxBringupPower = 12.0;
-double intake_pot_translate(double voltage) {
- return voltage * Values::kIntakePivotPotRadiansPerVolt();
-}
-
double climber_pot_translate(double voltage) {
return voltage * Values::kClimberPotRadiansPerVolt();
}
@@ -140,11 +136,7 @@
CopyPosition(intake_pivot_encoder_, builder->add_intake_pivot(),
Values::kIntakePivotEncoderCountsPerRevolution(),
- Values::kIntakePivotEncoderRatio(), intake_pot_translate,
- true,
- robot_constants_->robot()
- ->intake_constants()
- ->potentiometer_offset());
+ Values::kIntakePivotEncoderRatio(), /* reversed: */ false);
CopyPosition(climber_encoder_, builder->add_climber(),
Values::kClimberEncoderCountsPerRevolution(),
@@ -212,12 +204,10 @@
}
void set_intake_pivot(::std::unique_ptr<frc::Encoder> encoder,
- ::std::unique_ptr<frc::DigitalInput> absolute_pwm,
- ::std::unique_ptr<frc::AnalogInput> potentiometer) {
+ ::std::unique_ptr<frc::DigitalInput> absolute_pwm) {
fast_encoder_filter_.Add(encoder.get());
intake_pivot_encoder_.set_encoder(::std::move(encoder));
intake_pivot_encoder_.set_absolute_pwm(::std::move(absolute_pwm));
- intake_pivot_encoder_.set_potentiometer(::std::move(potentiometer));
}
void set_transfer_beambreak(::std::unique_ptr<frc::DigitalInput> sensor) {
@@ -246,7 +236,7 @@
std::unique_ptr<frc::DigitalInput> imu_yaw_rate_input_, transfer_beam_break_;
- frc971::wpilib::AbsoluteEncoderAndPotentiometer intake_pivot_encoder_;
+ frc971::wpilib::AbsoluteEncoder intake_pivot_encoder_;
frc971::wpilib::AbsoluteEncoderAndPotentiometer climber_encoder_;
frc971::wpilib::DMAPulseWidthReader imu_yaw_rate_reader_;
@@ -290,8 +280,7 @@
sensor_reader.set_yaw_rate_input(make_unique<frc::DigitalInput>(0));
// TODO: (niko) change values once robot is wired
sensor_reader.set_intake_pivot(make_encoder(4),
- make_unique<frc::DigitalInput>(4),
- make_unique<frc::AnalogInput>(4));
+ make_unique<frc::DigitalInput>(4));
sensor_reader.set_transfer_beambreak(make_unique<frc::DigitalInput>(7));
sensor_reader.set_climber(make_encoder(5),