Skip to content

3.3 AlarmClient Class

Overview

AlarmClient handles active alarm queries and alarm reset. After Arm is connected, access the instance through arm.alarmClient ; no separate initialization is required.

LanguageType selects the language used by GetAllActiveAlarms() . RobotAlarm describes one alarm record. When there is no active alarm, the query APIs return an empty list or an empty RobotAlarm .

3.3.1 Reset Alarm

cpp
Reset() -> STATUS_CODE
ItemDescription
DescriptionSends an alarm/servo reset command, typically after the fault condition has been handled
Request ParametersNone
Return ValueSTATUS_CODE: function execution result
NotesCall this only when an alarm reset is actually required. If the underlying fault still exists, the alarm may remain active or appear again
Compatible Robot Software VersionsCollaborative (Copper): v7.5.0.0+
Industrial (Bronze): v7.5.0.0+

3.3.2 Get All Active Alarms

cpp
GetAllActiveAlarms(LanguageType language = LanguageType::Chinese) -> std::pair<std::vector<RobotAlarm>, STATUS_CODE>
ItemDescription
DescriptionGets the current list of all active alarms
Request Parameterslanguage : LanguageType used for the alarm list. Defaults to Chinese ; English is also supported
Return Valuestd::vector<RobotAlarm> : active alarm list
STATUS_CODE: function execution result
NotesThe SDK preserves the order returned by the server. If the server returns no alarms, the list is empty and the status code is OK
Compatible Robot Software VersionsCollaborative (Copper): v7.5.0.0+
Industrial (Bronze): v7.5.0.0+

3.3.3 Get Highest-Priority Alarm

cpp
GetTopAlarm() -> std::pair<RobotAlarm, STATUS_CODE>
ItemDescription
DescriptionGets the current highest-priority alarm
Request ParametersNone
Return ValueRobotAlarm: highest-priority alarm information
STATUS_CODE: function execution result
NotesIf there is no active alarm, the returned RobotAlarm is empty
Compatible Robot Software VersionsCollaborative (Copper): v7.5.0.0+
Industrial (Bronze): v7.5.0.0+

RobotAlarm Structure

FieldTypeDescription
user_codestd::stringUser-readable alarm code
inner_codestd::stringInternal controller-side alarm code
namestd::stringAlarm name
reasonstd::stringAlarm cause
suggeststd::stringSuggested handling action
consequencestd::stringPossible impact of the alarm
ext_descstd::stringExtended description

Minimal Call Example

Example code:

cpp17/alarm_query/src/query_active_alarms/run.cpp
cpp
#include <iostream>
#include <vector>
#include "arm_api.h"
#include "status_code.h"

#include "query_active_alarms/run.h"

/**
 * 查询全部活动报警门面。
 * @return 0 表示成功,否则返回 1。
 */
int RunAlarmQueryQueryActiveAlarms(void)
{
    // [ZH] 连接机器人,请直接修改下面的魔鬼字符串。
    // [EN] Connect to the robot and edit the hard-coded magic strings below directly.
    Arm arm;
    STATUS_CODE connectRet = arm.Connect("10.27.1.2", "10.27.1.102");
    if (connectRet != STATUS_CODE::OK) {
        std::cerr << "[cpp17_alarm] 连接机器人失败 / Connect to the robot failed, 状态码 / Status code: "
                  << static_cast<int>(connectRet) << "\n";
        return 1;
    }
    std::cout << "[cpp17_alarm] 机器人连接成功 / Robot connected successfully\n";
    // [ZH] 获取全部活动报警。
    // [EN] Get all active alarms.
    std::pair<std::vector<RobotAlarm>, STATUS_CODE> alarmPair = arm.alarmClient.GetAllActiveAlarms(LanguageType::Chinese);
    std::cout << "[cpp17_alarm] GetAllActiveAlarms 状态码 / GetAllActiveAlarms status code: "
              << static_cast<int>(alarmPair.second) << "\n";
    std::cout << "[cpp17_alarm] 活动报警数量 / Active alarm count: "
              << alarmPair.first.size() << "\n";
    for (size_t index = 0; index < alarmPair.first.size() && index < 3U; ++index) {
        std::cout << "[cpp17_alarm] 活动报警 / Active alarm #" << index
                  << ": user_code=" << alarmPair.first[index].user_code
                  << ", name=" << alarmPair.first[index].name << "\n";
    }

    // [ZH] 断开连接,结束示例。
    // [EN] Disconnect and finish the example.
    arm.Disconnect();
    std::cout << "[cpp17_alarm] 示例结束 / Example finished\n";
    return 0;
}
cpp17/alarm_query/src/reset_alarm/run.cpp
cpp
#include <iostream>
#include "arm_api.h"
#include "status_code.h"

#include "reset_alarm/run.h"

/**
 * 报警复位门面。
 * @return 0 表示成功,否则返回 1。
 */
int RunAlarmQueryResetAlarm(void)
{
    // [ZH] 连接机器人,请直接修改下面的魔鬼字符串。
    // [EN] Connect to the robot and edit the hard-coded magic strings below directly.
    Arm arm;
    STATUS_CODE connectRet = arm.Connect("10.27.1.2", "10.27.1.102");
    if (connectRet != STATUS_CODE::OK) {
        std::cerr << "[cpp17_alarm] 连接机器人失败 / Connect to the robot failed, 状态码 / Status code: "
                  << static_cast<int>(connectRet) << "\n";
        return 1;
    }
    std::cout << "[cpp17_alarm] 机器人连接成功 / Robot connected successfully\n";
    // [ZH] 直接执行报警复位接口。
    // [EN] Execute the alarm reset API directly.
    STATUS_CODE resetRet = arm.alarmClient.Reset();
    std::cout << "[cpp17_alarm] Reset 状态码 / Reset status code: "
              << static_cast<int>(resetRet) << "\n";

    // [ZH] 断开连接,结束示例。
    // [EN] Disconnect and finish the example.
    arm.Disconnect();
    std::cout << "[cpp17_alarm] 示例结束 / Example finished\n";
    return 0;
}