# Drift

This folder contains the experiment code, analysis code and raw data from the experiment to measure change in the moving platform position over time when the stage is left in an ambient environment.

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 blank piece of microscope slide with a cross scratched on it. 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 10 times objective lens was used for magnification and the microscope slide was illuminated by a white LED. Light from the LED was diffused by some white tape. Furthermore, an [Adafruit Sensirion SHT31-D temperature & humidity sensor](https://www.adafruit.com/product/2857) was used to monitor the temperature and humidity of the environment.

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 microscope slide 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.

Data collected in this experiment 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 experiment code script used to characterise stage drift can be found in folder 'Experiment'. The data collected can be found in folder 'Raw_data'. The analysis code used to analyse the collected data can be found in folder 'Analysis'.

The 'drift.hdf5' file inside folder 'Raw_data' contains a data group named 'data000' which includes stage drift data over 25 days. The 'data000' group is further divided into subgroups that contain an initial image, a template image, and many datasets. An initial image of the scratched piece of microscope slide taken at the start of the experiment is saved inside a subgroup named 'initial_image'. A cropped version of this initial image used as the template for position tracking is saved inside a subgroup named 'template'. All other subgroups contain 1000 five-element arrays, where the first array element is measurement time in seconds, the second array element is humidity, the third array element is temperature in degree celsius, the fourth array element is stage _x_ position as measured by the camera in pixels, and the fifth array element is stage _z_ position as measured by the camera in pixels. Whenever a subgroup is filled, a new subgroup is created labelled with incrementing numbers.