Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
CsAngel-github committed Feb 17, 2025
2 parents 788cafd + 71c0398 commit e640d1f
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ In this workshop, we will guide you through assembling a LED-powered fluorescenc

---


### Materials Needed

1. Blue LED (for exciting fluorescence molecules)
Expand All @@ -24,6 +25,7 @@ In this workshop, we will guide you through assembling a LED-powered fluorescenc

---


### Diagram

![](./IMAGES/diagramm.png)
Expand Down Expand Up @@ -68,6 +70,7 @@ Now, your bright-field microscope is ready!

---


#### 1.2: Assembling the Fluorescence Microscope
But of course if you got this box you want more, so now let#s start buidling the fluorescene Microscope

Expand All @@ -81,37 +84,42 @@ But of course if you got this box you want more, so now let#s start buidling the
After completing these steps, you're done with the assembly, nice job!

---

# Step 2: Turn Your Microscope Into a Smart One - aka the Electronics

### 2.1: Plug in the Electronics as Shown Below

<div style="background-color: rgba(255, 255, 0, 0.3); padding: 10px; border-radius: 5px;">
<strong style="font-size: 20px;">⚠️ Caution!</strong>
<p>If you need to change any of the cables or their position, always unplug the 12V power cable before doing so. Otherwise, the electronic components might get damaged!</p>
</div>

- connect the LED-matrix panel by plugging in the micro-USB and connect it to your PC.
- Connect the Z-stage to the ``Z-Motor`` on the main board. Ensure there's a motor driver.
- Connect the blue LED to the LED driver (red plate) at ``out1``:
- The cable at ``-`` goes to ``-``
- The cable at ``+`` goes to ``+``
=======
- connect the LED-Array panel by plugging in the micro-USB and connect it to your PC.
- Connect the Z-stage to the `Z-Motor` on the main board. Ensure there's a motor driver.
- Connect the blue LED to the LED driver (red plate) at `out1`:
- The cable at `-` goes to `-`
- The cable at `+` goes to `+`
>>>>>>> 71c0398dd737fa5c1183ae087bf67ad92c0a9f37
- Connect the LED driver to the main board:
- The cable at ``in 1`` goes to ``PM2 - PMW2``
- The cable at ``V In -`` goes to ``12V - GND``
- The cable at ``V IN +`` goes to ``12V - 12V``
- The cable at `in 1` goes to `PM2 - PMW2`
- The cable at `V In -` goes to `12V - GND`
- The cable at `V IN +` goes to `12V - 12V`
- Plug in the micro-USB and connect to your PC.
- Plug in the 12V power cable.


---


### 2.2: Flashing the ESP32 Firmware

