diff --git a/main/ugv_comms.cc b/main/ugv_comms.cc index 368c0be..2686d1e 100644 --- a/main/ugv_comms.cc +++ b/main/ugv_comms.cc @@ -12,8 +12,6 @@ namespace ugv { namespace comms { -CommsClass Comms; - static const char *TAG = "ugv_comms"; CommsClass::CommsClass() @@ -167,7 +165,7 @@ void CommsClass::RunTask() { if (ret != ESP_OK) { ESP_LOGE(TAG, "error sending packet: %d", ret); } else { - ESP_LOGI(TAG, "lora wrote UGV_Message packet"); + ESP_LOGV(TAG, "lora wrote UGV_Message packet"); } current_tick = xTaskGetTickCount(); diff --git a/main/ugv_comms.hh b/main/ugv_comms.hh index 1d20568..431835e 100644 --- a/main/ugv_comms.hh +++ b/main/ugv_comms.hh @@ -69,7 +69,5 @@ class CommsClass { static void CommsTask(void* arg); }; -extern CommsClass Comms; - } // namespace comms } // namespace ugv diff --git a/main/ugv_io.cc b/main/ugv_io.cc index 371c6af..bf5e9de 100644 --- a/main/ugv_io.cc +++ b/main/ugv_io.cc @@ -88,7 +88,7 @@ void IOClass::WriteOutputs(const Outputs &outputs) { ERROR_CHECK(ret); ret = gpio_set_level(MOTOR_RIGHT_DIR, right_dir); ERROR_CHECK(ret); - ESP_LOGD(TAG, "motor outputs: (%f, %f)", outputs.left_motor, + ESP_LOGV(TAG, "motor outputs: (%f, %f)", outputs.left_motor, outputs.right_motor); } diff --git a/main/ugv_io.hh b/main/ugv_io.hh index 4cd22b5..9073e4e 100644 --- a/main/ugv_io.hh +++ b/main/ugv_io.hh @@ -35,7 +35,5 @@ class IOClass { void InitMotors(); }; -extern IOClass IO; - } // namespace io } // namespace ugv diff --git a/main/ugv_io_gps.cc b/main/ugv_io_gps.cc index 8838e19..f33f7c3 100644 --- a/main/ugv_io_gps.cc +++ b/main/ugv_io_gps.cc @@ -73,7 +73,7 @@ void UART_GPS::Init() { ESP_LOGI(TAG, "gps uart configured"); BaseType_t xRet = xTaskCreate(UART_GPS::GPS_Task, "ugv_io_gps", 2 * 1024, - this, 1, &this->task_); + this, 3, &this->task_); if (xRet != pdTRUE) { ESP_LOGE(TAG, "error creating GPS task"); return; diff --git a/main/ugv_main.cc b/main/ugv_main.cc index 0b89e66..e4905d7 100644 --- a/main/ugv_main.cc +++ b/main/ugv_main.cc @@ -1,31 +1,69 @@ #include -#include -#include - +#include #include "ugv_comms.hh" #include "ugv_display.hh" #include "ugv_io.hh" namespace ugv { -using ugv::comms::Comms; -using ugv::io::IO; - -DisplayClass *display; +using ugv::comms::CommsClass; +using ugv::io::IOClass; static const char *TAG = "ugv_main"; +constexpr uint64_t LOOP_PERIOD_US = 1e6 / 1; + +extern "C" void OnTimeout(void *arg); + +struct State { + public: + CommsClass * comms; + IOClass * io; + DisplayClass * display; + esp_timer_handle_t timer_handle; + io::Inputs inputs; + io::Outputs outputs; + + State() { + comms = new CommsClass(); + io = new IOClass(); + display = new DisplayClass(comms, io); + } + + void Init() { + comms->Init(); + io->Init(); + display->Init(); -void setup(void) { - ESP_LOGI(TAG, "setup"); + esp_timer_init(); - Comms.Init(); - IO.Init(); - display = new DisplayClass(&Comms, &IO); - display->Init(); + esp_timer_create_args_t timer_args; + timer_args.callback = OnTimeout; + timer_args.arg = this; + timer_args.dispatch_method = ESP_TIMER_TASK; + timer_args.name = "ugv_main_loop"; + esp_timer_create(&timer_args, &this->timer_handle); + esp_timer_start_periodic(timer_handle, LOOP_PERIOD_US); + } + + void OnTick() { + ESP_LOGD(TAG, "OnTick"); + } +}; + +extern "C" void OnTimeout(void *arg) { + State *state = (State*)arg; + state->OnTick(); } -} // namespace ugv +State *state; -extern "C" void app_main() { - ugv::setup(); +void Setup(void) { + ESP_LOGI(TAG, "Starting UAS UGV"); + state = new State(); + state->Init(); + ESP_LOGI(TAG, "Setup finished"); } + +} // namespace ugv + +extern "C" void app_main() { ugv::Setup(); }