# Setting Velocity

## Setting Velocity in our Program

Velocity is a closed loop control within the [SDK](https://docs.revrobotics.com/duo-control/hello-robot-blocks/where-to-program/what-is-an-opmode) that uses the encoder counts to determine the approximate power/speed the motors need to go in order to meet the set velocity.&#x20;

To set a velocity, its important to understand the maximum velocity in RPM your motor is capable of. For the Class Bot V2 the motors are capable of a maximum RPM of 300. With a drivetrain, you are likely to get better control by setting velocity lower than the maximum. In this case, lets set the velocity to 175 RPM!

Since RPM is the amount of revolutions per minute, a conversion needs to be made from RPM to ticks per second (TPS). To do this, divide the RPM by 60 to get the amount of rotations per second.&#x20;

Rotations per second can then be multiplied by `COUNTS_PER_WHEEL_REV`, to get the amount of ticks per second.&#x20;

$$
TPS = \frac{175}{60} \* CPWR
$$

### Adding Ticks per Second as a Variable

Create a new variable called TPS. Add the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYeyIdN23s6PuxYRjxx%2F-MYfxnoZpHQV4V7dyiqS%2FVariable%20-%20set%20TPS%20to.svg?alt=media&#x26;token=49523bae-8ad5-4b97-8af8-b20edd5d61b4" alt="" data-size="original">  to the beginning of the if/then statement above the target variables.&#x20;

<figure><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2F5qI1FNtRZsR9mr07C7Ey%2Fimage.png?alt=media&#x26;token=7fc27f11-2948-4890-bdf9-91a0b9fd5f0e" alt=""><figcaption><p>Adding the TPS variable</p></figcaption></figure>

Add a <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYQpFaVyN6OAN2wLm6r%2F-MYRS32ax0_5fhPWNou9%2FMath%20-%20multiplication.svg?alt=media&#x26;token=76bfe431-53f9-4310-9164-47faeef5a26b" alt="" data-size="original"> block to the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYeyIdN23s6PuxYRjxx%2F-MYfxnoZpHQV4V7dyiqS%2FVariable%20-%20set%20TPS%20to.svg?alt=media&#x26;token=49523bae-8ad5-4b97-8af8-b20edd5d61b4" alt="" data-size="original"> block. On the right side of the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYQpFaVyN6OAN2wLm6r%2F-MYRS32ax0_5fhPWNou9%2FMath%20-%20multiplication.svg?alt=media&#x26;token=76bfe431-53f9-4310-9164-47faeef5a26b" alt="" data-size="original"> block add the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYRgR43ABOUSGb1f8WZ%2F-MYey5fLzndMDfYs7HdW%2FVariable%20-counts%20per%20wheel.svg?alt=media&#x26;token=1ff59bbd-6e23-404f-a0bd-15b37501cec6" alt="" data-size="original">. One the left side of the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYQpFaVyN6OAN2wLm6r%2F-MYRS32ax0_5fhPWNou9%2FMath%20-%20multiplication.svg?alt=media&#x26;token=76bfe431-53f9-4310-9164-47faeef5a26b" alt="" data-size="original"> add the<img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYRgR43ABOUSGb1f8WZ%2F-MYepPimZMwCPPARot8P%2FMath%20-%20division.svg?alt=media&#x26;token=53cb0fdc-cdf6-4ce0-abbd-cd3ab3f9d30d" alt="" data-size="original"> block.&#x20;

Add the chosen RPM (175 in this example) to the left side of the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYRgR43ABOUSGb1f8WZ%2F-MYepPimZMwCPPARot8P%2FMath%20-%20division.svg?alt=media&#x26;token=53cb0fdc-cdf6-4ce0-abbd-cd3ab3f9d30d" alt="" data-size="original"> block and 60 to the right side.&#x20;

![](https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYeyIdN23s6PuxYRjxx%2F-MYfzugs_ZuQcMfIRTGE%2FCombo%20block%20-%20setting%20TPS%20to.svg?alt=media\&token=e0e406a4-a2b8-48e8-9f83-87a714af1b02)

### Changing from Power to Velocity

Now that the target ticks per second has been set, swap the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYeyIdN23s6PuxYRjxx%2F-MYg1RLiF3aIU-PaJgah%2FEncoder%20-%20setpower%20.08.svg?alt=media&#x26;token=5de07247-352c-4727-bb52-966146c861a0" alt="" data-size="original">block for a <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYeyIdN23s6PuxYRjxx%2F-MYg1WJmbeYlb5XsxdAI%2FDual%20Motor%20-%20setVelocity.svg?alt=media&#x26;token=8a44a6b2-f60f-4a37-8291-d3bdf2049504" alt="" data-size="original"> block. Add the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MYeyIdN23s6PuxYRjxx%2F-MYg2807btHlLi-Ew5MN%2FVariable%20-%20TPS.svg?alt=media&#x26;token=311503ee-e5fe-47e7-b374-20b7b0b3ef24" alt="" data-size="original"> to both motors.&#x20;

<figure><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2FG8sfxOkQwK1IgcopUWOZ%2Fimage.png?alt=media&#x26;token=fef5489d-0d99-4e12-89b6-ba509a6fb7fa" alt=""><figcaption><p>Setting our motors to run the specific velocity</p></figcaption></figure>

With the velocity set, let's give our program a test run after saving!&#x20;

### Full Program

<figure><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2FX4RpxeqHF9vIl7QJJ9cf%2Fimage.png?alt=media&#x26;token=cc69453e-8d5a-4747-96f1-ffa931c2194b" alt=""><figcaption><p>Full encoder demo Blocks program</p></figcaption></figure>


---

# 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://docs.revrobotics.com/duo-control/hello-robot-blocks/part-3/autonomous-navigation-blocks/setting-velocity.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.
