Simplify aos::Init
Most of the variants were to deal with core, which has been gone for a
year. Simplify those all into InitGoogle.
InitGoogle should be renamed to Init at some point. It does everything
now.
Change-Id: I738ee03e9c5b2e6348ef33302835f915df68011f
diff --git a/frc971/analysis/py_log_reader.cc b/frc971/analysis/py_log_reader.cc
index e8843a9..8d3e2a6 100644
--- a/frc971/analysis/py_log_reader.cc
+++ b/frc971/analysis/py_log_reader.cc
@@ -13,11 +13,13 @@
#include <Python.h>
#include <memory>
+#include <errno.h>
#include "aos/configuration.h"
#include "aos/events/logging/logger.h"
#include "aos/events/simulated_event_loop.h"
#include "aos/flatbuffer_merge.h"
+#include "aos/init.h"
#include "aos/json_to_flatbuffer.h"
namespace frc971 {
@@ -75,6 +77,15 @@
}
int LogReader_init(LogReaderType *self, PyObject *args, PyObject *kwds) {
+ int count = 1;
+ if (!aos::IsInitialized()) {
+ // Fake out argc and argv to let InitGoogle run properly to instrument
+ // malloc, setup glog, and such.
+ char *name = program_invocation_name;
+ char **argv = &name;
+ aos::InitGoogle(&count, &argv);
+ }
+
const char *kwlist[] = {"log_file_name", nullptr};
const char *log_file_name;
diff --git a/frc971/autonomous/base_autonomous_actor.cc b/frc971/autonomous/base_autonomous_actor.cc
index 27b63cc..7df6998 100644
--- a/frc971/autonomous/base_autonomous_actor.cc
+++ b/frc971/autonomous/base_autonomous_actor.cc
@@ -36,7 +36,9 @@
drivetrain_status_fetcher_(
event_loop->MakeFetcher<drivetrain::Status>("/drivetrain")),
drivetrain_goal_fetcher_(
- event_loop->MakeFetcher<drivetrain::Goal>("/drivetrain")) {}
+ event_loop->MakeFetcher<drivetrain::Goal>("/drivetrain")) {
+ event_loop->SetRuntimeRealtimePriority(29);
+}
void BaseAutonomousActor::ResetDrivetrain() {
AOS_LOG(INFO, "resetting the drivetrain\n");
diff --git a/frc971/wpilib/ahal/RobotBase.h b/frc971/wpilib/ahal/RobotBase.h
index cf1ed4c..5b4ce5b 100644
--- a/frc971/wpilib/ahal/RobotBase.h
+++ b/frc971/wpilib/ahal/RobotBase.h
@@ -19,20 +19,6 @@
class DriverStation;
-#ifdef WPILIB2017
-#define START_ROBOT_CLASS(_ClassName_) \
- int main() { \
- if (!HAL_Initialize(0)) { \
- std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
- return -1; \
- } \
- HAL_Report(HALUsageReporting::kResourceType_Language, \
- HALUsageReporting::kLanguage_CPlusPlus); \
- static _ClassName_ robot; \
- std::printf("\n********** Robot program starting **********\n"); \
- robot.StartCompetition(); \
- }
-#else
#define START_ROBOT_CLASS(_ClassName_) \
int main(int argc, char *argv[]) { \
aos::InitGoogle(&argc, &argv); \
@@ -50,7 +36,6 @@
std::printf("\n********** Robot program starting **********\n"); \
robot.StartCompetition(); \
}
-#endif
/**
* Implement a Robot Program framework.
diff --git a/frc971/wpilib/joystick_sender.cc b/frc971/wpilib/joystick_sender.cc
index d31d4a5..a4634bf 100644
--- a/frc971/wpilib/joystick_sender.cc
+++ b/frc971/wpilib/joystick_sender.cc
@@ -19,7 +19,7 @@
joystick_state_sender_(
event_loop_->MakeSender<::aos::JoystickState>("/aos")),
team_id_(::aos::network::GetTeamNumber()) {
- event_loop_->SetRuntimeRealtimePriority(29);
+ event_loop_->SetRuntimeRealtimePriority(28);
event_loop->set_name("joystick_sender");
event_loop_->OnRun([this]() {
diff --git a/frc971/wpilib/wpilib_robot_base.h b/frc971/wpilib/wpilib_robot_base.h
index 3404bb8..e34e3ad 100644
--- a/frc971/wpilib/wpilib_robot_base.h
+++ b/frc971/wpilib/wpilib_robot_base.h
@@ -48,7 +48,18 @@
class WPILibAdapterRobot : public frc::RobotBase {
public:
void StartCompetition() override {
- ::aos::InitNRT();
+ // Just allow overcommit memory like usual. Various processes map memory
+ // they will never use, and the roboRIO doesn't have enough RAM to handle
+ // it. This is in here instead of starter.sh because starter.sh doesn't run
+ // with permissions on a roboRIO.
+ AOS_CHECK(system("echo 0 > /proc/sys/vm/overcommit_memory") == 0);
+
+ // Configure throttling so we reserve 5% of the CPU for non-rt work.
+ // This makes things significantly more stable when work explodes.
+ // This is in here instead of starter.sh for the same reasons, starter is
+ // suid and runs as admin, so this actually works.
+ AOS_CHECK(system("/sbin/sysctl -w kernel.sched_rt_period_us=1000000") == 0);
+ AOS_CHECK(system("/sbin/sysctl -w kernel.sched_rt_runtime_us=950000") == 0);
robot_.Run();
}