> For the complete documentation index, see [llms.txt](https://modeltrainscript.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://modeltrainscript.gitbook.io/docs/manual/automation/tutorials/pendel.md).

# Shuttle

Basic shuttle script

In this tutorial you will create a shuttle script that drives a locomotive back and forth between two points. The train travels from A to B, waits, reverses, and repeats — a classic model railway automation scenario.

**What you'll need:**

* A configured [vehicle](/docs/manual/vehicles.md)
* Two feedback sensors (e.g. R-Bus occupancy detectors)

## 1. Layout

Start by building your track plan in the [layout editor](/docs/manual/layout.md). For this tutorial we use a simple straight track with bumpers on both ends.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2F4oRJuIvq3EVLUkKC7ndl%2Fimage.png?alt=media&amp;token=6d0b4d98-942a-4d17-95bb-d52e392664ba" alt="" width="188"><figcaption></figcaption></figure>

Model Train Script needs to know when a train arrives at A or B, so we configure feedback sensors at both ends. In this basic scenario we use simple occupancy detectors (no RailCom required).

Select the pencil to enter edit mode, tap the track at position A, and open its configuration. Set the feedback to R-Bus module 1, port 1. For B, use module 1, port 2.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FYxzRwzHc9b2Dj1d2zelu%2Fimage.png?alt=media&amp;token=cbc48069-3ec9-412b-8e46-b2178a5a376e" alt="" width="188"><figcaption></figcaption></figure>

After configuring, the layout shows darker track sections indicating that feedback sensors have been assigned.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FQv4GZYnSNUJIhdY9RnHh%2Fimage.png?alt=media&amp;token=a8cf800d-091b-4605-a226-e50e9c46f535" alt="" width="188"><figcaption></figcaption></figure>

The layout is ready — time for some automation!

## 2. Script

In your [profile](/docs/manual/profile.md), go to **Scripts** and create a new script. Give it a descriptive name and enable the **repeat** option, since the train should shuttle continuously.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FNq2vTcGBbD64yWqa7kHa%2Fimage.png?alt=media&amp;token=3d27522d-f474-44b6-b126-4eda0546af8d" alt="" width="188"><figcaption></figcaption></figure>

Open the default section, rename it to "Shuttle", and delete the default wait action.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FF3ukZCLsnH4z6hgeQMbz%2Fimage.png?alt=media&amp;token=09aed2fe-a47e-441f-bb85-fb776b70c73d" alt="" width="188"><figcaption></figcaption></figure>

Now add the [actions](/docs/manual/automation/scripts/action.md) for the first half of the journey. Select your vehicle, set the direction to forward, and set the speed.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FS9UaKk9tNat3SU2wuXYb%2Fimage.png?alt=media&amp;token=23ff89a5-9199-462f-ba6f-a180410b7fea" alt="" width="188"><figcaption></figcaption></figure>

The train is now moving towards B. Add a **Wait for condition** action to pause the script until the feedback sensor at B reports occupancy.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FMjgG2WAoyKYGlD1J0JiC%2Fimage.png?alt=media&amp;token=0e068e77-0d02-491d-af4f-e12e47862739" alt="" width="188"><figcaption></figcaption></figure>

When the train arrives at B: stop it, wait 15 seconds, and reverse direction.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FaT3w34dZEDgqRBWbIlAu%2Fimage.png?alt=media&amp;token=449f0675-cd87-406b-9ff0-b169eebdd2d2" alt="" width="188"><figcaption></figcaption></figure>

Now repeat the same pattern for the return trip to A: set speed, wait for the sensor at A, stop, wait, and reverse.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FG10UGNt7fQsL2quOy5Ut%2Fimage.png?alt=media&amp;token=3631e70f-a32d-473d-b4dd-3e235186dbeb" alt="" width="188"><figcaption></figcaption></figure>

The script is complete!

## 3. Running the script

Start the shuttle from the script editor or from the automate tab in the [throttle](/docs/manual/throttle.md). With repeat enabled, the script loops until you stop it manually.

<figure><img src="https://4224524483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjZj7d8De4optEMsLAji%2Fuploads%2FxmrzKsxZf1uQ2VFjA6Cv%2Fimage.png?alt=media&amp;token=00528390-12cb-4764-ba37-bb0b971d8fd5" alt="" width="188"><figcaption></figcaption></figure>

Enjoy your shuttle!

## 4. Ideas for improvement

We kept this tutorial simple. Here are some suggestions to take it further:

* **Use separate sections** with descriptive names like "Travel from A to B" and "At station B" for a better overview.
* **Use RailCom** to detect which vehicle is on the track instead of selecting one at the start. See the [RailCom tutorial](/docs/manual/automation/tutorials/railcom.md).
* **Use vehicle profiles** to define speed and functions centrally, rather than configuring them directly in the script. This makes it easier to adjust driving behaviour later.
