1.切换示教员,然后在示教器释放掉控制权
2.连接机器人代码
#include <memory>
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MP_Public_API.h"
int main()
{
int64_t llRet = MP_SUCCESS;
// Create Handle
void * pHandle = MP_CreateHandle();
if (nullptr == pHandle)
{
printf("Create Handle fail!\n");
}
else
{
printf("Create Handle Success!\n");
do
{
// Connect Controller Wth IP Address
char szConnectInfo[BUFFER_LEN_32] = { "127.0.0.1:9000" };
//请查看通讯管理中的IP,并改为Socket通讯
llRet = MP_ConnectCtrlWithIP(pHandle, szConnectInfo);
if (MP_SUCCESS != llRet)
{
printf("Connect Ctrl With IP fail! llRet [0x%x]\n", llRet);
MP_DestroyHandle(pHandle);
break;
}
printf("Connect Controller With IP Success!\n");
Sleep(500);
// Request Control Access
llRet = MP_RequestControlAccess(pHandle);
if (MP_SUCCESS != llRet)
{
printf("Request Control Access fail! llRet [0x%x]\n", llRet);
MP_DestroyHandle(pHandle);
break;
}
printf("Request Control Access Success!\n");
// Disconnect Controller
llRet = MP_DisConnectCTRL(pHandle);
if (MP_SUCCESS != llRet)
{
printf("Disconnect Ctrl With IP fail! llRet [0x%x]\n", llRet);
MP_DestroyHandle(pHandle);
break;
}
printf("Disconnect Ctrl With IP Success!\n");
// Destroy Handle
llRet = MP_DestroyHandle(pHandle);
if (MP_SUCCESS != llRet)
{
printf("Destroy Handle fail! llRet [0x%x]\n", llRet);
break;
}
printf("Destroy Handle Success!\n");
} while (false);
}
system("pause");
return 0;
}
3.各部分讲解
int64_t llRet = MP_SUCCESS;//用于各部分的标志位执行判断
void* pHandle = MP_CreateHandle();//创建连接句柄
char szConnectInfo[BUFFER_LEN_32] = { "192.168.3.64:9000" };llRet = MP_ConnectCtrlWithIP(pHandle, szConnectInfo);//连接机器人
llRet = MP_RequestControlAccess(pHandle);//请求机器人控制权
llRet = MP_DisConnectCTRL(pHandle);//断开机器人控制器
llRet = MP_DestroyHandle(pHandle);//销毁机器人句柄
llRet = MP_ReleaseControlAccess(pHandle);//释放机器人控制权