National Instruments NI-Motion User Manual

Page 239

Advertising
background image

Chapter 14

Onboard Programs

© National Instruments Corporation

14-31

NI-Motion User Manual

err = flex_load_var(boardID, targetPosition, 1);

CheckError;

// Begin onboard program storage - program number 1

err = flex_begin_store(boardID, 1);

// Set the operation mode to absolute position

err = flex_set_op_mode(boardID, axis,

NIMC_ABSOLUTE_POSITION);

CheckError;

// Set the velocity

err = flex_load_velocity(boardID, axis, 10000,

0xFF);

CheckError;

// Insert Label number 1

err = flex_insert_program_label(boardID, 1);

CheckError;

// Load Target Position from onboard variable 1

err = flex_load_target_pos(boardID, axis, 0, 1);

CheckError;

// Start the move

err = flex_start(boardID, axis, 0);

CheckError;

// Wait for move to complete

err = flex_wait_on_event(boardID, 0, NIMC_WAIT,

NIMC_CONDITION_MOVE_COMPLETE,

(u8)(1<<axis)/*Indicates axis to wait on*/, 0,

NIMC_MATCH_ALL, 3000 /*time out*/, 0);

CheckError;

// Multiply variable 1 (target position) with 2

(multiplier)

// Save the result in variable 1 - this calculates

the negative of //last target position

err = flex_mult_vars(boardID, 1, 2, 1);

CheckError;

// Set the 13th bit in the move complete status

register so that //the host knows that the axis is

about to reverse direction

err = flex_set_status_momo(boardID, 0x20, 0);

CheckError;

// Jump unconditionally to load new target position

Advertising