Modbus Motion Interface Examples

Examples

The following psuedocode examples illustrate how the master can use the MMI to achieve various motion objectives.

Minimum Steps to Read a Result

Reading the alignment register confirms that the addressing is properly understood. We expect to see the value 12345.

Read_Word(System_+_WordAlignmentCheck_w);

Minimum Steps to See an Effect

Before writing any commands the communication state must be set to enabled. Writing to the yellow LED register can turn the yellow application LED on and off.

Write_Word(System_+_ComunicationState_w,1);
Write_Word(System_+_TurnYellowLED_w,1);

Minimum Steps To Achieve Single Axis Motion

Assume that Snap2Motion has been used to establish an axis configuration through the Setup Tab and that a default current has also been set. The minimum steps to achieve motion would be:

Write_Word(System_+_ComunicationState_w,1);
Write_Word(Axis1_+_MotorOn_w,1);
Write_Single(Axis1_+_Jog_s,2);

Single Axis Configuration

This list of operations would replace the default axis configuraiton with one specified by the host:

Write_Word(System_+_ComunicationState_w,1);
Write_Double(Axis1_+_CountsPerUserUnit,51200);

{Set speed, accel, and decel for axis 1}
Write_Single(Axis1_+_Speed_s,3);
Write_Single(Axis1_+_Accel_s,10);
Write_Single(Axis1_+_Decel_s,10);

Single Axis Relative Move

This turns the motor on and moves 3 user units from the motor's current position

Write_Word(System_+_ComunicationState_w,1);
Write_Word(Axis_1+_MotorOn_w,1);
Write_Double(Axis1_+_BeginMoveBy_d,3);

Multiple Single Axis Moves

This example presumes a host side routines that polls a modbus word and waits until that register is not 0:

Write_Word(System_+_ComunicationState_w,1);
Write_Word(Axis1_+_MotorOn_w,1);
Write_Double(Axis1_+_BeginMoveBy_d,3);
WaitUntilRegisterNotZero(Axis1_+_MoveIsFinished_w);
Write_Double(Axis1_+_BeginMoveBy_d,-2);
WaitUntilRegisterNotZero(Axis1_+_MoveIsFinished_w);
Write_Double(Axis1_+_BeginMoveBy_d,1);
WaitUntilRegisterNotZero(Axis1_+_MoveIsFinished_w);

Starting and Monitoring a User Task

Controller resident programs can be written with Snap2Motion blocks or text style programming. These resident user tasks can be managed from a Modbus host.

Write_Word(System_+_ComunicationState_w,1);
Write_Word(System_+_UserTask1_w,BeginUserTask);
WaitUntilRegisterZero(System_+_UserTask1_w);

Performing a 3 Axis Coordinated Move

This series of operations identifies which axes will participate in a coordinated group, turn the motors on, establish a motion profile, and perform a vector move.

First describe which axes are participating in the coordinated group.

Write_Word(System_+_ComunicationState_w,1);
Write_Word(AxisGroup1_+_Motor1Index_w,1);
Write_Word(AxisGroup1_+_Motor2Index_w,2);
Write_Word(AxisGroup1_+_Motor3Index_w,3);
Write_Word(AxisGroup1_+_Motor4Index_w,0);

Turn on the motors in the group.

Write_Word(AxisGroup1_+_MotorOn_w,1);

Assign profile parameters.

Write_Single(AxisGroup1_+_Speed_s,2);
Write_Single(AxisGroup1_+_Accel_s,20);
Write_Single(AxisGroup1_+_Decel_s,20);

Assign each additional motion component parameter.

Write_Double(AxisGroup1_+_MoveParameter2_d,3);
Write_Double(AxisGroup1_+_MoveParameter3_d,1);

Commence motion by writing the first component position.

Write_Double(AxisGroup1_+_BeginMoveBy_d,2);

Wait until the motion is finished.

WaitUntilRegisterNonZero(AxisGroup1_+_MoveIsFinished_w);