Skip to content

Commit

Permalink
Add folder with micromanager config file and add stop/start function …
Browse files Browse the repository at this point in the history
…for loghthouse plus solve bug in movement
  • Loading branch information
sfbarrerab committed Jun 10, 2024
1 parent 7563186 commit 15b6d9f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 37 deletions.
10 changes: 6 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def __init__(self):
try:
self.core = Core()
print(self.core)
print("micromanager connection established succesfully!")
except:
print("Did you open uManager with the proper configuration?")
return -1


# Init arduino serial communication
Expand All @@ -63,8 +65,8 @@ def initUI(self):
self.current_slider, self.current_text = self.create_slider_with_text('Current', -300, 300, 0, self.change_optotune_current)

# Sliders for motor frequency and amplitude
self.frequency_slider, self.frequency_text = self.create_slider_with_text('Acceleration', 1000, 15000, 1000, self.send_acc_serial_command)
self.amplitude_slider, self.amplitude_text = self.create_slider_with_text('Amplitude', 10, 100, 100, self.send_width_serial_command)
self.acceleration_slider, self.acceleration_text = self.create_slider_with_text('Acceleration', 1000, 15000, 5000, self.send_acc_serial_command)
self.amplitude_slider, self.amplitude_text = self.create_slider_with_text('Amplitude', 20, 100, 100, self.send_width_serial_command)

# Main layout setup
main_layout = QVBoxLayout()
Expand All @@ -81,7 +83,7 @@ def initUI(self):
main_layout.addLayout(self.y_slider)
main_layout.addLayout(self.z_slider)
main_layout.addLayout(self.current_slider)
main_layout.addLayout(self.frequency_slider)
main_layout.addLayout(self.acceleration_slider)
main_layout.addLayout(self.amplitude_slider)

self.setLayout(main_layout)
Expand Down Expand Up @@ -165,7 +167,7 @@ def print_values(self):
print("Y Position:", self.y_text.text())
print("Z Position:", self.z_text.text())
print("Current:", self.current_text.text())
print("Frequency:", self.frequency_text.text())
print("Frequency:", self.acceleration_text.text())
print("Amplitude:", self.amplitude_text.text())
print("Exposure:", self.exposure_text.itemAt(1).widget().text())
print("Alpha:", self.alpha_text.itemAt(1).widget().text())
Expand Down
65 changes: 33 additions & 32 deletions arduino/step_motor_LSM/src/motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ TMC2130Stepper driver = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN);
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN, DIR_PIN);

bool dir = true;
int sheet_width = 200;
int sheet_width = 100;
long headAcceleration = 5000;
long cero_position = 0;

void init_motor() {

pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);

// Grab the initial position and set it as the cero position
cero_position = stepper.currentPosition();


driver.begin();
driver.rms_current(600); // Set stepper current to 600mA
driver.stealthChop(1); // Enable extremely quiet stepping
Expand All @@ -26,49 +22,54 @@ void init_motor() {
stepper.setAcceleration(headAcceleration);
stepper.setEnablePin(EN_PIN);
stepper.setPinsInverted(false, false, true);
stepper.enableOutputs();
//stepper.enableOutputs();
// Grab the initial position and set it as the cero position
//stepper.setCurrentPosition(0);
}

void task_move_motor(void *pvParameters) {
command_t received_command;
long current_position;
int new_sheet_width = sheet_width;
int first_move = true;
bool first_move = true;
bool start_movement = false;

while(1)
{
// If there is an element in the queue...
if(x_received_commands_queue != NULL && xQueueReceive(x_received_commands_queue, (void *)&received_command, 0) == pdTRUE){
if(received_command.command == "w"){
new_sheet_width = received_command.value;
}else if (received_command.command == "a"){
if(received_command.command == "w"){ // change width
sheet_width = received_command.value;
}else if (received_command.command == "a"){ // Change amplitude
stepper.setAcceleration(received_command.value);
}else if(received_command.command == "s"){ // Start the stepper motor movement
stepper.enableOutputs();
stepper.setCurrentPosition(0);
start_movement = true;
first_move = true;
}else if(received_command.command == "h"){ // Stop the stepper motor
stepper.stop();
stepper.disableOutputs();
start_movement = false;
}

}

current_position = stepper.currentPosition();

if (stepper.distanceToGo() == 0) {
if (first_move){
stepper.move(sheet_width/2);
first_move = false;
}
else if (dir){
stepper.move(sheet_width);
}else{
stepper.move(-1*sheet_width);
if(start_movement){
if (stepper.distanceToGo() == 0) {
if (first_move){
stepper.moveTo(sheet_width/2);
first_move = false;
}
else if (dir){
stepper.moveTo(sheet_width);
}else{
stepper.moveTo(-1*sheet_width);
}
dir = !dir;
}
dir = !dir;
}

// Update the sheet width only when it cross the cero position
if(current_position == cero_position){
sheet_width = new_sheet_width;
stepper.run();
}
stepper.run();

vTaskDelay(2/ portTICK_PERIOD_MS);
vTaskDelay(1/ portTICK_PERIOD_MS);
}

}
48 changes: 48 additions & 0 deletions micro_manager_config_files/MMConfig_cameraTest.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Configurator on Mon Apr 29 17:41:10 CEST 2024

# Reset
Property,Core,Initialize,0


# PixelSize settings
# Resolution preset: Res20x
ConfigPixelSize,Res20x,Objective,Label,Mitutoyo 20x Plan Apo L
PixelSize_um,Res20x,1.2

# Resolution preset: Res40x
ConfigPixelSize,Res40x,Objective,Label,Nikon 40X Plan Fluor ELWD
PixelSize_um,Res40x,0.25


# Devices
Device,pco_camera,PCO_Camera,pco_camera

# Pre-init settings for devices
Property,pco_camera,DemoMode,Off

# Pre-init settings for COM ports

# Hub (parent) references

# Initialize
Property,Core,Initialize,1

# Delays

# Focus directions

# Roles
Property,Core,Camera,pco_camera
Property,Core,AutoShutter,1

# Camera-synchronized devices

# Labels

# Configuration presets
# Group: Channel

# Group: System
# Preset: Startup


2 changes: 1 addition & 1 deletion test_code/pycromanager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Check if Micro-Manager is running and ZMQ server is enabled on port 4827
with Acquisition(directory='/', name='acquisition_name') as acq:
# Create events for acquisition
events = multi_d_acquisition_events(num_time_points=0)
events = multi_d_acquisition_events(num_time_points=5)
print(f"Acquisition events created: {events}")

# Start the acquisition
Expand Down

0 comments on commit 15b6d9f

Please sign in to comment.