TOnProgramStoppedCB

이 콜백 함수로 자동 모드에서 실행 중인 프로그램이 오류나 사용자 명령으로 멈췄을 때 로봇 컨트롤러의 프로그램 실행이 완전히 종료되었는지 확인합니다.

콜백 함수 규칙을 참고하세요.

정의 위치: DRFLEx.h

// typedef 정의(DRFL.h)
typedef void (*TOnProgramStoppedCB)(const PROGRAM_STOP_CAUSE);

// 등록 API(내부 + 래퍼)
DRFL_API void _set_on_program_stopped(LPROBOTCONTROL pCtrl, TOnProgramStoppedCB pCallbackFunc);
void set_on_program_stopped(TOnProgramStoppedCB pCallbackFunc)
{
    _set_on_program_stopped(_rbtCtrl, pCallbackFunc);
};

매개변수

매개변수 이름

자료형

기본값

설명

eStopCause

PROGRAM_STOP_CAUSE

프로그램 종료 원인(예: 사용자 정지, 오류, 안전 등)입니다.

반환값
없음

예제

#include "DRFLEx.h"
#include <cstdio>
#include <thread>
#include <chrono>
using namespace DRAFramework;

// 실행 중인 DRL 프로그램이 정지하거나 종료되면 자동으로 호출됩니다
void OnProgramStoppedCB(const PROGRAM_STOP_CAUSE eStopCause)
{
    switch (eStopCause)
    {
    case PROGRAM_STOP_CAUSE_FORCE:
        std::printf("[PROGRAM STOP] Program was force-stopped.\n");
        break;

    case PROGRAM_STOP_CAUSE_ERROR:
        std::printf("[PROGRAM STOP] Error occurred during execution.\n");
        // 필요하면 오류 코드를 확인하거나 복구 로직 실행
        break;

    case PROGRAM_STOP_CAUSE_NORMAL:
        std::printf("[PROGRAM STOP] Program completed normally.\n");
        break;

    default:
        std::printf("[PROGRAM STOP] Unknown stop cause: %d\n", eStopCause);
        break;
    }
}

int main()
{
    CDRFLEx drfl;

    // 로봇 컨트롤러에 연결
    if (!drfl.open_connection("192.168.137.100")) {
        std::printf("Failed to connect to controller.\n");
        return -1;
    }

    // 프로그램 정지 이벤트 콜백 함수 등록
    drfl.set_on_program_stopped(OnProgramStoppedCB);

    // 제어권 획득 후 서보 온
    drfl.manage_access_control(MANAGE_ACCESS_CONTROL_FORCE_REQUEST);
    std::this_thread::sleep_for(std::chrono::seconds(1));
    drfl.set_robot_control(CONTROL_SERVO_ON);
    for (int i = 0; i < 10 && drfl.get_robot_state() != STATE_STANDBY; ++i)
        std::this_thread::sleep_for(std::chrono::seconds(1));

    // drl_start는 자동 모드가 필요합니다
    if (!drfl.set_robot_mode(ROBOT_MODE_AUTONOMOUS)) return -1;

    // 예제: DRL 프로그램을 시작하고 콜백 함수 호출 대기
    if (!drfl.drl_start(ROBOT_SYSTEM_VIRTUAL, "movej(posj(0,0,90,0,90,0), vel=30, acc=30)\r\n")) {
        std::printf("drl_start was refused.\n");
        return -1;
    }

    while (true) {
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }

    drfl.close_connection();
    return 0;
}

참고

  • 자동 모드에서 실행 중인 DRL 프로그램이 종료되면(정상 또는 비정상) 콜백이 호출됩니다.

  • 프로그램이 끝났을 때 정리 작업, 로그 기록, 재시작 준비에 사용하세요.