synthetos / g2

g2core - The Next Generation
Other
625 stars 296 forks source link

Rotary axes values are skewed #439

Closed justinclift closed 4 years ago

justinclift commented 4 years ago

Found an interesting bug today after calibrating the 4th axis (rotary B) of a machine.

Although the machine was moving the correct distance (eg 360 degrees) for a given command (eg G0 B360), the value being returned in posb was skewed. eg 385.xxx etc

The problem is caused by this section of code:

https://github.com/synthetos/g2/blob/e1b5af7e45fe86f8e5558847520bc44ca53e3e72/g2core/canonical_machine.cpp#L708-L712

From discussion with @giseburt, it's used for treating rotary axis as linear. eg to overload ABC axis functionality in use with 3d printers

An initial workaround is to add a test for the axes being rotary, to skip the conversion to linear mm. eg:

    if ((cm.a[axis].axis_mode == AXIS_STANDARD) || (cm.a[axis].axis_mode == AXIS_INHIBITED) ||
        (cm.a[axis].axis_mode == AXIS_RADIUS)) {
        return(target[axis]);    // no mm conversion - it's in degrees
    }
    // radius mode
    return (_to_millimeters(target[axis]) * 360.0 / (2.0 * M_PI * cm.a[axis].radius));

Not sure if this will break things for the overloaded ABC axes use case though.

Maybe we should add a new AXIS enum specifically to allow for the rotary-as-linear use case?

justinclift commented 4 years ago

@giseburt For the extruder use case, we could add a new AXIS_TYPE_EXTRUDER enum to cmAxisType.

Alternatively, we could add AXIS_EXTRUDER to the cmAxisMode enum.

Either way should let us check if the axis is supposed to be a 3D printer extruder head, then adjust the model target calculation as appropriate.

I don't have a 3D printer to test g2core stuff with in the near term though, so am kind of flying blind right atm. :wink:

justinclift commented 4 years ago

This turned out to be due to my misunderstanding the meaning of AXIS_RADIUS, thinking that was the correct setting for a 4th-axis rotary. It's not. It's really a setting used when A, B, or C is used for non-rotary-axis purposes.

I'll need to update my CNC machine settings file to use AXIS_STANDARD instead, which should (in theory) not exhibit the problem mentioned in this issue. :smile: