> For the complete documentation index, see [llms.txt](https://docs.hello-robot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hello-robot.com/stretch4_docs/working-with-stretch/common_tasks/base-frame-convention-and-wheel-odom.md).

# Base Frame Conventions

## Wheel Numbering

Wheel numbering must increase counter-clockwise. Wheel 0 must be to the left of the forward direction. Based on these rules, here’s how the wheels should be numbered on Basquiat and Calder.

<div align="center"><img src="/files/YC4aytrVfrzVR0ehFlXu" alt="" width="400"> <img src="/files/vybOjwZSCmWrf5KNdu5P" alt="" width="400"></div>

## Forward Direction

We want to go from wheel numbering to a ROS frame convention where X+ is forward and Y+ is to the left, forming a right handed coordinate frame.

<div align="center"><img src="/files/9LRYV2j7yu0oZJYyOxgw" alt="" width="400"> <img src="/files/fncIlYdBIDprpEzpW7pC" alt="" width="400"> <img src="/files/1oL8Q66YHzSm5uJKBuTm" alt="" width="400"></div>

We need 1 number, called “gamma”, that is the angle between wheel 0 and X+.

<div align="center"><img src="/files/1Q0Bwkp4JdWtxEtAxFLU" alt="" width="400"> <img src="/files/L6wLMPKumN6FdoKO9WKz" alt="" width="400"></div>

Gamma lives in Stretch Body II, inside the [H0\_from\_driving\_dir()](https://github.com/hello-robot/stretch_body_ii/blob/8b281a316574ed511d06fcf8a5e5ed33352cd612/src/stretch_body_ii/core/hello_utils.py#L964) function.

More details on H0 can be found in the [ROS docs](https://control.ros.org/rolling/doc/ros2_controllers/doc/mobile_robot_kinematics.html#omnidirectional-wheeled-mobile-robots).

<div align="center"><img src="/files/DmvrTIlscAGBK9jQflq3" alt="" width="600"></div>

## Gamepad Teleop

Here is the convention for the joysticks on the gamepad controller. Each axis ranges from \[-1, 1]

<div align="center"><img src="/files/X0hAJsqd7lpKjRr7iHKL" alt="" width="400"> <img src="/files/1oL8Q66YHzSm5uJKBuTm" alt="" width="400"></div>

Two things to note: First, we have to use the gamepad's Y axis for the robot’s X axis. Second, since the robot’s left is Y+ and the gamepad’s left is X-, we need to multiply the X range by -1. This explains the confusing negative sign in the gamepad teleop [code](https://github.com/hello-robot/stretch_body_ii/blob/7f3e2f17a41bbd0a6124ba3b349177c92d6991ac/src/stretch_body_ii/core/gamepad_teleop.py#L157):

<div align="center"><img src="/files/0JCt5gKHBSVBidskxtTR" alt="" width="600"></div>

## Wheel Odometry

H0 maps base velocity to wheel velocities. H0 inverse or `H0_inv` maps wheel velocities to base frame twist. Computing wheel odometry includes:

1. Counting magnetic encoder ticks in firmware and converting to motor space rad/s in Stretch Body II
2. Using `H0_inv` to calculate base frame twist
   \*

   ```
   <div align="center"><img src="/files/LSFSfYAVHPdzYsNUO8Bb" alt="" width="400"></div>
   ```
3. Scaling base frame twist (Vb) by the frequency update\_odom() is called
   \*

   ```
   <div align="center"><img src="/files/7iwXhe4ZeIZojmZUptEX" alt="" width="400"></div>
   ```
4. Rotating scaled base frame twist (Sb) into odom frame
   \*

   ```
   <div align="center"><img src="/files/umWDohlBK9xeF1XRrWcH" alt="" width="400"></div>
   ```
5. Add odom change to running odom frame
   \*

   ```
   <div align="center"><img src="/files/cqplfoLQYFGiLtR70Som" alt="" width="400"></div>
   ```


---

# 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:

```
GET https://docs.hello-robot.com/stretch4_docs/working-with-stretch/common_tasks/base-frame-convention-and-wheel-odom.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.
