> For the complete documentation index, see [llms.txt](https://docs.creativeconners.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.creativeconners.com/docs/spikemark/spikes/nearest-multiple.md).

# Nearest Multiple Spike

Nearest Multiple Spikes will move the motor in either direction to the **closest multiple** of **Factor** plus **Offset.** Put in other words:

$$
NewTargetPosition=NearestMultiple(Factor+offSet)
$$

The $$NearestMultiple(Factor+offSet)$$is found by calculating the $$New Forward Position$$ and the $$New Reverse Position$$, then selecting which one is closest to the $$Current Motor Position$$ and setting that as the New Target Position.

#### For Math Nerds

* $$P\_C=$$ Current Position
* $$R↑=$$ Round Up
* $$R↓=$$ Round Down
* $$F=$$ Factor Value
* $$S=$$ Offset Value

$$
|P\_C-(R↑\[P\_C/F]\*F+S)|  <^? |P\_C-(R↓\[P\_C/F]\*F+S)|
$$

#### If Yes, $$NewTargetPosition=NewForwardPosition$$

$$
New Forward Position = Round↑(CurrentMotorPosition/Factor) \* Factor + Offset
$$

#### If No, $$NewTargetPosition=NewReversePosition$$

$$
New Reverse Position = Round↓(CurrentMotorPosition/Factor) \* Factor + Offset
$$

### Changing the Type

Nearest multiple spikes are denoted with a `↔` (left right arrow) and use a **Factor** and an **Offset.**

To change the type double click in the **Type** column and select **Nearest Multiple** then press `enter` or `tab` to save it.

![](https://3040525219-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MhFI6SSKpm8M7EkrYqp%2Fuploads%2Fgit-blob-ad1df37b7c2215606b95347c8e6144827a2b6101%2FChange%20Spike%20To%20Nearest%20Multiple.gif?alt=media)

### Changing the Factor <a href="#changing-the-offset" id="changing-the-offset"></a>

To change the factor double click in the **Factor** column give it a new factor and then press `enter` or `tab` to save it.

![](https://3040525219-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MhFI6SSKpm8M7EkrYqp%2Fuploads%2Fgit-blob-f352a9862ba96a0ee916e809fbb3656f1830260b%2FEdit%20NM%20Factor.gif?alt=media)

### Changing the Offset‌ <a href="#changing-the-offset" id="changing-the-offset"></a>

To change the offset double click in the **Offset** column give it a new offset and then press `enter` or `tab` to save it.

![](https://3040525219-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MhFI6SSKpm8M7EkrYqp%2Fuploads%2Fgit-blob-443e931e4428cbc016ff1714e358abf825497ba0%2FEdit%20NM%20Offset.gif?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.creativeconners.com/docs/spikemark/spikes/nearest-multiple.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
