Join us in Chat. Click link in menu bar to join. Unofficial chat day is every Friday night (US time).

0 Members and 1 Guest are viewing this topic.

unsigned int Rib_1_Left_Adapt[9];int amp_avg_F=11;int amp_avg_R=15;int amp_avg_U=5;int amp_avg_D=8;signed long int theta;//some angle in degreesdouble weightA;//some value below 1double weightB;//once per loopweightA=(amp_avg_U/amp_avg_F)/(tan(theta)+(amp_avg_U/amp_avg_F));weightB=tan(theta)/(tan(theta)+(amp_avg_U/amp_avg_F));//10 equations like this per loopRib_1_Left_Adapt[time_position]= Rib_1_Left_F[time_position]*weightA + Rib_1_Left_U[time_position]*weightB;

then you could have a smaller more detailed lookup table if theta only falls in a specific range.

I would scale things up by 1000

weightA=(Lu-Tu*tan(theta))/((Tf-Tu)*tan(theta)-Lf+Lu);weightB=1-weightA;

As such, this brings up another question . . . so I have tan(theta), but I assume theta must be in radians for it to calculate properly, and the solution will also be in radians, right? Doesn't this force me to use floating point? tan(1.5) != tan(1500)

QuoteAs such, this brings up another question . . . so I have tan(theta), but I assume theta must be in radians for it to calculate properly, and the solution will also be in radians, right? Doesn't this force me to use floating point? tan(1.5) != tan(1500)No - you just prescale the 1.5 to an integer value. If you are using radians instead of degrees, your range is 0 to 6.28 radians, so you could multiply the radians by 100 to create 628 table entries. Or you could note that there is redundant information in the table for 0 to 157, 158 to 314, 315 to 472, and 473 to 627, and set up the calculation based on your quadrant

Use a lookup table. They (if done properly) end up in FLASH, and you've got 256 KB of the stuff.