Thread: Drive Equations
View Single Post
  #6   Spotlight this post!  
Unread 11-02-2006, 22:28
CronosPrime1 CronosPrime1 is offline
Registered User
FRC #0321
 
Join Date: Jan 2006
Location: Hyperspace
Posts: 53
CronosPrime1 is an unknown quantity at this point
Re: Drive Equations

For example, my smoothed out motor curve looks as shown in the image at the bottom of this post.

If you're wondering what equation I used: it is as follows, in Java syntax (in the C code, I just have a lookup table):

(i is the joystick input)

pwm_output [i] = 127-42.5*(Math.pow (1.010889286,-i+127)-1)+Heaviside (i-127)*42.5*(Math.pow (1.010889286,-i+127)-1)+Heaviside (i-127)*42.5*(Math.pow (1.010889286,i-127)-1);

Heaviside (i) is just a fancy term. By definition,

Heaviside (i) = 0 if i < 0
Heaviside (i) = 1 if i >= 0.

Thus, Heaviside (i-127) is 1 if i >= 127 and 0 otherwise.

It allows me to write the whole function in one equation. So really, this is two exponential functions stuck together.

If you want the syntax for the table,

Code:
rom const int drive_lookup[]= {0, 0, 0, 0, 0, 5, 10, 13, 15, 16,
18, 20, 21, 23, 24, 26, 28, 29, 31, 32, 34, 35, 36, 38, 39, 41,
42, 43, 45, 46, 47, 49, 50, 51, 53, 54, 55, 56, 58, 59, 60, 61,
62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 88, 89, 90, 91, 92, 93,
94, 94, 95, 96, 97, 98, 98, 99, 100, 101, 101, 102, 103, 103, 104,
105, 106, 106, 107, 108, 108, 109, 110, 110, 111, 111, 112, 113,
113, 114, 114, 115, 116, 116, 117, 117, 118, 118, 119, 120, 120,
121, 121, 122, 122, 123, 123, 124, 124, 125, 125, 126, 126, 127,
127, 127, 128, 128, 129, 129, 130, 130, 131, 131, 132, 132, 133,
133, 134, 135, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140,
141, 142, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149,
150, 150, 151, 152, 152, 153, 154, 155, 155, 156, 157, 158, 159,
159, 160, 161, 162, 163, 164, 165, 165, 166, 167, 168, 169, 170,
171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 197, 198,
199, 200, 202, 203, 204, 206, 207, 208, 210, 211, 212, 214, 215,
217, 218, 219, 221, 222, 224, 225, 227, 229, 230, 232, 233, 235,
237, 238, 240, 245, 250, 254, 254, 254, 254, 254, 254};
You can plug this right into your program and just say:
Code:
pwm01 = drive_lookup [p1_y];
to map your pwm01 to your p1_y using my curve.

At the endpoints, I chose to replace several of the last terms with an endvalue. Notice how there are several 254 terms at the end and several zeros in the beginning.
Attached Thumbnails
Click image for larger version

Name:	image002.gif
Views:	54
Size:	4.4 KB
ID:	3970  
__________________

Last edited by CronosPrime1 : 11-02-2006 at 22:34.