C/C++ for Windows

NI-Motion Functions

C/C++ for Windows

Data Returned by Reference

The NI-Motion functions that return data do so in variables whose address is passed into the function.

Example

To read position on an axis, you have to pass the address of the position variable.

i32 status;
i32 position;
u8 boardID = 1;
u8 axis = NIMC_AXIS1;
status = flex_read_pos_rtn (boardID, axis, &position);

The data position for axis one is returned in the position variable.

Data Returned in Arrays

While passing an array to a NI-Motion function, you need to pass the address of the beginning of the array.

Example

You would pass returnData as the parameter where returnData is an array of size MAX i32s.

#define MAX 12
i32 status;
u8 boardID;
i32 returnData [MAX];
boardID = 1;
status = flex_read_trajectory_data_rtn(boardID, returnData);

Trajectory data is returned in the returnData array and can be accessed by incrementing through the array.

NI-Motion Data Structures

Two data structures are used by the NI-Motion functions—the registry information data structure REGISTRY, and the PID parameters data structure PID.

The registry information data structure REGISTRY is used by the Read Object Registry function to get the information about the object registry on the NI motion controller. Refer to Onboard Programming Functions for more information about the object registry.

typedef struct {

   u16 device; // The object number
   u16 type; // The type of object
   u32 pstart; // The address where the object is stored
   u32 size; // Size of the object

} REGISTRY;

The PID parameters data structure PID is used by the Read Object Registry function to load the PID and PIVFF parameter for an axis. Refer to Axis & Resource Configuration Functions for more information on PID and PIVFF parameters.

typedef struct{

   u16 kp; //Proportional Gain
   u16 ki; //Integral Gain
   u16 ilim; //Integration Limit
   u16 kd; //Derivative Gain
   u16 td; //Derivative Sample Period
   u16 kv; //Velocity Gain
   u16 aff; //Acceleration Feedforward
   u16 vff; //Velocity Feedforward

} PID;

Example

While using the data structures, pass the address of the structure in the function.

i32 status;
u8 boardID=1;
u8 axis=NIMC_AXIS1;
u8 inputVector=0xFF;
PID PIDValues;
PIDValues.kp = 100;
PIDValues.ki = 0;
PIDValues.ilim = 1000;
PIDValues.kd = 1000;
PIDValues.td = 2;
PIDValues.kv = 0;
PIDValues.aff = 0;
PIDValues.vff = 0;
status = flex_load_pid_parameters(boardID, axis, &PIDValues, inputVector);