-
Notifications
You must be signed in to change notification settings - Fork 0
Initialization functions
The board must be initialized before any commands can be sent. After the board is initialized, each motor must be initialized individually. Motor initialization creates a motor instance (e.g. MCR.focus) that gives access to all movement and configuration functions for that motor.
Initialization sequence:
-
MCRControl()— open the board connection and initialize the controller sub-class -
focusInit(),zoomInit(),irisInit(),IRCInit()— initialize each motor sequentially -
close()— release the connection when done (unless done automatically when the program is terminated)
MCRControl(serialPortName, moduleDebugLevel=False, communicationDebugLevel=False, logFiles=True)Top-level class for all interactions with the MCR600 series boards. Opens the serial port and confirms the connection by reading the board firmware version. The controllerClass sub-class is created automatically as MCR.MCRBoard.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
serialPortName |
str |
— | Serial port name (e.g. 'com4' or '/dev/ttyAMA0') |
moduleDebugLevel |
bool |
False |
Set True to enable DEBUG-level console logging (default is INFO) |
communicationDebugLevel |
bool |
False |
Set True to print all serial port traffic to the console. Implies moduleDebugLevel=True. Not recommended in production. |
logFiles |
bool |
True |
Set True to write log files to the user's local application data directory |
Class variables
| Variable | Description |
|---|---|
MCRInitialized |
True when the class is successfully initialized (logging started) |
boardInitialized |
True when this board instance is initialized and the COM port is open |
boardCommunicationState |
True when the COM port is open and the board is responding |
boardCommunicationRestarts |
Count of times the COM port has been automatically reconnected |
Sub-classes
| Sub-class | Access | Description |
|---|---|---|
motor |
MCR.focus, MCR.zoom, MCR.iris, MCR.IRC
|
Motor movement and configuration (created by each motor init function) |
controllerClass |
MCR.MCRBoard |
Board-level commands (firmware revision, serial number, communication path) |
MCRCom |
internal | Serial port communication — not for direct use |
Example
#include "TheiaMCR.h"
#include <iostream>
int main() {
auto MCR = new TheiaMCR::MCRControl("COM4", true, false, false);
if (!MCR->isInitialized()) {
std::cerr << "Board not found. Check the COM port." << std::endl;
delete MCR;
return 1;
}
std::cout << "Board initialized: " << MCR->isInitialized() << std::endl;
MCR->close();
delete MCR;
return 0;
}focusInit(steps, pi, move=True, accel=0, homingSpeed=-1) -> boolInitialize the focus motor. Creates the MCR.focus motor instance. Must be called after board initialization.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
steps |
int |
— | Maximum number of steps for the full focus range |
pi |
int |
— | Step position of the photo interrupter (PI) limit switch |
move |
bool |
True |
True to move the motor to the home (PI) position during initialization; False to initialize without moving |
accel |
int |
0 |
Motor acceleration steps. See firmware documentation for support (not currently supported v.5.3.1.2.0). |
homingSpeed |
int |
-1 |
Speed (pps) to use when homing. Uses the default speed if set to -1 or out of range. Defaults to 1200pps. |
Returns True if initialization succeeded, False otherwise.
Example
// TL1250 lens
bool success = MCR->focusInit(8390, 7959);
// Initialize without moving to home
success = MCR->focusInit(8390, 7959, false);
// Set a custom homing speed
success = MCR->focusInit(8390, 7959, true, 0, 800);zoomInit(steps, pi, move=True, accel=0, homingSpeed=-1) -> boolInitialize the zoom motor. Creates the MCR.zoom motor instance. Must be called after board initialization.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
steps |
int |
— | Maximum number of steps for the full zoom range |
pi |
int |
— | Step position of the photo interrupter (PI) limit switch |
move |
bool |
True |
True to move the motor to the home (PI) position during initialization; False to initialize without moving |
accel |
int |
0 |
Motor acceleration steps. See firmware documentation for support (not currently supported v.5.3.1.2.0). |
homingSpeed |
int |
-1 |
Speed (pps) to use when homing. Uses the default speed if set to -1 or out of range. Defaults to 1200pps. |
Returns True if initialization succeeded, False otherwise.
Example
// TL1250 lens
bool success = MCR->zoomInit(3227, 3119);
// TL410 lens (PI near step 0)
success = MCR->zoomInit(4073, 154);irisInit(steps, move=True, homingSpeed=-1) -> boolInitialize the iris motor. Creates the MCR.iris motor instance. The iris motor does not have a photo interrupter limit switch; it uses a hard stop at step 0 (fully open) for homing. Must be called after board initialization.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
steps |
int |
— | Maximum number of steps (fully closed position) |
move |
bool |
True |
True to move the iris to the fully open (home) position during initialization; False to initialize without moving |
homingSpeed |
int |
-1 |
Speed (pps) to use when homing. Uses the default speed if set to -1 or out of range. Defaults to 100pps. |
Returns True if initialization succeeded, False otherwise.
Example
bool success = MCR->irisInit(75);IRCInit() -> boolInitialize the IRC (IR cut filter) motor. Creates the MCR.IRC motor instance. The IRC motor is a DC motor and is controlled differently from the stepper motors: it is driven for a fixed activation time rather than a step count.
At the default speed of 1000 pps, each step corresponds to approximately 1 ms of activation time. The maximum of 1000 steps gives 1 second of activation.
Returns True if initialization succeeded, False otherwise.
Example
bool success = MCR->IRCInit();close()Close the serial port and release all resources held by the MCR board instance. After calling close(), the MCR instance cannot be used again — create a new instance to reconnect.
Example
MCR->close();
delete MCR;#include "TheiaMCR.h"
#include <iostream>
int main() {
// Initialize board
auto MCR = new TheiaMCR::MCRControl("COM4", true, false, false);
if (!MCR->isInitialized()) {
std::cerr << "Board not found" << std::endl;
delete MCR;
return 1;
}
// Initialize motors (TL1250 lens)
MCR->focusInit(8390, 7959);
MCR->zoomInit(3227, 3119);
MCR->irisInit(75);
MCR->IRCInit();
std::cout << "Focus at step: " << MCR->focus.currentStep << std::endl;
std::cout << "Zoom at step: " << MCR->zoom.currentStep << std::endl;
// ... use the motors ...
MCR->close();
delete MCR;
return 0;
}