Skip to content

Commit 7764341

Browse files
authored
Merge pull request #142 from CU-Robotics/feature-agnostic-feeder
Feature agnostic feeder
2 parents 9ba387e + bb626a3 commit 7764341

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/controls/controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,5 @@ void NewFeederController::step(float reference[STATE_LEN][3], float estimate[STA
321321
// float outputv = pidv.filter(dt, true, false);
322322
// float output = outputp + outputv;
323323

324-
outputs[0] = -outputp;
324+
outputs[0] = outputp * gear_ratios[0]; // negative because the feeder motor is reversed
325325
}

src/controls/estimator.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ void LocalEstimator::step_states(float output[CAN_MAX_MOTORS][MICRO_STATE_LEN],
546546

547547
NewFeederEstimator::NewFeederEstimator(CANManager* _can, SensorManager* _sensor_manager, Config config_data) {
548548
feeder_offset = config_data.sensor_info[10][2];
549+
feeder_direction = config_data.sensor_info[10][3];
550+
feeder_ratio = config_data.sensor_info[10][4];
549551
micro_estimator = false;
550552
can = _can;
551553
sensor_manager = _sensor_manager;
@@ -560,18 +562,22 @@ void NewFeederEstimator::step_states(float output[CAN_MAX_MOTORS][MICRO_STATE_LE
560562
if (count == 0) {
561563
Serial.printf("prev_feeder_angle %f\n",prev_feeder_angle);
562564
dt = 0; // first dt loop generates huge time so check for that
563-
diff = fmod((feeder_angle - feeder_offset), (float)(M_PI / 2.0)) ;
565+
diff = fmod((feeder_angle - feeder_offset), (float)(M_PI / feeder_ratio)) ;
564566
count++;
565567
} else {
566568
diff = feeder_angle - prev_feeder_angle;
567569
}
570+
568571
prev_feeder_angle = feeder_angle;
569572
if (diff > PI) diff -= 2 * PI;
570573
else if (diff < -PI) diff += 2 * PI;
571-
float feeder_velocity = (dt > 0) ? (diff/(M_PI/2.0))/dt : 0;
572-
ball_count += diff/(M_PI/2.0);
573-
output[0][0] = ball_count;
574-
output[0][1] = feeder_velocity;
574+
575+
float feeder_velocity = (dt > 0) ? (diff/(M_PI/feeder_ratio))/dt : 0;
576+
577+
ball_count += diff/(M_PI/feeder_ratio);
578+
output[0][0] = ball_count * feeder_direction; // ball count
579+
output[0][1] = feeder_velocity * feeder_direction; // ball velocity
575580
output[0][2] = feeder_angle; // this is not the acceleration just the encoder value for debugging
581+
576582
}
577583

src/controls/estimator.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ struct NewFeederEstimator : public Estimator {
561561
int count = 0;
562562
/// @brief feeder encoder offset for improving feeder delay
563563
float feeder_offset = 0;
564+
/// @brief feeder direction multiplier
565+
/// @note 1 for normal direction, -1 for reverse direction
566+
float feeder_direction = 1;
567+
/// @brief gear ratio of the feeder
568+
float feeder_ratio = 1;
564569
public:
565570
/// @brief Make new local estimator and set can data pointer and num states
566571
/// @param can can pointer from EstimatorManager

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ int main() {
433433
can.issue_safety_mode();
434434
governor.set_reference_at_index(temp_state[6][0], 6, 0);
435435
feed = temp_state[6][0]; // reset feed to the current state
436+
last_feed = feed; // reset last feed to the current state
436437
// Serial.printf("Can zero\n");
437438
}
438439

0 commit comments

Comments
 (0)