> For the complete documentation index, see [llms.txt](https://docs.revrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.revrobotics.com/duo-control/hello-robot-blocks/part-3/autonomous-navigation-blocks/setting-velocity.md).

# Setting Velocity

## Setting Velocity in our Program

Velocity is a closed loop control within the [SDK](/duo-control/hello-robot-blocks/where-to-program/what-is-an-opmode.md) 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="/files/-MYfxnoZpHQV4V7dyiqS" alt="" data-size="original">  to the beginning of the if/then statement above the target variables.&#x20;

<figure><img src="/files/uAbW7ExReh2CcewPxM02" alt=""><figcaption><p>Adding the TPS variable</p></figcaption></figure>

Add a <img src="/files/-MYRS32ax0_5fhPWNou9" alt="" data-size="original"> block to the <img src="/files/-MYfxnoZpHQV4V7dyiqS" alt="" data-size="original"> block. On the right side of the <img src="/files/-MYRS32ax0_5fhPWNou9" alt="" data-size="original"> block add the <img src="/files/-MYey5fLzndMDfYs7HdW" alt="" data-size="original">. One the left side of the <img src="/files/-MYRS32ax0_5fhPWNou9" alt="" data-size="original"> add the<img src="/files/-MYepPimZMwCPPARot8P" alt="" data-size="original"> block.&#x20;

Add the chosen RPM (175 in this example) to the left side of the <img src="/files/-MYepPimZMwCPPARot8P" alt="" data-size="original"> block and 60 to the right side.&#x20;

![](/files/-MYfzugs_ZuQcMfIRTGE)

### Changing from Power to Velocity

Now that the target ticks per second has been set, swap the <img src="/files/-MYg1RLiF3aIU-PaJgah" alt="" data-size="original">block for a <img src="/files/-MYg1WJmbeYlb5XsxdAI" alt="" data-size="original"> block. Add the <img src="/files/-MYg2807btHlLi-Ew5MN" alt="" data-size="original"> to both motors.&#x20;

<figure><img src="/files/BSJP344nOJWgBMJuJZvu" 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="/files/zbYgzCPevIkW41EIsDoH" alt=""><figcaption><p>Full encoder demo Blocks program</p></figcaption></figure>


---

# 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 dynamically by asking a question.

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

```
GET https://docs.revrobotics.com/duo-control/hello-robot-blocks/part-3/autonomous-navigation-blocks/setting-velocity.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
