Add the UME RobotArm and Damiao CAN-FD path, migrate the legacy UME controller, and introduce guarded cross-machine gRPC teleoperation with lifecycle, authority, configuration, and test coverage.
62 lines
2.0 KiB
C++
62 lines
2.0 KiB
C++
#ifndef CMVR_ES_TASK_MANAGER_H
|
|
#define CMVR_ES_TASK_MANAGER_H
|
|
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <chrono>
|
|
#include <thread>
|
|
#include <unordered_map>
|
|
#include <atomic>
|
|
|
|
#include "task/task.h"
|
|
#include "task/touch_screen_task/include/touch_screen_task.h"
|
|
#include "cmvr/config/task_manager_config/task_manager_config.pb.h"
|
|
|
|
namespace cmvr::task {
|
|
|
|
class TaskManager {
|
|
public:
|
|
TaskManager(const TaskManager&) = delete;
|
|
TaskManager& operator=(const TaskManager&) = delete;
|
|
|
|
static TaskManager& getInstance(const config::TaskManagerConfig& cfg);
|
|
static TaskManager& getInstance();
|
|
static void destroyInstance();
|
|
|
|
~TaskManager();
|
|
|
|
bool startRunTask(double control_period_s = 0.001);
|
|
void stopRunTask();
|
|
bool running() const { return running_.load(); }
|
|
bool initialized() const noexcept { return initialized_; }
|
|
|
|
std::shared_ptr<Task> getTask(const std::string& task_id) const;
|
|
std::shared_ptr<TouchScreenTask> getTouchScreenTask(const std::string& task_id = "touch_screen") const;
|
|
|
|
private:
|
|
explicit TaskManager(const config::TaskManagerConfig& cfg);
|
|
|
|
void logTaskPlan() const;
|
|
bool initTasks();
|
|
void runTaskLoop(double control_period_s);
|
|
static TaskRunMode toTaskRunMode(config::TaskConfigEntry::TaskRunMode run_mode);
|
|
|
|
static std::mutex init_mutex_;
|
|
static std::shared_ptr<TaskManager> instance_;
|
|
|
|
config::TaskManagerConfig cfg_;
|
|
std::unordered_map<std::string, std::shared_ptr<Task>> tasks_;
|
|
std::unordered_map<std::string, double> task_period_s_;
|
|
std::unordered_map<std::string, std::chrono::steady_clock::time_point> next_step_time_;
|
|
mutable std::mutex tasks_mutex_;
|
|
std::mutex lifecycle_mutex_;
|
|
std::atomic<bool> running_{false};
|
|
std::thread run_thread_;
|
|
bool initialized_{false};
|
|
};
|
|
|
|
} // namespace cmvr::task
|
|
|
|
#endif // CMVR_ES_TASK_MANAGER_H
|