Application note

# Intro to MCode: Basic Motion Commands

Home > Resources > Application notes > Intro to MCode: Basic Motion Commands

### Description

This tutorial covers the basic variables and instructions impacting motion. The motion commands are common between the Lexium MDrive products and the MDrive/MForce products. The only variation is with the value scaling for encoder based move commands, as the Lexium MDrive closed loop products have a 1000 line (4000 counts) encoder, where MDrive motion products with an encoder have a 512-line (2048 count) encoder.

### Applicable

• Lexium MDrive
• MDrive Linear Actuator
• MDrive Plus
• MForce

#### Requirements

1. PC with the Motion Control Programmer application installed
2. A Lexium MDrive Motion Control connected to power and RS-422/485 communication.

### Motion variables and commands covered

Variables

• A – Acceleration
• D – Deceleration
• MS – Set microstep resolution
• VI – Initial velocity
• VM – Maximum velocity

Commands

• MA – Move to absolute position
• MR – Move to relative position
• SL – Slew at constant velocity

### MCode motion variables

The relationship between VI, VM, A and D is shown in the motion profile diagram on the right. The following details the sequence of events when a motion command is given.

1. The motor will accelerate from VI to VM based upon the setting of A in steps per second^2.
2. Upon reaching VM, the motor will index at the velocity specified by VM in steps per second.
3. Before reaching the commanded position, the axis will decelerate at the rate in steps per second^2.Note: Setting VI to a high value could cause a motor stall.

The relationship of MS (Microstep Resolution select) and the motion variables

The motion variables are all based on microsteps as the unit of measure. The ratio between the microstep resolution setting and the variables is an important factor in how the motor will perform. Using the factory default settings as a baseline, for example, we can see that when we change the step resolution of the device, the motion variable may also need to be changed.

For example, the default settings of the Lexium MDrive Motion Control:

 MS (steps/rev) VI VM A D Default 51200 1000 768000 1000000 1000000 New 200 4 3000 3906 3906 Ratio MS: 1:0.20 1:15 1:19.5 1:19.5

As shown in the table, the settings for a particular velocity profile can change dramatically based on the microstep resolution setting.

### Move to a relative position (MR)

A moving relative (MR) moves an offset distance (motor steps) from the current position. In the case of the profile shown above the end position of the first move will be 1 + 2, or 0 + 51200. The position will be 51200 steps from 0.

The second move of +51200 steps will end at position 3 or 51200 steps from position 2. The third MR will index the axis 153600 steps in the negative direction from position 3.

Note that if the position counter is read using PR P, the counter will read in steps from 0 or -51200.

### Move to an Absolute Position (MA)

A move absolute (MA) moves a distance (motor steps) from the 0. In the case of the profile shown above the end position of the first move will be 1 + 2, or 0 + 51200. The position will be 51200 steps from 0.

The second move of +51200 steps will end at position 3 or 102400 steps from position 2. The third MA will index the axis 153600 steps in the negative direction from position 3, with a final position of -51200 absolute from 0.

### Slew at velocity (SL)

Slew (SL) is used to index the axis at a constant velocity. The motor will continue to slew at commanded velocity until an SL 0, or escape is commanded.

Note that SL will function independent of the VM setting. If a velocity greater than VM is commanded the motor will accelerate to the commanded velocity, ignoring the setting of VM.

### Using an encoder

If the encoder is enabled the move commands use different values. The encoder has 1000 lines and yields 4000 counts or counts per revolution, as shown in the diagram at right.

Therefore, the MR and MA command values are programmed in encoder counts. One full revolution would be programmed as MR or MA 4000.

When the encoder is enabled, the MS value defaults to 256.

Knowing these factors, you can program a multitude of different movements, speeds, and time intervals.

The default values for the motion variables is now used in encoder counts with the following values:

 MS VI VM A D 51200 78 60000 78125 78125

Encoder related variables and commands

Note that when the Lexium MDrive is in an hMTechnology mode (AS=1, 2 or 3) the encoder functions become irrelevant.

Resource files

### Custom Products

When it comes to your form, fit and function requirements, don’t settle. Get precisely what you need working with us. We know motion.