Skip to main content

Variable operation related

Global numeric variables can be used to pass information between the main program, called sub-program, and background program for logical judgment. Numeric variables store values, including boolean variables, integer variables, and double variables.

Int var

Call the function NRC_SetIntVar(int num, int value) to set the value of the INT variable. The parameter "num" is the number of the INT variable, with a value range of 0 < num <= 100, and "value" is the target value to be set.

Call the function NRC_ReadIntVar(int num) to read the value of the INT variable. The parameter "num" is the number of the INT variable, with a value range of 0 < num <= 100.

Double var

Call the function NRC_SetDoubleVar(int num, double value) to set the value of the DOUBLE variable.The parameter "num" is the number of the DOUBLE variable, with a value range of 0 < num <= 100, and "value" is the target value to be set.

Call the function NRC_ReadDoubleVar(int num) to read the value of the DOUBLE variable. The parameter "num" is the number of the DOUBLE variable, with a value range of 0 < num <= 100.

Bool var

Call the function NRC_SetBoolVar(int num, bool value) to set the value of the BOOL variable.The parameter "num" is the number of the BOOL variable, with a value range of 0 < num <= 100, and "value" is the target value to be set.

Call the function bool NRC_ReadBoolVar(int num) to read the value of the BOOL variable. The parameter "num" is the number of the BOOL variable, with a value range of 0 < num <= 100.

#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 the object tmp
printf("msgHook localTime=%d:%d::%d, 0x%x,0x%x,text=%s,size=%d\n",tmp.localTime.minute, tmp.localTime.second, tmp.localTime.milliseconds, tmp.kind, tmp.type, tmp.text.c_str(),NRC_GetMesssageSize());
NRC_Delayms(200);
}
int main ()
{
SystemStartup();//System startup, see section 3.3 for details
SetServoMap();//Set the servo mapping relationship, see section 3.5 for details
SettingofRobotRelatedParameters();//Robot-related parameter settings, see section 3.6 for details
//////The above call functions can be found in Appendix I/////
NRC_SetServoReadyStatus(1);//Set servo ready status, see section 3.8 for details
NRC_SetInterpolationMethod(1);//Set to S-shaped interpolation, see section 3.12 for details
NRC_SetOperationMode(NRC_RUN_);//Set the operation mode to run mode, see section 3.11 for details
NRC_SetAutoRunSpeedPer(80);//Set the auto-run speed to 80, see section 3.11 for details
NRC_Delayms(1000);//Delay 1000ms

NRC_SetIntVar(1, 6);//Set int variable 6, number 1
NRC_SetIntVar(2, 7);//Set int variable 7, number 2
NRC_SetDoubleVar(1, 6.6);//Set double variable 6.6, number 1
NRC_SetBoolVar(1, 0);//Set boolean variable 0, number 1
NRC_SetBoolVar(2, 1);//Set boolean variable 1, number 2

cout << "log : " << "GI001=" << NRC_ReadIntVar(1) << " GI002=" << NRC_ReadIntVar(2) << " GD001=" << NRC_ReadDoubleVar(1)<< " GA001=" << NRC_ReadBoolVar(1)<<endl;
while(1)
{
NRC_Delayms(2*1000);
cout << "bool=" << NRC_ReadBoolVar(2) << endl;
cout << "int=" << NRC_ReadIntVar(1) << endl;
cout << "double=" << NRC_ReadDoubleVar(1) << endl;

if (NRC_ReadIntVar(1) == 50)
{
cout << "111111111" << endl;
NRC_SetBoolVar(5, true);
NRC_SetIntVar(5, 66);
NRC_SetDoubleVar(5, 66.66);
cout <<"Set successfully"<<endl;
}
if (NRC_ReadIntVar(1) == 6)
{
cout << "222222222222" << endl;
NRC_SetBoolVar(5, false);
NRC_SetIntVar(5, -88);
NRC_SetDoubleVar(5, -88.88);
cout <<"Set successfully"<<endl;
}
}
}