> For the complete documentation index, see [llms.txt](https://ftc-code.gitbook.io/tech-toolbox/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ftc-code.gitbook.io/tech-toolbox/please-visit-the-new-link/linear-slides.md).

# Linear Slides

Commonly Used Extension Mechanism

{% hint style="info" %}
Prerequisites

* [Motors](/tech-toolbox/please-visit-https-ftc-tech-toolbox.vercel.app-for-the-new-tech-toolbox/motors-and-encoders.md)
  {% endhint %}

> Resources:&#x20;
>
> * [FTC Team PIEaters Linear Slide Tutorial](https://www.youtube.com/watch?v=mbSP4dkfD2g)

### Implementation

Programming linear slides is usually as simple as setting a viable target position to your motors that control the slides. Note that encoders are required to do this.&#x20;

{% hint style="danger" %}
When operating two motors together, we highly recommend that you remove any modules from the motors and test your positioning functions first. This will ensure that your motors are moving in the desired direction. Not doing this may lead to you risking breaking your motors or the slides! If one motor is not moving the correct way **try setting another target position or reversing its direction.**&#x20;
{% endhint %}

```java
public void extendVerticalSlides(int verticalSlideExtendPos) {
    verticalLeftSlide.setTarget(verticalSlideExtendPos); // the position you want the slides to reach
    verticalLeftSlide.retMotorEx().setTargetPositionTolerance(1); // set accuracy to 1 tick
    verticalLeftSlide.toPosition();
    verticalLeftSlide.setPower(1); // raise at some power

    verticalRightSlide.setTarget(verticalSlideExtendPos);
    verticalRightSlide.retMotorEx().setTargetPositionTolerance(1);
    verticalRightSlide.toPosition();
    verticalRightSlide.setPower(1);
 }
```

### Exercise (One Encoder, Two Slides)

{% tabs %}
{% tab title="Problem" %}
Due to a lack of encoder slots you may only have one encoder spot left to control both of your slides. To work around this issue you can use the encoder readings from one motor to control both slides via a custom PID loop. Note that this may not be as accurate as using two separate  encoders.&#x20;

Inside your opMode loop, implement the following psuedocode:

```java
int error = leftSlide.getCurrentPosition() - destinationPosition;
leftSlide.executePID(error); 
rightSlide.exectutePID(error);  
```

{% endtab %}

{% tab title="Solution" %}

{% endtab %}
{% endtabs %}

### Case Study

Take a look at the code of FTC Freight Frenzy world championship winning team, Delta Force!

{% embed url="<https://github.com/TAVii119/FTC-Freight-Frenzy-2021-2022>" %}

{% embed url="<https://www.youtube.com/watch?v=qnAq9K8zn3o>" %}
