I'm something of a rookie to the programming field, particularly robotics programming. Heck, I didn't really know C until the beginning of the season, and I had no CLUE what a PD or PID loop was until a mentor showed me the ins and outs of it...
However, one of our team rules being that only the students may produce the final product, I was drafted into the job--especially since I was the only guy on the team that knew a #define from an int.
Thankfully, I had an older robot to practice on, and I'm fairly well up on my higher math algorithms, so it wasn't all that bad...
Our robot is a 2-wheel drive, caster steering lightweight--not designed for pushing matches, but fast enough to get out of the way should one begin. Given that information, I quickly realized that even though our team used NO gearbox except the KOP transmission, we needed to have both very high speed and enough precision to control the 'bot at low speed. To combat this discrepancy, I eventually resorted to a math trick I'd learned long ago... Exponential control.
The code goes something like this:
Quote:
//Convert input from 0 - 255 range to -127 - 127 range
input -= 127;
//Square input and divide by 127, giving us the expected range--since
// squaring a variable loses its sign, multiply by 1 or -1 depending on the
// input sign
output = (input * input / 127) * (input > 0) ? 1 : -1;
//Send out the modified output; add 127 to put it back into 0 - 255 range
motor_speed = output + 127;
|
This control algorithm seems to work quite nicely for our drivers. They're able to control the machine with a high degree of precision when the input is small, but as they push the stick farther, the robot gains in speed... well, exponentially.
Of course, this is a little different than the code we used, as it's not mixed for multiple drive motors or anything.
A couple other cool things we did:
-Position-based arm: Position is controlled by a shaft encoder; if the arm is knocked off position it will automatically try to return to that position
-Simple drive system--the robot can be controlled completely using only two joystick axis, the top hat, and a trigger
-Automated function for "return to home"--resets the robot, brings the arm and wrist back into folded positions and readies it for another round
-Automated function for "drop ringer"--we determined a precise sequence of motions that are very efficient for hanging a ringer on a post once positioned properly, then assigned a button to perform all these motions simultaneously. The result is rather cool--the robot drops the ringer on the rack in one smooth (though rather noisy--it's running 3-4 elements simultaneously!) motion, much faster than any of our drivers could perform the task, and gets the arm out of the way of the ringer entirely.
We tinkered around with autonomous code, and with the use of 2 PD positioning algorithms got the robot to drop a ringer successfully. However, we'll need a couple things tweaked before competition--the building team crated the robot before I could manage to get the code to raise the arm to the proper scoring position in!
