# Starting BakingTray

You should by now have run through the detailed hardware checks before proceeding with the instructions on this page.

### Making default settings files

At the command line run `BakingTray`. You will see something like this at the command prompt:

```
Starting construction of BT object
Can not find system settings file: making default file at C:\MATLAB\BakingTray\SETTINGS\systemSettings.yml
BT is reading default component settings

 **** Can not find a component settings file in C:\MATLAB\BakingTray\SETTINGS\
 **** Copying an empty file to this location but you will need to edit it ****

** Laser not defined in component settings file
** Cutter not defined in component settings file
** Scanner not defined in component settings file
** No motion axes defined


 BakingTray starting...
 Connecting to hardware components:

** Laser not defined in component settings file
** Cutter not defined in component settings file
** Scanner not defined in component settings file
** No motion axes defined
BT.attachMotionAxes failed to build one or more axes. Not starting BT.
Cleaning up BT object
BakingTray failed to create an instance of BT. Quitting.
```

BakingTray failed to start but created default settings in a `SETTINGS` sub-directory within the BakingTray directory. You will now edit these settings files for you hardware. Before proceeding, familiarise yourself with the information on the [settings files](/getting-started/finishing-the-install/the-settings-files.md).

### Editing the settings file

* The component settings file describes the hardware BakingTray will use.
* Navigate to the `SETTINGS` sub-directory and open the `componentSettings.m` file in an editor. For now set the maximum and minimum stage positions to reasonably large values: we'll deal with them in detail later.
* Edit the file and re-run `BakingTray`. There are instructions in the file describing how it should be edited based on the information you gathered when [verifying the hardware](https://github.com/raacampbell/bakingtray_docs/blob/master/getting_started/finishing_the_installation/Verifying-hardware-operation.md).

### Editing the system settings file

* The system settings file describes the system as a whole.
* As before, information on editing the file is [described here](/getting-started/finishing-the-install/the-settings-files.md).

### The default recipe

* Also in the settings directory is a file called `default_recipe.yml`. The recipe files define the properties of an acquisition. When you start BakingTray, `default_recipe.yml` is read. You may edit this file so BakingTray starts with different defaults. You may create multiple such files and manually load one after BakingTray starts. e.g. different recipes for different organ types.

## Finalising hardware settings

At this point you should be able to start BakingTray without errors and, if necessary, have at least roughly tweaked the X/Y stage [PID loops](https://github.com/raacampbell/bakingtray_docs/blob/master/getting_started/finishing_the_installation/PI-Stage-Setup.md). The most important task right now is to ensure that the stages can not produce an motion that would cause a hardware crash:

{% hint style="danger" %}
Be careful with the following steps. Go slowly so as not to damage your hardware.
{% endhint %}

* Place the vibratome and blade holder with blade in the correct position with respect to the objective. e.g. So the blade centered on the objective and the blade tip is about 30 mm from the axis of the objective.
* Assemble the stages and place an empty water bath on top.
* You can leave the objetive off for now in order to avoid damageing it.
* Set the X/Y stages to 0 (their mid-points) and move the XYZ stage so that the middle of the sample is under where the objective would be.
* Bolt the stage into place.
* Raise the water bath until the waterbath lip is level with the widest part of the blade holder. Move the Y stage and determine the maximum and minimum positions you can go without the blade holder hitting the lip of the water bath.
* Perform the same check for the X stage. Motions of the X stage could cause the bath to hit the vibratome or the objective. You may, therefore, want the objective in place when making this measurement.
* Carefully raise the Z stage and determine the point at which the blade comes within about 0.5 mm of the sample platform. This is is the maximum Z position.
* Edit the config file. Restart BakingTray. Ensure the positions are honoured. You might need to restart MATLAB for the new values to be honoured.

With PI stages it's possible to define soft limits for the motions in PI Mikromove. For extra safety, set the limits in MikroMove then also set the limits in the BakingTray settings file. It's best to set slightly narrower limits in the BakingTray settings file so you will not get an out of bounds error from the stages.

{% hint style="danger" %}
Altering blade tile (pitch) will require updating the max Z axis position.
{% endhint %}

### Calibrations

* The three-axis stage should be [aligned with the imaging plane](/getting-started/finishing-the-install/calibration/basic-calibrating-procedures.md).
* It is important that you [accurately calibrate](/getting-started/finishing-the-install/calibration/calibrating-the-number-of-microns-per-pixel-with-scanimage.md) the number of microns per pixel in ScanImage. BakingTray uses this number to figure out where to move the stages. Also note the optional [fine-tuning](/getting-started/finishing-the-install/calibration/fine-tuning-positioning-accuracy.md) procedure.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bakingtray.mouse.vision/getting-started/finishing-the-install/starting-bakingtray-for-the-first-time.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
