create main loop
This commit is contained in:
parent
3fc065d212
commit
fac5b63e62
@ -12,8 +12,6 @@
|
|||||||
namespace ugv {
|
namespace ugv {
|
||||||
namespace comms {
|
namespace comms {
|
||||||
|
|
||||||
CommsClass Comms;
|
|
||||||
|
|
||||||
static const char *TAG = "ugv_comms";
|
static const char *TAG = "ugv_comms";
|
||||||
|
|
||||||
CommsClass::CommsClass()
|
CommsClass::CommsClass()
|
||||||
@ -167,7 +165,7 @@ void CommsClass::RunTask() {
|
|||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "error sending packet: %d", ret);
|
ESP_LOGE(TAG, "error sending packet: %d", ret);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "lora wrote UGV_Message packet");
|
ESP_LOGV(TAG, "lora wrote UGV_Message packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
current_tick = xTaskGetTickCount();
|
current_tick = xTaskGetTickCount();
|
||||||
|
@ -69,7 +69,5 @@ class CommsClass {
|
|||||||
static void CommsTask(void* arg);
|
static void CommsTask(void* arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CommsClass Comms;
|
|
||||||
|
|
||||||
} // namespace comms
|
} // namespace comms
|
||||||
} // namespace ugv
|
} // namespace ugv
|
||||||
|
@ -88,7 +88,7 @@ void IOClass::WriteOutputs(const Outputs &outputs) {
|
|||||||
ERROR_CHECK(ret);
|
ERROR_CHECK(ret);
|
||||||
ret = gpio_set_level(MOTOR_RIGHT_DIR, right_dir);
|
ret = gpio_set_level(MOTOR_RIGHT_DIR, right_dir);
|
||||||
ERROR_CHECK(ret);
|
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);
|
outputs.right_motor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,5 @@ class IOClass {
|
|||||||
void InitMotors();
|
void InitMotors();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern IOClass IO;
|
|
||||||
|
|
||||||
} // namespace io
|
} // namespace io
|
||||||
} // namespace ugv
|
} // namespace ugv
|
||||||
|
@ -73,7 +73,7 @@ void UART_GPS::Init() {
|
|||||||
ESP_LOGI(TAG, "gps uart configured");
|
ESP_LOGI(TAG, "gps uart configured");
|
||||||
|
|
||||||
BaseType_t xRet = xTaskCreate(UART_GPS::GPS_Task, "ugv_io_gps", 2 * 1024,
|
BaseType_t xRet = xTaskCreate(UART_GPS::GPS_Task, "ugv_io_gps", 2 * 1024,
|
||||||
this, 1, &this->task_);
|
this, 3, &this->task_);
|
||||||
if (xRet != pdTRUE) {
|
if (xRet != pdTRUE) {
|
||||||
ESP_LOGE(TAG, "error creating GPS task");
|
ESP_LOGE(TAG, "error creating GPS task");
|
||||||
return;
|
return;
|
||||||
|
@ -1,31 +1,69 @@
|
|||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <string.h>
|
#include <esp_timer.h>
|
||||||
#include <u8g2.h>
|
|
||||||
|
|
||||||
#include "ugv_comms.hh"
|
#include "ugv_comms.hh"
|
||||||
#include "ugv_display.hh"
|
#include "ugv_display.hh"
|
||||||
#include "ugv_io.hh"
|
#include "ugv_io.hh"
|
||||||
|
|
||||||
namespace ugv {
|
namespace ugv {
|
||||||
|
|
||||||
using ugv::comms::Comms;
|
using ugv::comms::CommsClass;
|
||||||
using ugv::io::IO;
|
using ugv::io::IOClass;
|
||||||
|
|
||||||
DisplayClass *display;
|
|
||||||
|
|
||||||
static const char *TAG = "ugv_main";
|
static const char *TAG = "ugv_main";
|
||||||
|
constexpr uint64_t LOOP_PERIOD_US = 1e6 / 1;
|
||||||
|
|
||||||
void setup(void) {
|
extern "C" void OnTimeout(void *arg);
|
||||||
ESP_LOGI(TAG, "setup");
|
|
||||||
|
|
||||||
Comms.Init();
|
struct State {
|
||||||
IO.Init();
|
public:
|
||||||
display = new DisplayClass(&Comms, &IO);
|
CommsClass * comms;
|
||||||
display->Init();
|
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();
|
||||||
|
|
||||||
|
esp_timer_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();
|
||||||
|
}
|
||||||
|
|
||||||
|
State *state;
|
||||||
|
|
||||||
|
void Setup(void) {
|
||||||
|
ESP_LOGI(TAG, "Starting UAS UGV");
|
||||||
|
state = new State();
|
||||||
|
state->Init();
|
||||||
|
ESP_LOGI(TAG, "Setup finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ugv
|
} // namespace ugv
|
||||||
|
|
||||||
extern "C" void app_main() {
|
extern "C" void app_main() { ugv::Setup(); }
|
||||||
ugv::setup();
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user