Skip to main content

Robot configuration

In the new version of nrcAPI.h, when the system is started with NRC_StartController(), the robot type, servo type, and IO board model will be automatically set by the system. Even for new control systems, there is no need to write a separate configuration program. The functions NRC_SetEthercatIOConfig() and NRC_SetServoTypeConfig() have been removed from the earlier versions, while the functions NRC_SetRobotTypeConfig() and NRC_SetIOTypeConfig() have been retained. Additionally, the NRC_SetServoMapRelation() function for setting servo mapping relationships has been added. It should be noted that when running a program on the inexbot controller to simulate robot actions, the servo should be set to virtual servo, and the corresponding parameter for virtual servo should be set to 0.

Set robot type

Setting the robot type is a prerequisite for the robot to operate normally. This interface supports four robot types. Call the function NRC_SetRobotTypeConfig(std::string type) to set the robot type. After the robot parameters are set, the teach pendant needs to be restarted to take effect.

The parameter "type" indicates the robot type:

  • "R_GENERAL_6S": 6-axis
  • "R_SCARA": 4-axis SCARA
  • "R_FOURAXIS_PALLET": 4-axis palletizing
  • "R_FOURAXIS": 4-axis
  • "R_GENERAL_1S": 1-axis
  • "R_GENERAL_5S": 5-axis
  • "R_GENERAL_6S_1": 6-axis special-shaped 1
  • "R_SCARA_TWOAXIS": 2-axis SCARA
  • "R_SCARA_THREEAXIS": 3-axis SCARA
  • "R_THREE_CARTESIAN_COORDINATE": 3-axis Cartesian
  • "R_THREE_CARTESIAN_COORDINATE_1": 3-axis special-shaped 1
  • "R_GENERAL_7S_RBT": 7-axis
  • "R_SCARA_1": 4-axis SCARA special-shaped 1

IO configuration

(1) Set the type of the extended IO by calling the function int NRC_SetIOTypeConfig(std::string type). This interface supports two types of IO parameter settings. If it is an EtherCAT extended IO, set the type to "none" and the controller will automatically recognize it. If a non-EtherCAT extended IO is connected, setting the type to "custom" will not take effect. After setting the parameter, you need to restart the controller for the changes to take effect. It needs to be set according to actual work requirements. The following demo program uses EtherCAT extended IO.

The parameter "type" indicates the extended IO type:

  • "none": no extended IO or automatic recognition of extended IO
  • "custom": custom extended IO

(2) When selecting "custom" as the type of extended IO, it is necessary to define the number and addresses of the custom IO, including custom IO dout and IO din.

Set the number and corresponding address of custom IO dout by calling the function NRC_SetCustomIODoutConfig(int sum, int* addr), 1 means high level, 0 means low level. The parameter "sum" is the number of custom IO douts, and the parameter range: sum >= 0. The parameter "addr" indicates the corresponding address of the custom IO dout.

Set the number and corresponding address of custom IO din by calling the function NRC_SetCustomIODinConfig(int sum, int* addr), 1 means high level, 0 means low level. The parameter "sum" is the number of custom IO dins, and the parameter range: sum >= 0. The parameter "addr" indicates the corresponding address of the custom IO din.

Here's an example of custom IO:

..........
NRC_SetIOTypeConfig("custom");//Custom extended IO type
int inexbotIn[32] = {0};//Define an array
int inexbotOut[32] = {0};//Define an array
NRC_SetCustomIODoutConfig(32, inexbotIn);//Set custom IO dout configuration
NRC_SetCustomIODinConfig(32, inexbotOut);//Set custom IO din configuration
..........

IO port invocation

Output digital port information by calling the function NRC_DigOut(int port, int value), where "port" is the digital IO port to be output, with a maximum range of 1 <= port <= 16. The actual range depends on the number of IO ports on the connected IO module. "value" is the state to be output, value=0 means output low level, value=1 means output high level.

Call the function NRC_ReadDigOut(int port) to read the state of the digital IO output port. The parameter "port" specifies the digital IO port to be read, with a maximum range of 1 <= port <= 16. The actual range depends on the number of IO ports on the connected IO module. The return value indicates the current state of the specified port, where "retval=0" means that the port is currently at a low level, "retval=1" means that the port is currently at a high level, and "retval=-1" indicates that the specified port does not exist.

Call the function NRC_ReadDigIn(int port) to read the state of the digital IO input port. The parameter "port" specifies the digital IO port to be read, with a maximum range of 1 <= port <= 16. The actual range depends on the number of IO ports on the connected IO module. The return value indicates the current state of the specified port, where "retval=0" means that the port is currently at a low level, "retval=1" means that the port is currently at a high level, and "retval=-1" indicates that the specified port does not exist.

Get robot configuration

In the new version of library, the robot will be automatically configured when the system starts, and we can call related functions to get these configuration information.

  • Get the number of robot axes: int NRC_GetRobotAxisSum();
  • Get the number of external axes: int NRC_GetSyncAxisSum();
  • Get the total number and type of IO expansion boards: int NRC_GetEthercatIOConfig(int& sum, std::string& type1, std::string& type2). The parameter "sum" is used to return the total number of expansion boards, and "type1" and "type2" are used to return the type of expansion boards.

C++ demo program for robot configuration and IO port call

#include <iostream>
#include "nrcAPI.h"
using namespace std;
void robotsetting()
{
NRC_SetRobotTypeConfig("R_GENERAL_6S");//6-axis
NRC_SetIOTypeConfig("ethercat");
}
void flicker(int j)
{
for (int i=j; i>0; i--)
{
NRC_DigOut(2, 1); //IO port 2 output high level
NRC_Delayms(1000); //Delay 1000ms
NRC_DigOut(2, 0); //IO port 2 output low level
NRC_Delayms(1000); //Delay 1000ms
}
}
void RobotMsg()
{
int ioNum;
std::string type1,type2;
cout<<"Number of robot axes:"<<NRC_GetRobotAxisSum()<<endl;
NRC_GetEthercatIOConfig(ioNum, type1, type2);
cout<<"Number of expansion boards:"<<ioNum<<endl;
if(ioNum>0)
{
cout<<"Expansion board type:"<<type1<<", "<<type2<<endl;
}
}int main()
{
SystemStartup();//System startup, see section 3.3 for details
robotsetting();//Set the robot configuration, for program simplicity, adopt a function call form
RobotMsg(); //Get robot configuration, implement IO calls in the form of function calls for program simplicity
int inexbot6=NRC_ReadDigOut(1);//Read the status of digital IO output port 1
if( inexbot6 == -1 )
{
cout << "The port does not exist" << endl;
}
else
{
NRC_DigOut(1, inexbot6); //IO port 1 output status
NRC_Delayms(1000); //Delay 1000ms
}
flicker (15);//IO port 2 blinks 15 times
int inexbot8=NRC_ReadDigIn(1);//Read the status of digital IO input port 1
if( inexbot8== -1 )
{ cout << "The port does not exist" << endl ;}
else if(inexbot8==1)
{cout << "Currently at a high level" << endl;}
else
{cout << "Currently at a low level" << endl;}
}

When calling the inexbotAPI to make the robot move, you need to set the parameters according to the servo and IO settings of the robot you want to run, and then you need to restart the controller to make the settings take effect and generate the corresponding configuration file.When calling inexbotAPI to make the robot move, you need to call the corresponding API to set the parameters according to the servo and IO settings of the actual robot to be run. After setting, you need to restart the controller to make the parameter settings take effect and generate the corresponding configuration file.