set_on_rt_monitoring_data
이 함수는 로봇 컨트롤러가 외부 컨트롤러로 실시간 출력 데이터를 보낼 때마다 호출되는 콜백 함수를 등록합니다.
이 콜백으로 실시간 작업 중 로봇 상태(예: 조인트 위치, 토크)를 계속 모니터링할 수 있습니다. 보통 read_data_rt, start_rt_control과 함께 사용합니다.
정의
DRFLEx.h, CDRFLEx 클래스의 public 섹션
void set_on_rt_monitoring_data(TOnRTMonitoringDataCB pCallbackFunc) {
_set_on_rt_monitoring_data(_rbtCtrlUDP, pCallbackFunc);
};
매개변수
매개변수 이름 |
자료형 |
설명 |
|---|---|---|
pCallbackFunc |
새 RT 데이터를 받을 때마다 실행할 함수 포인터(콜백)입니다. |
참고
경고
콜백이 받는 포인터는 새 패킷이 도착할 때마다 덮어쓰이는 버퍼를 가리키므로, 포인터를 보관해 두면 그 사이에 내용이 바뀝니다. 필요한 필드만 복사하고 바로 반환하세요. 콜백 안에서 하는 작업은 다음 패킷 수신을 지연시킵니다.
콜백 함수는 컨트롤러의 실시간 갱신 주기에 맞춰 자동으로 호출됩니다.
콜백 안에서는
printf()나 파일 I/O 같은 비실시간 함수를 30 Hz보다 자주 사용하지 마세요.이 콜백은 주로 실시간 제어(Real-time Control) 세션 중 조인트 상태, 모터 토크, 작업 공간(Task Space) 피드백을 모니터링할 때 사용합니다.
예제
// 콜백 함수 정의
void OnRTMonitoringData(LPRT_OUTPUT_DATA_LIST data) {
static int count = 0;
if (++count % 60 == 0) { // 60주기마다 출력(1kHz에서 약 0.06s)
printf("Timestamp: %.3lf\n", data->time_stamp);
printf("Actual Joint Position: %.3f %.3f %.3f %.3f %.3f %.3f\n",
data->actual_joint_position[0], data->actual_joint_position[1],
data->actual_joint_position[2], data->actual_joint_position[3],
data->actual_joint_position[4], data->actual_joint_position[5]);
printf("Actual Motor Torque: %.3f %.3f %.3f %.3f %.3f %.3f\n",
data->actual_motor_torque[0], data->actual_motor_torque[1],
data->actual_motor_torque[2], data->actual_motor_torque[3],
data->actual_motor_torque[4], data->actual_motor_torque[5]);
printf("----------------------------------------\n");
}
}
// 메인 프로그램
drfl.connect_rt_control("192.168.137.100", 12347);
string version = "v1.0";
float period = 0.001f; // 1 ms 주기
int losscount = 4;
// RT 모니터링 콜백 함수 등록
drfl.set_on_rt_monitoring_data(OnRTMonitoringData);
// 실시간 입출력 채널 설정
drfl.set_rt_control_input(version, period, losscount);
drfl.set_rt_control_output(version, period, losscount);
// 실시간 제어 시작
drfl.start_rt_control();
while (true) {
// 애플리케이션 로직 또는 모션 제어 루프
}
drfl.disconnect_rt_control();
이 예제는 OnRTMonitoringData()를 콜백 함수로 등록해 RT 제어 중에 로봇의 조인트 위치와 토크를 실시간으로 모니터링합니다.
팁
상태 피드백이 계속 필요한 애플리케이션(예: 토크 제어, 진단)에 권장합니다.
콜백 함수 규칙을 참고하세요.
RT 콜백에서
get_rt_control_input_version_list,get_rt_control_output_version_list,get_rt_control_input_data_list,get_rt_control_output_data_list,disconnect_rt_control을 호출하지 마세요. 호출이 반환되지 않습니다. RT 콜백에서connect_rt_control을 호출하면 false를 반환하고connect_rt_control() cannot be called from an RT callback을 출력합니다.RT에는 연결 해제 알림이 없습니다. RT 링크가 끊겼는지 감지하려면 read_data_rt나 RT 콜백의 time_stamp가 계속 증가하는지 확인하세요.