lejusdk-utils API
RobotVersion
-
class RobotVersion
机器人版本号类
机器人版本号类,用于表示机器人版本号
备注
机器人版本号格式为:
MMMM 表示次版本号, 范围为0-9999
N 表示修订号, 范围为0-9
PPP 表示主版本号, 范围为0-9999
BIGNUMBER: PPPPMMMMN
STRING: PPPPMMMMN Patch 为 0 时,不显示 Patch 部分, 比如 M(4), N(5),P(0) 表示为 45 而非 000000045 (0000,0004,5)
Public Functions
-
constexpr RobotVersion() = default
默认构造函数
-
constexpr RobotVersion(const RobotVersion&) = default
拷贝构造函数
-
constexpr RobotVersion &operator=(const RobotVersion&) = default
赋值运算符
-
inline constexpr RobotVersion(uint16_t major, uint16_t minor, uint16_t patch = 0)
从版本号数字创建 RobotVersion 对象
- 参数:
major – 主版本号 (0-9999)
minor – 次版本号 (0-9999)
patch – 补丁版本号 (0-9999), 默认为0
- 抛出:
std::invalid_argument – 如果版本号超出有效范围
- 返回:
RobotVersion 实例
-
inline constexpr bool start_with(uint16_t major) const
判断版本号是 major 版本系列
备注
例如:45, 100045, 4000045, 100000049 都是属于 4 代系列
- 参数:
major – 主版本号
- 返回:
是否以 major 开头
-
inline constexpr bool start_with(uint16_t major, uint16_t minor) const
判断版本号是 major.minor 版本系列
备注
例如:45, 100045, 4000045 都是属于 45 版本系列
- 参数:
major – 主版本号
minor – 次版本号
- 返回:
是否以 major.minor 开头
-
inline std::string version_name() const
获取版本号标准的 semantic version 字符串
备注
例如:45 –> 4.5.0 100045 –> 4.5.1 2000105 –> 10.5.20 https://semver.org/lang/zh-CN/
- 返回:
版本号字符串 如 4.5.0, 10.5.20
-
inline std::string version_name_short() const
获取简洁版本号字符串
备注
当patch为0时,只显示major.minor格式;当patch不为0时,显示完整的三段式版本号
备注
例如:45 –> “4.5”
- 返回:
简洁版本号字符串,格式为 major.minor 或 major.minor.patch
-
inline std::string to_string() const
将版本号转换为字符串
- 返回:
版本号字符串 如 45, 100045, 4000045, 100000049
-
inline constexpr uint16_t major() const
获取主版本号
- 返回:
主版本号
-
inline constexpr uint16_t minor() const
获取次版本号
- 返回:
次版本号
-
inline constexpr uint16_t patch() const
获取补丁版本号
- 返回:
补丁版本号
-
inline constexpr bool operator==(const RobotVersion &other) const
相等运算符
- 参数:
other – 其他版本
- 返回:
是否相等
-
inline constexpr bool operator!=(const RobotVersion &other) const
不等运算符
- 参数:
other – 其他版本
- 返回:
是否不等
-
inline constexpr bool operator<(const RobotVersion &other) const
小于运算符
- 参数:
other – 其他版本
- 返回:
是否小于
-
inline constexpr bool operator<=(const RobotVersion &other) const
小于等于运算符
- 参数:
other – 其他版本
- 返回:
是否小于等于
-
inline constexpr bool operator>(const RobotVersion &other) const
大于运算符
- 参数:
other – 其他版本
- 返回:
是否大于
-
inline constexpr bool operator>=(const RobotVersion &other) const
大于等于运算符
- 参数:
other – 其他版本
- 返回:
是否大于等于
Public Static Functions
-
static inline RobotVersion create(int big_number)
从大整数创建 RobotVersion 对象
- 参数:
big_number – 大整数
- 抛出:
std::invalid_argument – 如果版本号超出有效范围
- 返回:
RobotVersion 实例
-
static inline RobotVersion from_env()
从环境变量 ROBOT_VERSION 获取版本号
- 抛出:
std::invalid_argument – 如果环境变量不存在或版本号无效
- 返回:
RobotVersion 实例
-
static inline constexpr bool is_valid(int big_number)
判断版本号是否合法
- 参数:
big_number – 版本号数字
- 返回:
是否合法
RobotVersions
预定义的机器人版本常量。
Kuavo 系列
-
constexpr RobotVersion KUAVO4_BASE = {4, 2, 0}
Kuavo 4代 基础版 (短手基础版)
-
constexpr RobotVersion KUAVO4_PRO_DEXHAND = {4, 5, 0}
Kuavo 4代 PRO 专业版 (灵巧手版本)
-
constexpr RobotVersion KUAVO4_UAE = {4, 6, 0}
Kuavo 4代 UAE 版本
-
constexpr RobotVersion KUAVO4_PRO_GRIPPER = {4, 7, 0}
Kuavo 4代 PRO 夹爪版
-
constexpr RobotVersion KUAVO4_EDU = {4, 9, 0}
Kuavo 4代 EDU 教育版
-
constexpr RobotVersion KUAVO5_BASE = {5, 2}
Kuavo 5代 基础版
Roban 系列
-
constexpr RobotVersion ROBAN2_BASE = {1, 4}
Roban 2代 基础版
Kuavo 足式机器人检测宏
-
IS_KUAVO_LEGGED(rb)
判断是否为 Kuavo 足式机器人(4代或5代)
-
IS_KUAVO4_LEGGED(rb)
判断是否为 Kuavo 4代足式机器人
-
IS_KUAVO5_LEGGED(rb)
判断是否为 Kuavo 5代足式机器人
-
IS_KUAVO4PRO_LEGGED(rb)
判断是否为 Kuavo 4代 PRO 足式机器人(4.5及以上版本)
Roban 足式机器人检测宏
-
IS_ROBAN_LEGGED(rb)
判断是否为 Roban 足式机器人
-
IS_ROBAN2_LEGGED(rb)
判断是否为 Roban 2代足式机器人
Kuavo 轮式机器人检测宏
-
IS_KUAVO_WHEELED(rb)
判断是否为 Kuavo 轮式机器人
产品系列检测宏
-
IS_KUAVO(rb)
判断是否为 Kuavo 系列机器人(足式或轮式)
-
IS_ROBAN(rb)
判断是否为 Roban 系列机器人
时间工具函数
-
inline double leju::common::GetUnixTimestampS()
获取当前Unix时间戳(秒)
- 返回:
double 当前Unix时间戳,单位为秒(自1970-01-01以来)
-
inline uint64_t leju::common::GetUnixTimestampNs()
获取当前Unix时间戳(纳秒)
- 返回:
uint64_t 当前Unix时间戳,单位为纳秒(自1970-01-01以来)
-
inline void leju::common::GetUnixTimestampSecNsec(int32_t &sec, uint32_t &nsec)
获取当前Unix时间戳(秒和纳秒分离)
- 参数:
sec – 输出参数,秒部分(自1970-01-01以来)
nsec – 输出参数,纳秒部分(0-999,999,999)
-
inline uint64_t leju::common::GetSteadyTimestampNs()
获取当前高精度时间戳(纳秒,基于steady_clock)
- 返回:
uint64_t 当前高精度时间戳,单位为纳秒
Loop
-
class Loop
定时循环执行器类
创建一个独立的线程,按照指定周期循环执行用户提供的函数 支持绑定到指定CPU核心以提高性能和确定性
Public Types
-
using LoopFunction = std::function<void()>
循环函数类型定义
Public Functions
-
inline Loop(const std::string &name, LoopFunction function, int period_ms, int cpu_core = -1, int sched_priority = 80)
构造函数
- 参数:
name – 循环器名称,用于标识和调试
function – 要执行的函数对象
period_ms – 执行周期,单位毫秒
cpu_core – 要绑定的CPU核心号,-1表示不绑定
sched_priority – SCHED_FIFO优先级,-1表示不设置实时调度
-
inline ~Loop()
析构函数,自动停止循环
-
inline void start()
启动循环执行器
创建新线程并开始按周期执行函数,如果已经在运行则忽略
-
inline void shutdown()
停止循环执行器
安全停止循环并等待线程结束,如果已经停止则忽略
-
inline std::string getName() const
获取循环器名称
- 返回:
循环器名称
-
inline int getPeriod() const
获取执行周期
- 返回:
执行周期,单位毫秒
-
inline bool isRunning() const
获取运行状态
- 返回:
true表示正在运行,false表示已停止
-
using LoopFunction = std::function<void()>
日志宏
基础日志宏
-
LOG_D(tag, ...)
输出 DEBUG 级别日志
-
LOG_T(tag, ...)
输出 TRACE 级别日志
-
LOG_I(tag, ...)
输出 INFO 级别日志
-
LOG_W(tag, ...)
输出 WARN 级别日志
-
LOG_E(tag, ...)
输出 ERROR 级别日志
彩色日志宏
-
LOG_SUCCESS(tag, format, ...)
输出绿色的成功信息
-
LOG_WARNING(tag, format, ...)
输出黄色的警告信息
-
LOG_FAILURE(tag, format, ...)
输出红色的错误信息