Arbitrary unit conversions

It can be useful to convert real-world units to and from Zaber native units without sending a command to the device. An example may be checking what 1 cm is in native units for the currently connected device.

The example below shows how to use the library for this.

Python
C#
C++
JavaScript
MATLAB
Java
MATLAB (legacy)
const nativeUnits = axis.settings.convertToNativeUnits('pos', 1, Length.cm);
console.log('1 cm to native units:', nativeUnits);

const cm = axis.settings.convertFromNativeUnits('pos', 10000, Length.cm);
console.log('10000 native units to cm:', cm);
native_units = axis.settings.convert_to_native_units("pos", 1, Units.LENGTH_CENTIMETRES)
print("1 cm to native units:", native_units)

cm = axis.settings.convert_from_native_units("pos", 10000, Units.LENGTH_CENTIMETRES)
print("10000 native units to cm:", cm)
var nativeUnits = axis.Settings.ConvertToNativeUnits("pos", 1, Units.Length_Centimetres);
Console.WriteLine("1 cm to native units: {0}", nativeUnits);

var cm = axis.Settings.ConvertFromNativeUnits("pos", 10000, Units.Length_Centimetres);
Console.WriteLine("10000 native units to cm: {0}", cm);
double nativeUnits = axis.getSettings().convertToNativeUnits("pos", 1, Units.LENGTH_CENTIMETRES);
System.out.println("1 cm to native units: " + nativeUnits);

double cm = axis.getSettings().convertFromNativeUnits("pos", 10000, Units.LENGTH_CENTIMETRES);
System.out.println("10000 native units to cm: " + cm);
nativeUnits = axis.getSettings().convertToNativeUnits('pos', 1, Units.LENGTH_CENTIMETRES);
fprintf('1 cm to native units: %d.\n', nativeUnits);

cm = axis.getSettings().convertFromNativeUnits('pos', 10000, Units.LENGTH_CENTIMETRES);
fprintf('10000 native units to cm: %d.\n', cm);
nativeUnits = axis.Settings.convertToNativeUnits('pos', 1, Units.Length("cm"));
fprintf('1 cm to native units: %d.\n', nativeUnits);

cm = axis.Settings.convertFromNativeUnits('pos', 10000, Units.Length("cm"));
fprintf('10000 native units to cm: %d.\n', cm);
double nativeUnits = axis.getSettings().convertToNativeUnits("pos", 1, Units::LENGTH_CENTIMETRES);
std::cout << "1 cm to native units: " << nativeUnits << std::endl;

double cm = axis.getSettings().convertFromNativeUnits("pos", 10000, Units::LENGTH_CENTIMETRES);
std::cout << "10000 native units to cm: " << cm << std::endl;

The first argument of the method specifies the nature of the unit by referencing the name of the setting that uses it. The table below provides typical settings you can use for converting units.

PropertySettingLinear Device Units ExampleRotary Device Units Example
PositionposUnits.LENGTH_CENTIMETRESUnits.ANGLE_DEGREES
VelocitymaxspeedUnits.VELOCITY_MILLIMETRES_PER_SECONDUnits.ANGULAR_VELOCITY_DEGREES_PER_SECOND
AccelerationaccelUnits.ACCELERATION_MILLIMETRES_PER_SECOND_SQUAREDUnits.ANGULAR_ACCELERATION_DEGREES_PER_SECOND_SQUARED

The converted value will be specific to the axis, and you should use them only for that axis.

Reference

To read more about native units, refer to ASCII Protocol Manual (firmware version 7.xx)

API Reference: