// ProfileMotionConstrait.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
// 该例程仅用于功能演示,请保证安全的情况下使用
// 测试功能:规划运动飞车保护功能
// 测试平台:网络型运动控制器
// 测试环境:Windows
// 测试流程:
// (1)初始化控制器
// (2)配置规划器运动限制
// (3)关闭控制器
// 注意事项:
// (1)本例程使用的“例程专用.xml”、“例程专用.cfg”,仅用于本例程
// (2)实际使用时,需要使用MotionStudio生成网络配置xml
// 加载固高运动控制库头文件
#include "gxn.h"
// 动态加载固高运动控制gxn.lib库
#pragma comment(lib,"gxn.lib")
/**
* @brief 指令出错打印函数
* @param command 打印信息字符串
* @param error 错误码
* @return 错误码
*/
short CommandHandler(char* command, short error)
{
printf("%s = %d\n", command, error);
getchar();
return error;
}
/**
* @brief 初始化运动控制器(开卡 + 初始化网络拓扑 + 初始化轴)
* @param core 需要初始化的核号,从1开始
* @param axis 需要初始化的轴起始索引,从1开始
* @param axisCount 需要初始化的轴数量,从起始索引axis开始计数,必须大于0
* @return 0表示初始化成功,非0表示初始化失败
*/
short InitMc(short core,short axis,short axisCount)
{
short rtn;
short overTime;
long status;
// 打开运动控制器
rtn = GTN_OpenCard(CHANNEL_PCIE,NULL,NULL);
if ( 0 != rtn )
{
return CommandHandler("GTN_OpenCard",rtn);
}
printf("Open Card Success !\n");
// 初始化网络
// 注意:(1)“例程专用.xml”仅用于本例程
// (2)实际使用时,需要使用MotionStudio生成对应的网络配置文件
// overTime:网络初始化超时时间,单位:秒
overTime = 120;
rtn = GTN_NetInit(NET_INIT_MODE_XML_STRICT,"例程专用.xml",overTime,&status);
if ( 0 != rtn )
{
printf("status = %d\n",status);
return CommandHandler("GTN_NetInit",rtn);
}
printf("Init Net Success !\n");
// 加载配置文件到控制器
// 注意:(1)“例程专用.cfg”仅用于本例程
// (2)实际使用时,需要使用MotionStudio生成对应的配置文件
rtn = GTN_LoadConfig(core,"例程专用.cfg");
if ( 0 != rtn )
{
return CommandHandler("GTN_LoadConfig(\"例程专用.cfg\")",rtn);
}
// 清除轴状态
rtn = GTN_ClrSts(core,axis,axisCount);
if ( 0 != rtn )
{
return CommandHandler("GTN_ClrSts",rtn);
}
printf("Init Mc Config Success !\n");
return rtn;
}
int _tmain(int argc, _TCHAR* argv[])
{
short rtn; // 指令返回值
short core; // 需要执行例程的运动控制器核号
short axis; // 需要初始化的轴起始索引号
short axisCount; // 需要初始化的轴数量,从轴起始索引号开始算起
// 初始化运动控制器
// 开卡 + 初始化网络拓扑 + 初始化核1的1-8轴
core = 1;
axis = 1;
axisCount = 8;
rtn = InitMc(core,axis,axisCount);
if ( 0 != rtn )
{
return rtn;
}
short profile; // 规划器号
double velMax; // 最大速度限制,单位:pulse/ms
double accMax; // 最大加速度限制,单位:pulse/ms^2
profile = 1;
rtn = GTN_GetProfileMotionConstraint(core,profile,&velMax,&accMax);
if ( 0 != rtn )
{
return CommandHandler("GTN_GetProfileMotionConstraint",rtn);
}
printf("Current velMax:%lf accMax:%lf of profile:%d\n",velMax,accMax,profile);
velMax = 50;
accMax = 20;
rtn = GTN_SetProfileMotionConstraint(core,profile,velMax,accMax);
if ( 0 != rtn )
{
return CommandHandler("GTN_SetProfileMotionConstraint",rtn);
}
printf("Set velMax:%lf accMax:%lf to profile:%d\n",velMax,accMax,profile);
// 关闭控制器
rtn = GTN_Close();
if ( 0 != rtn )
{
return CommandHandler("GTN_Close",rtn);
}
printf("Press Any Key To Exit !\n");
getchar();
return 0;
}