I wanted to make sure I have the math correct before implementing it further.
With the measured centerline height offset (b, generally a negative value) and measured bed slope (m, unitless as in/in) the equation for the line the tool will draw as it moves along the axis is y=mx + b, this will give you the height offset from origin at any point along the travel of the carriage. The equation for a circle is x^2 + y^2=r^2, r here being the radius of the work we intend to cut. Substituting mx+b for y in this equation and doing some algebra you can arrive at x=(-mb + sqrt(r^2 + m^2r^2 - b^2))/(m^2 + 1) and x=-((mb + sqrt(r^2 + m^2r^2 - b^2))/(m^2+1) for the general intercepts of the line and the circle. We can ignore the negative value as in the normal case we will be working only in positive x values. With this info we can calculate r-x as the difference between the radius of the work we intend to cut and the radius we need to cut, or the distance between where the tool is and where the tool should be. Note here that the x value is along the ideal axis and not along the axis that the carriage is moving along. To get the value along the x axis we calculate (correction value) = x/cos(arctan(m)). arctan(m) converts the slope into degrees to work with cosine. This value would be subtracted from joints[0] (x) as it is the distance we need to move in the _negative_ direction to meet the circle.
Note that we also need to correct measured centerline height offsets via another method, when sweeping across the top of a test bar with a lathe that has differential wear, the high reading will be at the tangency point between the line the indicator travels and the test bar and NOT the point where the ideal Y axis intersects the top of the test bar. Since we know the slope the line is moving along and the diameter of the test bar, this correction is trivial to calculate. r*sin(arctan(m)) = opp, opp*tan((arctan(m)/2)) = hcorr
The other misalignments that can occur: z axis to work skew, x axis to z skew. X axis to z skew is easy to implement, it is simply multiplying x by the unitless skew error (in/in) between x and z. Work to z skew would be more complex and requires both x and z to be compensated. The z compensation would be a scaling of zactual=z/cos(arctan(zskew)) and the x compensation would be z*zskew=xzcomp. Work to z axis misalignment is _likely_ to fail, and I may not implement it. Getting the headstock and tailstock aligned with the ways is critical, and if the error is in the wrong direction you would end up making bad parts even with compensation.
Onto some programming questions.
Is it acceptable to use fopen in a component? I would like to load the measured data from a file containing an array of floats represented as strings, then strtof these into an array. Doing this is easy enough but I don't know that it's an acceptable method.
I am also not sure after that is done just how to pass the correction off to external offsets. By scaling up and scaling down I assume you mean multiplying the correction by 1000.0f, dividing by 1000.0f (as I saw in the other lathe bed wear compensation post) which should also cast the float to an integer that can be passed off to eo, correct?
Unfortunately I'm not much of a programmer, I'm sure I will have questions and (bad) code that needs looked over as I progress with this.
EDIT:
This compensation fails when the line no longer intercepts the intended circle to be cut or becomes tangent to the circle to be cut. This can be checked using the determinant described here
mathworld.wolfram.com/Circle-LineIntersection.html
, and if the line no longer intercepts the intended circle the compensation will not be performed and the x value requested will simply be passed through (in the case you are facing or cutting off a part and pass through the center to ensure it is cleaned up.)
EDIT 2:
You should also record the distance needed to move x to hit the tangent high point, this will be a direct offset subtracted to x in the case the bed slope is causing the x to move away from the work in the "true" x axis (ie, the bed pivot is not directly below the work centerline.) Am I correct in thinking this?