One Motor 0.5.1
RoboMaster全平台一站式电机驱动库
载入中...
搜索中...
未找到
OneMotor::Motor::DJI::MotorGuard类 参考

防止电机驱动器在运行结束时输出过高电流的保护类 更多...

#include <MotorGuard.hpp>

Public 类型

using ExitFrameData = std::optional<std::array<uint8_t, 16>>
 定义电机退出时发送的帧数据
 
using DriverPair = std::pair<std::string, ExitFrameData>
 定义驱动器名称和退出帧数据的配对
 

Public 成员函数

void guard (const std::vector< DriverPair > &driver_set)
 启动对指定CAN总线的监控
 
 MotorGuard (MotorGuard &)=delete
 
MotorGuardoperator= (const MotorGuard &)=delete
 

静态 Public 成员函数

static MotorGuardgetInstance ()
 获取MotorGuard的单例实例
 

详细描述

防止电机驱动器在运行结束时输出过高电流的保护类

MotorGuard实现了一种看门狗机制,用于监控CAN总线上的电机控制帧。 如果在指定时间内没有检测到ID为0x200的控制帧,它会触发一个熔断操作, 发送预设的CAN帧来将电机电流设置为安全值或零,从而防止电机失控。

Usage
// 创建一个驱动器列表
std::vector<OneMotor::Motor::DJI::MotorGuard::DriverPair> driver_set;
// 添加一个CAN接口,超时后不发送任何特定数据(电机将停止)
driver_set.push_back({"can0", std::nullopt});
// 添加另一个CAN接口,并指定超时后发送的数据
std::array<uint8_t, 16> exit_data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10};
driver_set.push_back({"can1", exit_data});
// 获取MotorGuard实例并启动监控
// ... 您的应用程序主循环 ...
static MotorGuard & getInstance()
获取MotorGuard的单例实例
定义 L_MotorGuard.cpp:98
void guard(const std::vector< DriverPair > &driver_set)
启动对指定CAN总线的监控
定义 L_MotorGuard.cpp:6

成员类型定义说明

◆ ExitFrameData

using OneMotor::Motor::DJI::MotorGuard::ExitFrameData = std::optional<std::array<uint8_t, 16>>

定义电机退出时发送的帧数据

这是一个16字节数组的可选类型。如果提供了数据,当看门狗超时时, 这些数据将被分成两个CAN帧(ID 0x200和0x1FF)发送出去。

成员函数说明

◆ getInstance()

MotorGuard & OneMotor::Motor::DJI::MotorGuard::getInstance ( )
static

获取MotorGuard的单例实例

返回
MotorGuard& 单例实例的引用

◆ guard()

void OneMotor::Motor::DJI::MotorGuard::guard ( const std::vector< DriverPair > & driver_set)

启动对指定CAN总线的监控

参数
driver_set一个包含驱动器名称和可选退出帧数据的向量

该类的文档由以下文件生成: