One Motor 0.5.1
RoboMaster全平台一站式电机驱动库
载入中...
搜索中...
未找到
MotorGuard.hpp
浏览该文件的文档.
1
7
8#ifndef MOTORGUARD_HPP
9#define MOTORGUARD_HPP
10#include <memory>
12
13namespace OneMotor::Motor::DJI
14{
41 class MotorGuard
42 {
43 public:
50 using ExitFrameData = std::optional<std::array<uint8_t, 16>>;
54 using DriverPair = std::pair<std::string, ExitFrameData>;
60 static MotorGuard& getInstance();
66 void guard(
67 const std::vector<DriverPair>& driver_set);
68 MotorGuard(MotorGuard&) = delete;
69 MotorGuard& operator=(const MotorGuard&) = delete;
70
71 private:
75 struct WatchdogState
76 {
77 std::atomic<std::chrono::steady_clock::time_point> last_fed_time_;
78 std::atomic<bool> triggered_;
79 };
80
81 MotorGuard();
82 std::vector<std::shared_ptr<Can::CanDriver>> drivers;
83
84 std::unordered_map<std::shared_ptr<Can::CanDriver>, std::unique_ptr<WatchdogState>> watchdog_states_;
86 std::unordered_map<std::shared_ptr<Can::CanDriver>, std::array<uint8_t, 16>> driver_exit_data_;
87 std::mutex state_mutex_;
88 std::chrono::milliseconds check_timeout_{50};
89 std::jthread watchdog_monitor_;
90
96 void feed_watchdog(const std::shared_ptr<Can::CanDriver>& driver);
102 void watchdog_monitor_func_(const std::stop_token& stop_token);
108 void circuit_breaker_action_(const std::shared_ptr<Can::CanDriver>& driver);
109 };
110}
111
112#endif //MOTORGUARD_HPP
提供一个统一的CAN总线驱动接口。
防止电机驱动器在运行结束时输出过高电流的保护类
定义 MotorGuard.hpp:42
static MotorGuard & getInstance()
获取MotorGuard的单例实例
定义 L_MotorGuard.cpp:98
std::pair< std::string, ExitFrameData > DriverPair
定义驱动器名称和退出帧数据的配对
定义 MotorGuard.hpp:54
void guard(const std::vector< DriverPair > &driver_set)
启动对指定CAN总线的监控
定义 L_MotorGuard.cpp:6
std::optional< std::array< uint8_t, 16 > > ExitFrameData
定义电机退出时发送的帧数据
定义 MotorGuard.hpp:50