cmvr-es/cmvr-es/task/grpc_server_task/include/grpc_server_task.h
xtkuang af67751937 feat: add safe UME teleoperation framework
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.
2026-07-31 08:48:04 +08:00

75 lines
2.1 KiB
C++

#ifndef CMVR_ES_GRPC_SERVER_TASK_H
#define CMVR_ES_GRPC_SERVER_TASK_H
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <grpcpp/grpcpp.h>
#include "cmvr/config/grpc_server_config/grpc_server_config.pb.h"
#include "task/task.h"
namespace cmvr::service {
class ArmTeleopBackend;
}
namespace cmvr::task {
class GrpcServerTask final : public Task {
public:
explicit GrpcServerTask(const config::GRPCServerConfig& cfg);
~GrpcServerTask() override;
const std::string& id() const override { return id_; }
TaskRunMode runMode() const override { return TaskRunMode::BLOCKING_SERVICE; }
bool init() override;
bool start() override;
bool step(double dt) override;
void stop() override;
TaskState state() const override;
bool isBusy() const override;
bool isFinished() const override;
bool isFailed() const override;
std::string stateString() const override;
std::string detailStatusString() const override;
std::string address() const;
private:
void waitLoop();
void clearServices();
config::GRPCServerConfig cfg_;
std::string id_;
mutable std::mutex mutex_;
TaskState state_{TaskState::UNINITIALIZED};
std::string address_;
std::string last_error_;
std::unique_ptr<grpc::Server> server_;
std::thread wait_thread_;
std::unique_ptr<grpc::Service> camera_service_;
std::unique_ptr<grpc::Service> system_service_;
std::unique_ptr<grpc::Service> speaker_service_;
std::unique_ptr<grpc::Service> microphone_service_;
std::unique_ptr<grpc::Service> dexhand_service_;
std::unique_ptr<grpc::Service> biohand_service_;
std::unique_ptr<grpc::Service> arm_service_;
std::unique_ptr<grpc::Service> arm_teleop_service_;
std::shared_ptr<cmvr::service::ArmTeleopBackend>
arm_teleop_backend_;
std::unique_ptr<grpc::Service> motor_service_;
std::unique_ptr<grpc::Service> agv_service_;
std::unique_ptr<grpc::Service> hlc_service_;
};
void registerGrpcServerTaskFactory();
} // namespace cmvr::task
#endif // CMVR_ES_GRPC_SERVER_TASK_H