Skip to main content

Function calls in Demo

#include <iostream>
#include "nrcAPI.h"
#include<stdio.h>
using namespace std;
void msgHook() {
NRC_Messsage tmp; //Define a message structure object
NRC_GetMesssage(1, tmp); //Assign the earliest message in the message queue to object 'tmp'.
printf("msgHooklocalTime=%d:%d::%d,0x%x,0x%x,0x%x,text=%s,size=%d\n",tmp.localTime.minute,tmp.localTime.second,tmp.localTime.milliseconds,tmp.kind,tmp.code,tmp.robot,tmp.text.c_str(),NRC_GetMesssageSize()); NRC_Delayms(200);
}
void SystemStartup()
{
std::string NRC_GetNexMotionLibVersion();//Get NexMotion library version information
cout << "Library version:" << NRC_GetNexMotionLibVersion() << endl;//Output NexMotion library version information
NRC_StartController(); //Start the control system
while (NRC_GetControlInitComplete() != 1) //Check if the control system initialization is complete
{
NRC_Delayms(100); //Delay 100ms
}
NRC_ClearAllError();//Clear all errors
cout << "StartController Success" << endl;
NRC_Delayms(200);
NRC_SetMsgHappenCallback(msgHook);//Set the callback function when the message occurs
}
void SetServoMap()
{
std::vector<int> servoMap = {0,0,0,0,0,0};//Robot mapping
int syncGroupNum = 1;//Number of external axis groups
int syncType[]={0,0,0};//External axis type
std::vector<std::vector<int>> syncServoMap={{0,0},{0,0},{0,0}};//External axis mapping, two dual-axis positioner
NRC_SetAllServoMapRelation(servoMap,syncGroupNum, syncType, syncServoMap);
}
void SettingofRobotRelatedParameters()
{
NRC_RobotDHConfig robotDHConfig = {321.5, 270,70,299, 78.5, 50, 0, 90, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};//DH parameter configuration
NRC_SetRobotDHConfig(robotDHConfig );//Set DH parameter configuration
NRC_RobotJointConfig robotJointConfig = {76.5, 17, 180, -180, 3000, -3000, 1, -1, 5, -5,1,1};//Joint parameter configuration
for (int i=1; i<7; i++)
{
NRC_SetRobotJointConfig(i,robotJointConfig );
}//Set joint parameter configuration
NRC_RobotRangeLimit robotRangeLimit = { true, 1000, true, -500, false, 300, true, -1000, false, 0, false, 3000 };//Range limit configuration
NRC_SetRobotRangeLimit(robotRangeLimit);//Set robot range limit
NRC_RobotDecareConfig robotDecareConfig = {1000, 3, -3};//Cartesian parameter configuration
NRC_SetRobotDecareConfig(robotDecareConfig);//Set Cartesian parameter configuration
}
void RobotMsg()
{
int ioNum;
std::string type1,type2;
cout<<"Number of robot axes:"<<NRC_GetRobotAxisSum()<<endl;
cout<<"Number of external axes"<<NRC_GetSyncAxisSum()<<endl;
NRC_GetEthercatIOConfig(ioNum, type1, type2);
cout<<"Number of expansion boards:"<<ioNum<<endl;
if(ioNum>0)
{
cout<<"Expansion board type:"<<type1<<" ,"<<type2<<endl;
}
}
void flicker(int j)
{
for (int i=j; i>0; i--)
{
NRC_DigOut(2, 1); //IO port 2 outputs high level
NRC_Delayms(1000); //Delay 1000ms
NRC_DigOut(2, 0); //IO port 2 outputs low level
NRC_Delayms(1000); //Delay 1000ms
}
}
int main()
{
SystemStartup();//System startup, see section 3.3 for details
RobotMsg();//Get the robot configuration, see section 3.4 for details
SetServoMap();//Set the servo mapping relationship, see section 3.5
SettingofRobotRelatedParameters();//Robot-related parameter settings, see section 3.6 for details
}