1. Before proceeding, ensure your ESP32 board has the latest firmware. You can download and flash the firmware via the official [openUC2 website](https://youseetoo.github.io/), selecting your version (**row 2, column 1**), then click on the ``connect`` button.

![](./IMAGES/Electronics_Box_5.png)

The source code can be found [here](https://github.com/youseetoo/uc2-esp32).

2. Connect the ESP32 to your computer using the micro-USB cable.

Expand All @@ -129,7 +137,6 @@ After completing these steps, you're done with the assembly, nice job!

5. &#x1F4A1; **flash your LED-matrix**. Repeat the same steps, but this time for the LED-matrix
![](./IMAGES/LED_install.png)
---

### 2.3: Connecting to the Web Interface

Expand All @@ -144,16 +151,13 @@ After completing these steps, you're done with the assembly, nice job!
```json
{"task":"/motor_act", "motor": { "steppers": [ { "stepperid": 3, "position": -1000, "speed": 1000, "isabs": 0, "isaccel": 0} ] } }
```
![](./IMAGES/Electronics_Box_1.png)

This command will move the Z-axis motor by -1000 steps (1 full rotation) at a speed of 1000 steps per second. Each step corresponds to a movement of 300nm when using microstepping. You’ll observe the motor rotating, adjusting the focus.

> **Note:** Ensure that the command string has no line breaks.

4. &#x1F4A1;**Connect your LED-matrix as well**. Duplicate the current tab and connect the LED-matrix again via the button. Choose the correct COM Port.
Now you can test all components through these two tabs.

---

### 2.4: Testing in the Web Interface

Expand Down Expand Up @@ -183,16 +187,13 @@ The UC2-ESP firmware supports various input devices, including the PS4 controlle
- **Move the Z-stage**: Use the **left analog stick** to move the stage up and down (adjust focus).
- **Control the LEDs**: Use the **controller buttons** to turn the LED-matrix on/off and cycle through different illumination patterns.

---

### 2.6: Setup and Use the Camera Software

1. Connect the camera to your PC.
2. For the installation process, follow these instructions: [Install MVS App for Camera Utilization](https://openuc2.github.io/docs/Toolboxes/DiscoveryInterferometer/SoftwareTutorial/#install-mvs-app-for-camera-utilization).

---

# Congratulations! You Have Completed All the Setup Steps! Now Let's Use the Microscope

---

Expand Down Expand Up @@ -359,7 +360,7 @@ Benedicts stuff

This file configures the ESP32 stage, LED control, and the camera for widefield imaging. Ensure the `host_` and `serialport` match your system setup.

---


### Step 3: Running the Microscope with ImSwitch

Expand Down
144 changes: 103 additions & 41 deletions docs/04_ImSwitch/ImSwitchClient.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,137 @@
# ImSwitchClient Documentation

`ImSwitchClient` is a Python package designed to connect to the ImSwitch REST API, enabling remote control of ImSwitchUC2 functionalities directly from Jupyter Notebooks. This client facilitates easy integration with the ImSwitch ecosystem, offering programmable access to various features like laser control, stage manipulation, and image acquisition.

[![PyPI Version](https://img.shields.io/pypi/v/imswitchclient.svg)](https://pypi.python.org/pypi/imswitchclient)
## Introduction

`ImSwitchClient` is a Python wrapper designed for interacting with the ImSwitch REST API, enabling remote control over ImSwitch functionalities, such as stage positioning, laser control, and image acquisition. This client simplifies API interactions and allows seamless integration into Python scripts and Jupyter Notebooks.

<iframe width="560" height="315" src="https://www.youtube.com/embed/WSDORF31O2M?si=hzqvJeZak0D13vFn" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
[![PyPI Version](https://img.shields.io/pypi/v/imswitchclient.svg)](https://pypi.python.org/pypi/imswitchclient)

## Features

- **Remote Control**: Interact with ImSwitchUC2 from Jupyter Notebooks via fastapi endpoints.
- **Comprehensive Documentation**: Access detailed documentation and explore API endpoints at [https://imswitchclient.readthedocs.io](https://imswitchclient.readthedocs.io).
- **API Exploration**: Utilize FastAPI's interface at http://localhost:8000/docs for an interactive API experience.
- **Broad Functionality**: Current implementations include laser control, stage manipulation, and image acquisition, with the possibility for future expansion based on user requests.
- **Global API Testing**: Test the client using the globally hosted API at [https://youseetoo.github.io/imswitch/api.html](https://youseetoo.github.io/imswitch/api.html).
- **Open Source**: Inspired by the OpenFlexure Client, `ImSwitchClient` is freely available for modification and distribution under the MIT license.
- **Implemented functions** (so far, please file an issue for feature requests):
- Laser
- Stage
- Image Acquisition
- You can test the client with the globally hosted api here: https://youseetoo.github.io/imswitch/api.html
- It is inspired by the OpenFlexure Client: https://gitlab.com/openflexure/openflexure-microscope-pyclient/-/blob/master/openflexure_microscope_client/microscope_client.py
- The source files can be found here: https://github.com/openUC2/imswitchclient/
- **Remote Control**: Interface with ImSwitch through REST API endpoints.
- **Comprehensive API Access**: Easily control positioners, lasers, detectors, and imaging settings.
- **Interactive API Exploration**: Utilize the FastAPI Swagger UI at `http://localhost:8000/docs`.
- **Modular Design**: Includes managers for lasers, positioners, image acquisition, and more.
- **Open Source**: Inspired by OpenFlexure Client, freely available under the MIT license.

## Installation

To install `ImSwitchClient`, use the following pip command:
You can install `ImSwitchClient` via pip:

```bash
pip install imswitchclient
```

## Quick Start Example
## Getting Started

This example demonstrates basic usage of `ImSwitchClient` for moving a positioner and acquiring an image.
### Initializing the Client

```python
import imswitchclient.ImSwitchClient as imc

# Initialize the client
client = imc.ImSwitchClient(host="0.0.0.0", isHttps=True, port=8001)
```

### Example: Moving a Stage and Acquiring an Image

```python
import numpy as np
import matplotlib.pyplot as plt
import time

# Initialize the client
client = imc.ImSwitchClient()

# Retrieve the first positioner's name and current position
# Retrieve positioner names
positioner_names = client.positionersManager.getAllDeviceNames()
positioner_name = positioner_names[0]
currentPositions = client.positionersManager.getPositionerPositions()[positioner_name]
initialPosition = (currentPositions["X"], currentPositions["Y"])

# Define and move to a new position
newPosition = (initialPosition[0] + 10, initialPosition[1] + 10)
client.positionersManager.movePositioner(positioner_name, "X", newPosition[0], is_absolute=True, is_blocking=True)
client.positionersManager.movePositioner(positioner_name, "Y", newPosition[1], is_absolute=True, is_blocking=True)

# Acquire and display an image
time.sleep(0.5) # Allow time for the move
lastFrame = client.recordingManager.snapNumpyToFastAPI()
plt.imshow(lastFrame)

# Get current position
current_positions = client.positionersManager.getPositionerPositions()[positioner_name]
initial_position = (current_positions["X"], current_positions["Y"])

# Turn on illumination
laser_name = client.lasersManager.getLaserNames()[0]
client.lasersManager.setLaserActive(laser_name, True)
client.lasersManager.setLaserValue(laser_name, 512)

# Move the stage and capture an image
def capture_image_at_position(x, y):
client.positionersManager.movePositioner(positioner_name, "X", x, is_absolute=True, is_blocking=True)
client.positionersManager.movePositioner(positioner_name, "Y", y, is_absolute=True, is_blocking=True)
last_frame = client.recordingManager.snapNumpyToFastAPI()
plt.imshow(last_frame)
plt.show()

# Example scanning
for ix in range(5):
for iy in range(5):
new_x = initial_position[0] + ix * 50
new_y = initial_position[1] + iy * 50
capture_image_at_position(new_x, new_y)

# Return stage to initial position
client.positionersManager.movePositioner(positioner_name, "X", initial_position[0], is_absolute=True, is_blocking=True)
client.positionersManager.movePositioner(positioner_name, "Y", initial_position[1], is_absolute=True, is_blocking=True)
```

### Laser Control Example

```python
laser_name = client.lasersManager.getLaserNames()[0]
client.lasersManager.setLaserActive(laser_name, True)
client.lasersManager.setLaserValue(laser_name, 800)

# Verify laser status
print(client.lasersManager.getLaserNames())
client.lasersManager.setLaserActive(laser_name, False)
```

### Recording an Image

```python
# Take a snapshot
image = client.recordingManager.snapNumpyToFastAPI()
plt.imshow(image)
plt.show()
```

# Return the positioner to its initial position
client.positionersManager.movePositioner(positioner_name, "X", initialPosition[0], is_absolute=True, is_blocking=True)
client.positionersManager.movePositioner(positioner_name, "Y", initialPosition[1], is_absolute=True, is_blocking=True)
### Setting Live View

```python
client.viewManager.setLiveViewActive(True)
client.viewManager.setLiveViewCrosshairVisible(True)
client.viewManager.setLiveViewGridVisible(False)
```

## API Overview

The ImSwitch API provides access to various components:

### Positioners Manager
- `getAllDeviceNames()` - Get all available positioners.
- `getPositionerPositions()` - Get current position.
- `movePositioner(name, axis, value, is_absolute, is_blocking)` - Move the stage.
- `homeAxis(name, axis, is_blocking)` - Home the positioner.

### Lasers Manager
- `getLaserNames()` - Get available lasers.
- `setLaserActive(name, status)` - Turn laser on/off.
- `setLaserValue(name, value)` - Set laser intensity.

### Recording Manager
- `snapNumpyToFastAPI()` - Capture an image.
- `startRecording()` - Begin recording.
- `stopRecording()` - Stop recording.

### View Manager
- `setLiveViewActive(status)` - Enable live view.
- `setLiveViewCrosshairVisible(status)` - Show/hide crosshair.
- `setLiveViewGridVisible(status)` - Show/hide grid.

## Contributing

Contributions to `ImSwitchClient` are welcome! Please refer to the project's GitHub repository for contribution guidelines: [https://github.com/openUC2/imswitchclient/](https://github.com/openUC2/imswitchclient/).
Contributions are welcome! Visit the GitHub repository for details: [https://github.com/openUC2/imswitchclient](https://github.com/openUC2/imswitchclient)

## License

`ImSwitchClient` is licensed under the MIT License. For more details, see the LICENSE file in the project repository.
This project is licensed under the MIT License.

0 comments on commit e640d1f

Please sign in to comment.