fixed SimpleLogInterval stupidity
diff --git a/aos/common/control_loop/ControlLoop-tmpl.h b/aos/common/control_loop/ControlLoop-tmpl.h
index 032d5fc..3b35949 100644
--- a/aos/common/control_loop/ControlLoop-tmpl.h
+++ b/aos/common/control_loop/ControlLoop-tmpl.h
@@ -26,6 +26,13 @@
template <class T, bool has_position, bool fail_no_position>
void ControlLoop<T, has_position, fail_no_position>::Iterate() {
+ LOG_INTERVAL(no_prior_goal_);
+ LOG_INTERVAL(no_sensor_generation_);
+ LOG_INTERVAL(very_stale_position_);
+ LOG_INTERVAL(no_prior_position_);
+ LOG_INTERVAL(driver_station_old_);
+ LOG_INTERVAL(no_driver_station_);
+
// Fetch the latest control loop goal and position. If there is no new
// goal, we will just reuse the old one.
// If there is no goal, we haven't started up fully. It isn't worth
@@ -35,14 +42,14 @@
// goals.
const GoalType *goal = control_loop_->goal.get();
if (goal == NULL) {
- LOG_INTERVAL(no_prior_goal_);
+ no_prior_goal_.WantToLog();
ZeroOutputs();
return;
}
::bbb::sensor_generation.FetchLatest();
if (::bbb::sensor_generation.get() == nullptr) {
- LOG_INTERVAL(no_sensor_generation_);
+ no_sensor_generation_.WantToLog();
ZeroOutputs();
return;
}
@@ -75,7 +82,7 @@
if (control_loop_->position.get()) {
int msec_age = control_loop_->position.Age().ToMSec();
if (!control_loop_->position.IsNewerThanMS(kPositionTimeoutMs)) {
- LOG_INTERVAL(very_stale_position_);
+ very_stale_position_.WantToLog();
ZeroOutputs();
return;
} else {
@@ -83,7 +90,7 @@
kPositionTimeoutMs);
}
} else {
- LOG_INTERVAL(no_prior_position_);
+ no_prior_position_.WantToLog();
if (fail_no_position) {
ZeroOutputs();
return;
@@ -104,9 +111,9 @@
outputs_enabled = true;
} else {
if (::aos::robot_state.get()) {
- LOG_INTERVAL(driver_station_old_);
+ driver_station_old_.WantToLog();
} else {
- LOG_INTERVAL(no_driver_station_);
+ no_driver_station_.WantToLog();
}
}
diff --git a/aos/common/util/log_interval.h b/aos/common/util/log_interval.h
index 188a16c..71d37ac 100644
--- a/aos/common/util/log_interval.h
+++ b/aos/common/util/log_interval.h
@@ -34,7 +34,7 @@
}
bool ShouldLog() {
const ::aos::time::Time now = ::aos::time::Time::Now();
- const bool r = (now - last_done_) >= interval_;
+ const bool r = (now - last_done_) >= interval_ && count_ > 0;
if (r) {
last_done_ = now;
}
@@ -55,17 +55,19 @@
};
// This one is even easier to use. It always logs with a message "%s %d
-// times\n".
+// times\n". Call WantToLog() like with LogInterval and insert a LOG_INTERVAL
+// call somewhere that will always get run (ie not after a conditional return).
class SimpleLogInterval {
public:
SimpleLogInterval(const ::aos::time::Time &interval, log_level level,
const ::std::string &message)
: interval_(interval), level_(level), message_(message) {}
+ void WantToLog() { interval_.WantToLog(); }
+
#define LOG_INTERVAL(simple_log) \
- simple_log.Hit(LOG_SOURCENAME ": " STRINGIFY(__LINE__))
- void Hit(const char *context) {
- interval_.WantToLog();
+ simple_log.Print(LOG_SOURCENAME ": " STRINGIFY(__LINE__))
+ void Print(const char *context) {
if (interval_.ShouldLog()) {
log_do(level_, "%s: %.*s %d times over %f sec\n", context,
static_cast<int>(message_.size()), message_.data(),
diff --git a/frc971/control_loops/drivetrain/drivetrain.cc b/frc971/control_loops/drivetrain/drivetrain.cc
index e7aae01..c9422cd 100644
--- a/frc971/control_loops/drivetrain/drivetrain.cc
+++ b/frc971/control_loops/drivetrain/drivetrain.cc
@@ -569,9 +569,10 @@
bool bad_pos = false;
if (position == nullptr) {
- LOG_INTERVAL(no_position_);
+ no_position_.WantToLog();
bad_pos = true;
}
+ LOG_INTERVAL(no_position_);
double wheel = goal->steering;
double throttle = goal->throttle;
diff --git a/frc971/output/motor_writer.cc b/frc971/output/motor_writer.cc
index 6f5ee34..9d39fe7 100644
--- a/frc971/output/motor_writer.cc
+++ b/frc971/output/motor_writer.cc
@@ -43,8 +43,9 @@
} else {
DisablePWMOutput(3);
DisablePWMOutput(8);
- LOG_INTERVAL(drivetrain_old_);
+ drivetrain_old_.WantToLog();
}
+ LOG_INTERVAL(drivetrain_old_);
}
{
@@ -59,8 +60,9 @@
} else {
DisablePWMOutput(9);
SetSolenoid(5, false); // engage the brake
- LOG_INTERVAL(shooter_old_);
+ shooter_old_.WantToLog();
}
+ LOG_INTERVAL(shooter_old_);
}
{
@@ -81,8 +83,9 @@
DisablePWMOutput(2);
DisablePWMOutput(4);
DisablePWMOutput(5);
- LOG_INTERVAL(claw_old_);
+ claw_old_.WantToLog();
}
+ LOG_INTERVAL(claw_old_);
}
}