View Single Post
  #22   Spotlight this post!  
Unread 23-03-2005, 20:50
robotaddict's Avatar
robotaddict robotaddict is offline
Registered User
FRC #1294 (Screws Loose (hopefully going to be changed soon))
Team Role: Programmer
 
Join Date: Mar 2005
Location: Sammamish, Washington
Posts: 11
robotaddict is on a distinguished road
Lightbulb Re: Holomonic Drive mathmatics discussion

Thanks seanwitte, it's very helpful, though I think I may have come up with a solution today at school. Here's how it goes.

Take your joystick inputs, p1_x, p1_y, and, just for kicks, let's say the joystick has a z axis too, p1_aux.

First off comes the task of putting p1_x and p1_y into headings the robot can understand. To do this, the robot needs an arbitrary front. Let's say the front is at 45 degrees to all the wheels. We'll say robot_x_approx drives the robot towards the front right and robot_y_approx drives the robot towards the front left. We get something like this:

robot_x_approx = sin(gyro_angle) * (p1_y - 127) + cos(gyro_angle) * (p1_x - 127) + 127
robot_y_approx = cos(gyro_angle) * (p1_y - 127) - sin(gyro_angle) * (p1_x - 127) + 127

Well, this is very close to 100% accurate. The problem however, is this, if p1_x and p1_y are too high or too low, we wind up with outputs greater than 255 or less than 0! This stems from sin(x) + cos(x) can be greater than 1. So then I asked, how does one go about getting this back to 1? well anything divided by itself is one, so I divided the whole thing by sin(gyro_angle) + cos(gyro_angle). This means that an input coming in at 45 degrees goes 50% one way and 50% the other instead of 70% and 70%. Take a look:

true_robot_x = (sin(gyro_angle) * (p1_y - 127) + cos(gyro_angle) * (p1_x - 127))/(sin(gyro_angle) + cos(gyro_angle)) + 127
true_robot_y = (cos(gyro_angle) * (p1_y - 127) - sin(gyro_angle) * (p1_x - 127))/(sin(gyro_angle) + cos(gyro_angle)) + 127

However, this will often give you a decimal, so you should run it through a truncate function, too. Now comes the tricky part. How does one give maximum drive in any direction without compromising simplicity of driving? Here comes our friend the if statement to the rescue. You use if statements to determine whether the robot is being driven within 45 degrees of one of its diagonal axis. Well, it always has to be driven within 45 degrees of one of its diagonal axis, so that isn't too big of a problem.

Now, however, we must ask, how do I get maximum power on the straight and diagonal axis? To do this we set the axis being driven "along" to the input with the greatest difference from zero. Some absolute value functions may be required.

We know what to do if the axis is being driven along itself, but what do we do if it isn't being driven along itself? Well we know that if a drive perpendicular to an axis is required, the axis must not drive at all, a.k.a. a value of 127. We come to the conclusion that an axis that is not being driven along must follow the other axis' lead. ENTER THE TANGENT.

More later, I have to go now.
But I'll be back!!!