![]() |
trentonDrive.c: our joystick/wheel drive code
1 Attachment(s)
I thought I'd share this bit of code. This is a single-joystick control routine for a robot chassis that uses two-wheel, two-motor drive. This is the version we are using in competition.
Its features include: Squaring the motor values (not the joystick axes). This desensitizes the joystick and compensates for the non-linear speed vs. voltage function of the drill motors. Turning radius independent of speed. The X Axis sets the ratio of the wheel speeds, not the difference. Y axis dead band independent of Victor deadband. Victor deadband bypassed in software. No x axis deadband. Dynamic rounding for an extra 2 bits of resolution for better slow-speed control. No floating point math. I have been very pleased with how this code performs. It probably won't work on your machine without some modification (e.g. my motors are on pwm10 and pwm11) -- your mileage may vary. But since so many robots use two-wheel drive, it might be useful to many people. Zipped code is attached. Code:
#include "trentonDrive.h" |
Re: trentonDrive.c: our joystick/wheel drive code
Just want to say very clever. :)
|
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
Very nice routine, think I'll take it for a spin |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
So, my actual declarations are Code:
// global calibration values. These valuesAnd, in User_Initialization(), there is Code:
// restore joystick calibration values from EEPROMCode:
// process the EEPROM data writing queue.Quote:
The trentonDrive() function is set up to limit the turning radius to spinning around one wheel or the other. If you hold the stick all the way left and run the stick forward and back, the left wheel motor will not turn, and the robot spins around the left wheel. At one time I had trentonDrive() set up to spin on its axis at the left and right joystick extremes, but it was too hard to control larger-radius turns. But spinning on a dime is sometimes very useful. So we added a button (MANUAL_SPIN_BUTTON) that changed it to "spin on a dime" mode. This is great for maneuvering in tight spots. The function is called squaredSpin because it includes the same squaring of the motor values and dead-band removal that makes trentonDrive work well. So trentonDrive() is actually called like this (in Default_Routine()): Code:
if ( ! calibratingJoystickRange() )Here is squaredSpin(): Code:
voidBTW, our robot does not have wheel encoders. If your robot has wheel encoders and can actually control the speed of the wheels, not just the voltage to the motors, then squaring the motor PWM values in trentonDrive() is probably a bad idea, because it tends to mess up the idea that the ratio of the wheel speeds should not change when you change the Y axis. (To reduce joystick sensitivity, try squaring the joystick x/y axis values instead.) In my case (no encoders), squaring the wheel values was simply an heuristic that worked well, perhaps because it made the motors' voltage/speed function more nearly linear. And here is the calibration routine: Code:
#define LOW_TO_HIGH( a, b ) ( (a)==0 ) && ( (b) == 1 ) |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
|
Re: trentonDrive.c: our joystick/wheel drive code
Isn't "Linear Curve" an oxymoron?
Also: LOOKUP TABLE. |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
The main feature of trentonDrive() is that the turning radius is independent of overall speed. The x-axis sets the turning radius, the y axis sets the speed. For a turning radius to be independent of speed, the ratio of the inner and outer wheel speeds must be constant: outer = faster * yAxis; inner = slower * yAxis; where 'faster' is, say, (1+x) and 'slower' is (1-x), where x runs from -1 to +1. But that doesn't matter, because what we care about is that the Yaxis term drops out of the ratio of outer to inner: outer / inner = (faster*yAxis) / (slower*yAxis) = faster / slower; So the ratio is independent of the yAxis. Now, intuitively, I suspected that squaring outer and inner would bring the yAxis into the ratio, but I was wrong: outer^2 = (faster*yAxis)^2 ; = faster^2 * yAxis^2; inner^2 = (slower*yAxis)^2 ; = slower^2 * yAxis^2; So the ratio would be: (faster^2 * yAxis^2) / ( slower^2 * yAxis^2 ) and the yAxis^2 terms once again cancel. So it's still okay to square the wheel values even if you have dead accurate speed control of the motors. trentonDrive() should work very well with such a system. |
Re: trentonDrive.c: our joystick/wheel drive code
Yes. I've been thinking about similar things.
Basically, you can determine the center (and angle) of rotation from the width of the bot and the distance the left and right sides travel in the same time. The only problem is that I don't know the formulas in that context. |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
If you think about it, the front wheels of a car are not always parallel -- during a turn the inside front wheel should be turned at a sharper angle. So this note applies only to two-wheeled bots. If the two wheels are 30" apart, and the outer one runs at three times the RPMs of the inner one, the outer one will trace a circle with three times the circumference, and thus three times the radius. The difference between the outer and inner radii is always 30", so in this case the inner radius must be 15" and the outer, 15 + 30 = 45". radiusInner = radiusOuter - 30; wheelSpeedRatio = radiusInner / radiusOuter; substituting ( radiusOuter - 30 ) for radiusInner: wheelSpeedRatio = ( radiusOuter - 30 ) / radiusOuter ; So if you want a certain turning radius, that is a formula for computing the ratio of wheel speeds that you need. |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
Good catch. |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
Quote:
Quote:
sI*rO = (rO - W)sO sI*rO = rO*sO - W*sO sO*rO - sI*rO = W*sO (sO-sI)*rO = W*sO rO = (W*sO)/(sO-sI) rI=W-rO Thank you! |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
Enough on drive philosophy. Quote:
trentonDrive() sets the inner wheel speed as sI = yAxis * ( 1 - abs( xAxis ) ) where abs( x ) goes from 0 to 1. This means that at the extreme of the xAxis, the inner wheel stops. That makes the bot turn around the inner wheel -- the turning radius of the inner wheel is zero. But if you double the xAxis in that equation: sI = yAxis * ( 1 - 2 * abs( xAxis ) ) now the inner wheel goes full speed reverse at the extreme of the xAxis, and the robot can spin on a dime. You can think of that as the inner radius going negative! I didn't like that on our machine, but it might work better on yours. trentonDrive would have to be reworked a bit to support negative values where it currently expects only positive. When I first worked out the "radius ratio" idea, I only thought to slow down the inner wheel -- I just sent the yAxis directly to the outer wheel: sI = yAxis * ( 1 - abs( xAxis ) ) sO = yAxis But that made it steer funny, like dragging your foot on one side or the other to make it turn. I didn't like how the robot slowed down when it turned. So I sped up the outer as much as I slowed down the inner: sI = yAxis * ( 1 - abs( xAxis ) ) sO = yAxis * ( 1 + abs( xAxis ) ) Now it maintains speed as it turns. Like a car. If you're going to nationals look me up at Team 381! |
Re: trentonDrive.c: our joystick/wheel drive code
Sorry, no. I worked out the behavior in something called Geometer's Sketchpad. Unfortunately, I don't think what I had was actually acurate, just described it.
I was hoping to do it for LVelocity and RVelocity and be able to describe the location as a signed value representing the distance towards the left side (negetive means towards the right). I mean just the algorithm; I didn't plan on putting it in the controller! but this is a whole lot closer. |
Re: trentonDrive.c: our joystick/wheel drive code
Can I keep the foward and backward motions on the joystick the same and delete the motions caused by moving along the x axis? If so, how?
|
Re: trentonDrive.c: our joystick/wheel drive code
Each time I compile the function it says
C:\FrcCode2005v2.2\trentonDrive.c:164:Error [1105] symbol 'pwm10' has not been defined C:\FrcCode2005v2.2\trentonDrive.c:164:Error [1101] lvalue required do you know what could be the problem? |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
Project -> Build Options... -> Project MPLAB C18 tab By "Macro Definitions" click on "Add..." type _FRC_BOARD in the popup, then OK Build everything again. |
Re: trentonDrive.c: our joystick/wheel drive code
Quote:
thanks anyway. |
| All times are GMT -5. The time now is 11:41. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi