Focus and Zoom Control - derangedhk417/MicroscopeControl GitHub Wiki
Introduction
Control of the focus and zoom knobs of the microscope is handled in the FocusControl.py file. The documentation used to develop this code is located in documentation/Second_Generation_Controller_Protocol_v1.0.pdf
. Several odd behaviors were encountered during development. Please read this page before attempting to modify the code.
General Functionality
The FocusController
class exposes the functionality of the serial command interface provided by the motor controller in a simple manner. The user can read and set both acceleration and velocity values for the motors. They can retrieve the current position of the motors and move them to specified positions. This class also exposes the "increment" functionality provided by the serial interface, so that the user can move the motors by small increments.
This class reads the limit values of the two motors on startup and attempts to prevent the user from moving the motors past their limits. Values passed to the setZoom
, setFocus
, incrementZoom
and incrementFocus
functions are expected to be scaled to the range [0.0, 1.0], which maps to the minimum and maximum values for the motors.
The values read from and sent to the controller for acceleration and velocity values are raw, uncorrected values. They are not scaled like the values for the current position of the motor.
Operations that take more than 100 ms (such as moving a motor), have an optional callback parameter. When this parameter is specified, these operations will return immediately and will call the specified callback function when the operation completes.
Notes and Odd Behavior
- The motor controller will not save any changes made to the acceleration and velocity values. There is a way to save these values from the serial interface, but I see no reason to do that when they can just as easily be saved on the computer and set at startup time.
- I didn't find any documentation on the exact specifications of the serial connection used by the controller. A baud rate of 38400 seems to work though.
- EDIT I discovered some instability with a baud rate of 38400. A baud rate of 115200 seems to work better.
- The documentation states "all serial port settings (such as baud rate, etc) are irrelevant". Which I find suspect given how unreliable the serial connection seems to be.
- The controller will echo back your command when it is sent. If you send too many commands per second, the command it echos back will sometimes be corrupted. I suspect that there is something wrong with the code on the controllers end. Everything seems to work fine if you don't send commands more than once every 50 milliseconds.
- Motor 1 is the zoom motor and motor 2 is the focus motor (when referenced in the documentation).
- The motor takes zoom and focus commands as integers. These integers are between 0 and some maximum number. The maximum (or limit) for each motor can be read with
read setup_limit_1\n
andread setup_limit_2\n
for motors 1 and 2 respectively. - The motor controller does not queue commands. If you send a movement command while another command is being processed, it will fail.
- Despite what the documentation says, the "idle" bit in the status register doesn't indicate whether or not the motor is idle. You need to wait for all bits to be zero except for the idle bit before sending commands.
- The documentation lists bits in Big-Endian format, meaning that bit 0 is the most significant bit. For example, the documentation refers to bit 0 as the idle bit, but this must be read with
(flags & 0b100000000000000) >> 14
.