Hey Samantha,
It looks like you're running into two separate issues with the Zaber motion control library:
- moveRelative is not recognized – This likely happens because axis is not properly initialized when you first try to use it.
- Motor runs indefinitely – This could be due to missing await calls that ensure motion commands complete before proceeding.
Potential Fixes1. Fixing moveRelative Not Found Error
Instead of calling home() on all axes before initializing axis, try:
- Make sure device is detected properly.
- Ensure the device is correctly homed before moving.
import zaber.motion.ascii.Connection;
import zaber.motion.Units;
connection = Connection.openSerialPort('COM3');
try
connection.enableAlerts();
deviceList = connection.detectDevices();
if deviceList.isEmpty()
error('No Zaber devices found. Check the connection.');
end
fprintf('Found %d devices.\n', deviceList.length);
device = deviceList(1);
axis = device.getAxis(1);
% Make sure the device is homed
if ~axis.isHomed()
axis.home().await(); % Ensure home completes before proceeding
end
% Move to 10mm
axis.moveAbsolute(10, Units.LENGTH_MILLIMETRES).await();
% Move by an additional 5mm
axis.moveRelative(5, Units.LENGTH_MILLIMETRES).await();
% Close connection after movement is complete
connection.close();
catch exception
connection.close();
rethrow(exception);
end
Why This Should Work
✅ Ensures device is detected properly before proceeding.
✅ Adds .await() after home(), moveAbsolute(), and moveRelative() to wait for each command to finish before the next one starts.
✅ Closes the connection properly so the motor doesn't keep running in an undefined state.
This should prevent the motor from running indefinitely while also ensuring moveRelative works as expected.
If this helps, follow me so you can message me anytime with future MATLAB or Simulink questions! 🚀