/*
 * Discrete motion script
 *
 * The script opens two axes by serial numbers.
 * Warning: enter the serial numbers of your axes.
 *
 * Moves along the X axis to a certain coordinate
 * Then it begins to shift discretely along the Y axis,
 * with a programmable pause after each offset.
 */

// Enter the serial numbers of your axes.
serial_number_x = 14889;
serial_number_y = 14888;

var x = new_axis(serial_number_x);
var y = new_axis(serial_number_y);

// Installing the source data
var x_target_coordinate = 5000; // first border coordinate
var delay = 100; // delay in milliseconds

var y_first_border = 0; // first border coordinate
var y_second_border = 5000; // second border coordinate 
var y_step = 100
var y_direct = 1

// Calibration and positioning of the axes to their original positions.
x.command_stop(); // send STOP command (does immediate stop)
x.command_zero(); // send ZERO command (sets current position and encoder value to zero)
y.command_stop(); // send STOP command (does immediate stop)
y.command_zero(); // send ZERO command (sets current position and encoder value to zero)

x.command_move(x_target_coordinate); // move to wards one border
x.command_wait_for_stop(10); // wait until controller stops moving
y.command_move(y_first_border); // move towards one border
y.command_wait_for_stop(10); // wait until controller stops moving

// Movement in discrete samples along one axis from the end to the end
// with a delay after each movement.
while (1) { // infinite loop

 // Choosing the direction of travel
 if (y.get_position() >= y_second_border)
 {
  y_direct = -1
 }
 if (y.get_status().CurPosition <= y_first_border)
 {
  y_direct = 1
 }

 // Movement in a given direction
 y.command_movr(y_step*y_direct); // move towards another border
 y.command_wait_for_stop(10); // wait until controller stops moving
 msleep(delay);
}