Chapter 14
Onboard Programs
14-38
ni.com
C/C++ Code
The following example code is not necessarily complete, and may
not compile if copied exactly. Refer to the
examples
folder on the
NI-Motion CD for files that are complete and compile as is.
//
Main Function
void main(void)
{
u8
boardID;//
Board identification number
u8
axis; //
Axis number
u16
csr = 0;//
Communication status register
//
Variables for modal error handling
u16
commandID;//
The commandID of the function
u16
resourceID;//
The resource ID
i32
errorCode;//
Error code
//
Set the board ID
boardID = 1;
//
Set the axis number
axis = NIMC_AXIS1;
//-----------------------------------------------
//
Onboard program 2. This onboard program moves axis
one clockwise
//
5,000 counts (steps). This onboard
program is executed by onboard
//
program one.
//-----------------------------------------------
//
Begin onboard program storage - program number 2
err =
flex_begin_store
(boardID, 2);
CheckError;
//
Set the operation mode to relative
err =
flex_set_op_mode
(boardID, axis,
NIMC_RELATIVE_POSITION);
CheckError;
//
Load Target Position to move clockwise 5,000
counts(st
eps)
err =
flex_load_target_pos
(boardID, axis, 5000,
0xFF);
CheckError;
//
Load Velocity in RPM
err =
flex_load_rpm
(boardID, axis, 100.00, 0xFF);
CheckError;
//
Load Acceleration and Deceleration in RPS/sec