Welcome! In this tutorial series, you will learn how a holonomic x-drive works and how to intelligently program such a robot using headings and magnitude.
I think you should have the following background knowledge: (I've added links for instructions on each from Khan Academy)
- Vectors
- Trigonometry with radians (up through an American Precalculus or Trigonometry class, most likely)
- Programming experience: I try to explain everything I've done in the code, but having the programming experience will help tremendously with understanding
A simple x-drive robot built by a programmer, so build quality cannot be assured. |
The code we'll be writing is for ROBOTC, and a version for PROS will be available I plan to make an easyC ported version, but I don't know when I'll be able to get around to it.
I also highly recommend that you have a holonomic x-drive robot to play with during the tutorial. I find it helps to have the real thing in front of you to see what's going on.
I also highly recommend that you have a holonomic x-drive robot to play with during the tutorial. I find it helps to have the real thing in front of you to see what's going on.
Before we get programming, we need to know how a holonomic x-drive works. The basic premise of the x-drive is that you have 4 omni-directional wheels at right angles to each other. When you spin these wheels, you can go literally any 2-dimensional (x-y plane) direction, plus z-axis rotation.
Throughout this tutorial, we'll be referring to specific headings that we want the robot to go. Because they are basic and end up ensuring that our program is correct, we'll be using headings of ,, , , , etc. Our headings will be the relationship of the north-south line (it's exactly the same as a compass). Also, all motor directions will be under the assumption that positive (+) PWM is clockwise and negative (-) PWM is counterclockwise. That means you may need to wire-invert motors or use ROBOTC's "reversed" attribute for the motor.
Let's start with the most basic of directions a holonomic robot can go: . As you can see in the diagram, the robot must make its front left turn counterclockwise (-) and the rear right wheel turn clockwise (+). The front right and rear left omni-wheels are only spinning on their perpendicular axis (the rollers of the omni-wheel).
This animation demonstrates the relationship between the "goal heading" and the wheel speed. The wheel in this particular animation is the front left wheel. The other wheels would have the CW/CCW flipped and/or have a line where y = -x (rather than y = x). There is another animation a little farther down. So, when we convert our goal heading to a wheel speed, we always know the following parameters:
Let's start verifying with a heading of If you look back up at what we know the wheel headings are supposed to be, we can verify that these values are the same. Let's take a look at the 8-cardinal heading output:
As you can see, the headings at 0, PI/2, PI, and 3PI/2 are not at +/-127. However, they are at the same relative speeds, so we can fix that with a recalling algorithm when we program these formulas. This concludes part 1 of the Holonomic Tutorial. In the next part, we'll program these formulas.
Let's start with the most basic of directions a holonomic robot can go: . As you can see in the diagram, the robot must make its front left turn counterclockwise (-) and the rear right wheel turn clockwise (+). The front right and rear left omni-wheels are only spinning on their perpendicular axis (the rollers of the omni-wheel).
This one is quite simple, as the total sum of the movement is in the same direction as the actual direction of travel. Next, we'll do , in which each wheel turns in a relative forward direction. The motor spins in the same direction as if you were to have every wheel parallel to each other (like a "normal" drive configuration)
This works because each wheel's x-axis vector cancels out with each other. Let's take a closer look with a vector diagram.
It is possible to split up every vector into two components, an x-axis component and a y-axis component. Our goal is to have one sum vector in the positive y-axis (hence ). As we don't have any wheels facing that specific direction, we can spin two opposing wheels in the same relative direction, so that there x-axis components cancel out to create one combined y-axis component. The same happens on the rear wheels. If you'd like a deeper explanation, I recommend you check out this site. It goes into further detail about vector addition, and starts to hit on some of the principles that will be discussed later in this tutorial.
We'll skim over the next major direction we'll need to head :
As in the previous situation, all of the vectors cancel out. Remember that this heading is , not . The heading is the same as you would see on a compass.
---------
The above section was helpful, but we still don't have any formulas or equations that we can plug in for any given heading and get a response for that wheel's speed should be. To begin, let's figure out what we will know under any circumstance.
- The goal heading
- The goal speed
- The wheel angle (and what makes it go CW/CCW)
Since we need to solve the problem generically, I'm going to do the following diagram generically. Afterwards, we'll plug in our "master" values to see if our formula works.
In this diagram, we know the grey elements: the angle Θ (theta), and the magnitude of vector s (speed). We also know the black line with angle to the x-axis (this is the wheel). Our goal is to find the length of c, which is the wheel speed. In order to do so, we'll need to construct a right triangle with angle A. The angle A is green and the right angle and it's constructor is in blue. Using angle addition, we can find angle A with the formula . We can use the cosine function to relate angle A, s, and unknown c together. We get the following function: . We can solve for c (wheel speed) for the front right wheel: . You can use the same method to derive the rest of the formulas for the front right, rear left, and rear right wheels. Note that s is the max wheel speed when in the angle is in Quadrants I and II (y is positive). Our formulas are as follows (in degree mode): Let's start verifying with a heading of If you look back up at what we know the wheel headings are supposed to be, we can verify that these values are the same. Let's take a look at the 8-cardinal heading output:
Heading | Front Left | Front Right | Rear Left | Rear Right |
0 | -90 | 90 | -90 | 90 |
PI/4 | -127 | 0 | 0 | 127 |
PI/2 | -90 | -90 | 90 | 90 |
3PI/4 | 0 | -127 | 127 | 0 |
PI | 90 | -90 | 90 | -90 |
5PI/4 | 127 | 0 | 0 | -127 |
3PI/2 | 90 | 90 | -90 | -90 |
7PI/4 | 0 | 127 | -127 | 0 |