A VERY nice perl script for generating lookup tables.

well everybody, i have spent the last two days working painstakingly on this Perl script that generates a lookup table for C. Right now it generates the joystick position then a tab then the corresponding PWM value. It is easy to switch the output format to generate a series of array definitions for a C .h file. I am not completely familiar with the max and min values that can be sent to the PWM (255 or 254? and 0 or 1?) so the program protect against anything lower then 126 away from the center of the graph on either side.

The program defaults to having 127 be zero but all that needs to be done to change that is to set the x offset variable. The left side and right side curves can be independently controlled as well as up and down (in their position, not the function used to generate them).

The script can graph 2 functions. There is a variable ($yOuterOffset) that controls how far from the center the first function ends and the second begins. The center of the graph is determined by ($xOffset,$yOffset).

I included a .xls file of some sample data generated by the script. The other lines represent 10 and -10 (the minimum for the victors) and a line with the slope 1 to give perspective.

This is my first contribution to Open Source and i would appreciate all comments/suggestions.

I move that .pl be legit attachment extentions

I apologies for my bad spelling and such. QBasic was my first language and i am just now learning English.

tablescript.txt (4.47 KB)
tabletest.xls (30 KB)


tablescript.txt (4.47 KB)
tabletest.xls (30 KB)

We have simple Python hacked-up scripts that generate our drivecurves. The curves we usually have:

  1. Quadratic, scaled to 0 - 255
  2. Sine (actually, cosine) wave, scaled to 0-255

With the joysticks we got this year, #1 worked the best for us.

not sure what u mean… can u give examples?

To make a drive curve, you don’t need any more code than:

echo ‘{’

for loop:
print CurveFunction(x),’,’

echo ‘};’

As far as the curves, a quadratic curve is simply scaling a quadratic function f(x)=x^2 such that f(127)=255.

what’s a drive curve and how is it helpful? why would i want to generate a drive curve?

A “drive curve” is just a way of saying that you want your robot to start out moving slowly, but gradually (typically in a curved way) get faster. It’s just designed to make control a little easier and to prevent wear and tear from fast reverses in direction. :slight_smile: In many cases, your driver may do this manually (a good one does it without even realizing it), but it’s typically very important for an accurate autonomous mode.

A drive curve makes it easier to control the bot in the lower ranges. Look at the excel graph i did.

Most people do not maneuver at high speeds. With a drive curve you can devote large amounts of your joystick swing to the lower speeds while still being able to hit the high speeds.

In its simplest form, yes. My script, however, incorperates compensation for Victor deadbands and it allows the use of a two curve composite.

Here is an updated version. I fixed a few bugs, made it easier to edit and documented it a little better.

tablescript.txt (5.54 KB)


tablescript.txt (5.54 KB)

It would be nice to see some user input instead of it all being hard-coded. Reasons being, I know Perl is an interpreted language and that its quick to execute, but on-the-fly curve changes would be very efficient. You could even go further and use another language to build a GUI that graphs the curve while you input the equation for the curve. If you need an example, I can show you a GUI written in Java that graphs equations (written by a friend) and change it so that it can fit your needs. Otherwise, the script is nice. Good job on it. :slight_smile:

Yea, i’m going to post a bugfix in the code in a sec. I think imay work on a way to edit paramaters from command line. the hard coded ones would still be here but they would be overridable.

BUGFIX!!!

tablescript.txt (5.58 KB)


tablescript.txt (5.58 KB)