# Resolution

This folder contains the experiment code, analysis code and raw data from the experiment to measure the resolution of the stage along the _x_ and _z_ axes.

This experiment was performed using a [Raspberry Pi 3 model B+](https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/). Motion of the stage was monitored using a [Raspberry Pi camera module v2](https://www.raspberrypi.org/products/camera-module-v2/) by tracking a [R3L1S4P positive 1951 USAF wheel pattern test target](https://www.thorlabs.com/thorproduct.cfm?partnumber=R3L1S4P). Motion of the stage was also monitored by counting the number of steps moved by the three [micro-geared 28BYJ-48 stepper motors](https://build.openflexure.org/openflexure-microscope/v6.0.0/docs/#/parts/electronics/stepper_motors) used to control the motion of the stage through an Arduino. We removed the original lens that came with the Raspberry Pi camera module and used an [AC127-050-A lens](https://www.thorlabs.com/thorproduct.cfm?partnumber=AC127-050-A) instead. A 40 times objective lens was used for magnification and the USAF test target was illuminated by a white LED. Light from the LED was diffused by some white tape.

The 3D printed accessories required by the setup can be found in the `Accessories` folder. The AC127-050-A lens and the camera module are assembled using the `microscope_module_25mm.stl` lens tube. The camera module with exposed sensor is attached to one end of the camera tube using two M2 screws and the lens is push fitted to the other end of the camera tube with the more convex side facing out. The camera tube and the objective lens are assembled using the `rms_to_stage_25mm.stl` part. The lens tube is attached to the non-threaded end of the part using three M3 screws and the objective lens is screwed into the threaded end of the part. We then mounted this entire component on one stationary platform of the stage using two M3 screws, two M3 washers, and two M3 cleats. The USAF test target is held on the moving platform of the stage using two `vertical_sample_clips.stl` parts and two M3 screws. The LED is held on the other fixed platform of the stage using the `LED_to_microblock` part mounted with two M3 screws. The `diffuser.scad` part was mounted in front of the LED using two M3 screws, this part has some white tape stuck on it to diffuse the white LED light.

This experiment characterises the resolution of the stage along _x_ and _z_ by finding the smallest resolvable step size along both axes. The `precision.py` script inside folder `Experiment` takes a movement size as input. It then repeatedly moves the stage by the predefined amount along a specific axis. At the same time, the position of the stage is constantly monitored by the camera. The algorithm repeats this process three times for each movement size at different locations along the M3 actuation screw to mitigate for possible local threading defects. For each axis, we started with a well resolved large movement size. The movement size was then sequentially reduced by one step at a time, until individual movements could no longer be resolved.

Data collected were saved in HDF5 format due to its advantage at handling big datasets of different datatypes. A HDF5 file works like a python dictionary, containing nested groups of datasets. The data can be viewed using [hdfview](https://www.hdfgroup.org/downloads/hdfview/) or packages such as [h5py in Python](http://docs.h5py.org/en/stable/index.html).

The data collected are saved in two separate files inside folder `Raw_data`, `precision_x.hdf5` for the _x_ axis and `precision_z.hdf5` for the _z_ axis. The analysis code used to analyse the collected data can be found in folder `Analysis`.

## _x_-axis data

The measured movement sizes range from ten steps to single step, starting from the largest movement size. For each movement size, three sets of measurements were recorded at different positions along the M3 actuation screw.

The `precision_x.hdf5` file inside folder `Raw_data` contains sequentially numbered groups of datasets, groups labelled with the same number contain data collected with the same movement size at identical locations along the M3 actuation screw. Since three sets of measurements were recorded for each movement size, groups labelled `000`, `001` and `002` all corresponds to the same movement size of ten steps. Similarly, groups labelled `003`, `004` and `005` all corresponds to the same movement size of nine steps and so on. Each `data_cam` group contains N three-element arrays inside a group named `data_cam00000`, where the first array element is measurement time in seconds, the second array element is stage _x_ position as measured by the camera in pixels, and the third array element is stage _z_ position as measured by the camera in pixels. Each `data_stage` group contains N four-arrays inside a group named `data_stage00000` obtained by counting the number of steps moved by the stage, where the first array element is measurement time in seconds, the second array element is stage _x_ position in steps, the third array element is stage _y_ position in steps, and the fourth array element is stage _z_ position in steps.

## _z_-axis data

The `precision_y.hdf5` file inside folder `Raw_data` contains data saved in the same way as `precision_x.hdf5`. The measured movement sizes range from ten steps to five steps, starting from the largest movement size. Two extra datasets measured by moving the stage with single step movements and a movement size of eleven steps were added at the end for completeness.