- 选型指南
- 概述
- 入门指南
- 机械臂参数
- 示教器使用
-
二次开发
-
API(C++)
- 快速开始
- 接口说明
- 7000端口接口说明
- 使用示例
- 返回值说明
-
API(Python)
- 快速开始
- 接口说明
- 7000端口接口说明
- 使用示例
- 返回值说明
- ROS2开发
-
API(C++)
- 相关下载
电机与关节监控接口
头文件:include/tl_interface.h
相关示例代码:examples\cpp\ex_info_query.cpp
1. get_current_motor_speed - 获取各关节电机当前转速
方法:Result get_current_motor_speed(SOCKETFD socketFd, std::vector<int>& motor_speed, std::vector<int>& motor_speed_sync);
功能描述:获取当前各关节电机转速。
参数:
- socketFd:已连接的句柄。
- motor_speed:输出参数,机器人本体电机转速,长度 7,单位 [RPM]。
- motor_speed_sync:输出参数,外部轴电机转速,长度 5,单位 [RPM]。
返回值:
- 0:成功。
- 非0:失败。
使用示例:
// ----查询各关节电机当前转速----
std::cout << "[INFO] **********查询各关节电机当前转速**********" << std::endl;
{
std::vector<int> motor_speed; // 机器人本体电机转速,长度 7
std::vector<int> motor_speed_sync; // 外部轴电机转速,长度 5
auto ret = tl::get_current_motor_speed(socket_fd, motor_speed, motor_speed_sync);
if (ret != tl::Result::SUCCESS) {
std::cerr << "[ERROR] 获取电机转速失败,错误码: " << ret << std::endl;
} else {
std::cout << "[INFO] 电机转速 (本体, RPM): ";
for (const auto& val : motor_speed) {
std::cout << val << " ";
}
std::cout << std::endl;
std::cout << "[INFO] 电机转速 (外部轴, RPM): ";
for (const auto& val : motor_speed_sync) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
std::cout << std::endl;
2. get_current_motor_torque - 获取各关节电机当前扭矩
方法:Result get_current_motor_torque(SOCKETFD socketFd, std::vector<int>& motor_torque, std::vector<int>& motor_torque_sync);
功能描述:获取当前各关节电机扭矩。
参数:
- socketFd:已连接的句柄。
- motor_torque:输出参数,机器人本体电机扭矩,长度 7,单位 [%]。
- motor_torque_sync:输出参数,外部轴电机扭矩,长度 5,单位 [%]。
返回值:
- 0:成功。
- 非0:失败。
使用示例:
// ----查询各关节电机当前扭矩----
std::cout << "[INFO] **********查询各关节电机当前扭矩**********" << std::endl;
{
std::vector<int> motor_torque; // 机器人本体电机扭矩,长度 7
std::vector<int> motor_torque_sync; // 外部轴电机扭矩,长度 5
auto ret = tl::get_current_motor_torque(socket_fd, motor_torque, motor_torque_sync);
if (ret != tl::Result::SUCCESS) {
std::cerr << "[ERROR] 获取电机扭矩失败,错误码: " << ret << std::endl;
} else {
std::cout << "[INFO] 电机扭矩 (本体, %): ";
for (const auto& val : motor_torque) {
std::cout << val << " ";
}
std::cout << std::endl;
std::cout << "[INFO] 电机扭矩 (外部轴, %): ";
for (const auto& val : motor_torque_sync) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
std::cout << std::endl;
3. get_current_motor_current - 获取各关节电机当前电流
方法:Result get_current_motor_current(SOCKETFD socketFd, std::vector<double>& motor_current, std::vector<double>& motor_current_sync);
功能描述:获取当前各关节电机电流(24.03/DEV 接口)。
参数:
- socketFd:已连接的句柄。
- motor_current:输出参数,机器人本体电机电流,长度 7,单位 ‰。
- motor_current_sync:输出参数,外部轴电机电流,长度 5,单位 ‰。
返回值:
- 0:成功。
- 非0:失败。
使用示例:
// ----查询各关节电机当前电流----
std::cout << "[INFO] **********查询各关节电机当前电流**********" << std::endl;
{
std::vector<double> motor_current; // 机器人本体电机电流,长度 7
std::vector<double> motor_current_sync; // 外部轴电机电流,长度 5
auto ret = tl::get_current_motor_current(socket_fd, motor_current, motor_current_sync);
if (ret != tl::Result::SUCCESS) {
std::cerr << "[ERROR] 获取电机电流失败,错误码: " << ret << std::endl;
} else {
std::cout << "[INFO] 电机电流 (本体, ‰): ";
for (const auto& val : motor_current) {
std::cout << val << " ";
}
std::cout << std::endl;
std::cout << "[INFO] 电机电流 (外部轴, ‰): ";
for (const auto& val : motor_current_sync) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
std::cout << std::endl;
4. get_current_motor_payload - 获取各关节电机当前负载
方法:Result get_current_motor_payload(SOCKETFD socketFd, std::vector<double>& motor_payload, std::vector<double>& motor_payload_sync);
功能描述:获取当前各关节电机负载。
参数:
- socketFd:已连接的句柄。
- motor_payload:输出参数,机器人本体电机负载,长度 7,单位 [%]。
- motor_payload_sync:输出参数,外部轴电机负载,长度 5,单位 [%]。
返回值:
- 0:成功。
- 非0:失败。
使用示例:
// ----查询各关节电机当前负载----
std::cout << "[INFO] **********查询各关节电机当前负载**********" << std::endl;
{
std::vector<double> motor_payload; // 机器人本体电机负载,长度 7
std::vector<double> motor_payload_sync; // 外部轴电机负载,长度 5
auto ret = tl::get_current_motor_payload(socket_fd, motor_payload, motor_payload_sync);
if (ret != tl::Result::SUCCESS) {
std::cerr << "[ERROR] 获取电机负载失败,错误码: " << ret << std::endl;
} else {
std::cout << "[INFO] 电机负载 (本体, %): ";
for (const auto& val : motor_payload) {
std::cout << val << " ";
}
std::cout << std::endl;
std::cout << "[INFO] 电机负载 (外部轴, %): ";
for (const auto& val : motor_payload_sync) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
std::cout << std::endl;
5. get_joint_voltage - 获取各关节电压
方法:Result get_joint_voltage(SOCKETFD socketFd, std::vector<double>& joint_voltage, std::vector<double>& positioner_voltage);
功能描述:获取当前各关节电压。
参数:
- socketFd:已连接的句柄。
- joint_voltage:输出参数,机器人本体各关节电压。
- positioner_voltage:输出参数,外部轴各关节电压。
返回值:
- 0:成功。
- 非0:失败。
使用示例:
// ----查询各关节电压----
std::cout << "[INFO] **********查询各关节电压**********" << std::endl;
{
std::vector<double> joint_voltage; // 机器人本体各关节电压
std::vector<double> positioner_voltage; // 外部轴各关节电压
auto ret = tl::get_joint_voltage(socket_fd, joint_voltage, positioner_voltage);
if (ret != tl::Result::SUCCESS) {
std::cerr << "[ERROR] 获取关节电压失败,错误码: " << ret << std::endl;
} else {
std::cout << "[INFO] 关节电压 (本体): ";
for (const auto& val : joint_voltage) {
std::cout << val << " ";
}
std::cout << std::endl;
std::cout << "[INFO] 关节电压 (外部轴): ";
for (const auto& val : positioner_voltage) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
std::cout << std::endl;
6. get_joint_temperature - 获取各关节电机温度
方法:Result get_joint_temperature(SOCKETFD socketFd, std::vector<double>& temperatures);
功能描述:获取当前各关节电机温度(单位:摄氏度 ℃)。
参数:
- socketFd:已连接的句柄。
- temperatures:输出参数,各关节温度列表。
返回值:
- 0:成功。
- 非0:失败。
使用示例:
// ----查询各关节电机温度----
std::cout << "[INFO] **********查询各关节电机温度**********" << std::endl;
{
std::vector<double> temperatures; // 各关节温度
auto ret = tl::get_joint_temperature(socket_fd, temperatures);
if (ret != tl::Result::SUCCESS) {
std::cerr << "[ERROR] 获取关节温度失败,错误码: " << ret << std::endl;
} else {
std::cout << "[INFO] 关节温度 (℃): ";
for (const auto& val : temperatures) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
std::cout << std::endl;
