We wrote our own sin() function.
It takes a degree measure in in "funnys", where there are 40 "funnys" per circle. We then directly map that angle to the table after correcting the sign of the number. We are using this to implement a feed forward controller with our PID controller. We will be adding in a function on Thursday that will take 2 angles and some other various data in from our double jointed arm, and output the torque that is being experienced on the "shoulder" joint and implement that into the PID controller for the shoulder.
I also wrote our drive code so that the steering wheel we use specifies the difference in motor power between the left and the right wheels. This even works when the throttle is full forward. The code calculates it out so that even though it would like to run one motor at over full power, it lowers the other motor's power further instead to retain this difference in power.
I like the reduced sensitivity code that I saw earlier. I think that I am going to implement a version of that using one of the buttons on our steering wheel to turn the mode on or off.
Our sin(x) function:
Code:
static const int8 sin_table[] = {0, 20, 39, 58, 75, 90, 103, 113, 121, 125, 127};
int sin(int x) {
char negate = 0;
int result;
// sin(-x) = -sin(x)
if (x < 0) {
x = -x;
negate = 1;
}
// sin(x) = sin(x - 360 degrees)
while (x >= 40) x -= 40;
if (x > 30) {
x = 40 - x;
negate = !negate;
} else if (x > 20) {
x = x - 20;
negate = !negate;
} else if (x > 10) {
x = 20 - x;
}
result = (int) sin_table[x];
if (negate) result = -result;
return result;
}