Interpretter- how to programmically set fixture


Results 1 to 5 of 5

Thread: Interpretter- how to programmically set fixture

  1. #1
    Registered
    Join Date
    Aug 2006
    Location
    USA
    Posts
    17
    Downloads
    0
    Uploads
    0

    Default Interpretter- how to programmically set fixture

    hi all,

    I'm trying to programically set fixture offsets in C++ before G code execution.
    In the KMotionCNC it is done by issuing pure g text command line aka "G54" which invovles createing/saving it to separate file and invoking "Interpret".
    Is there any way to do the same by altering variable directly?

    Tried this function based on KMotionCNC code but it does not work:

    void CMotion::SetFixture(int fixtureNo, int X, int A)
    {
    setup_pointer ps = Interpreter->p_setup;
    double *Vars = ps->parameters;

    int Fix = fixtureNo - 1; // G54 is fixture "1", so it is 1 based
    Vars[5221 + Fix * 20 + 0/*X axis*/] = (double)X *0.01 ;
    Vars[5221 + Fix * 20 + 3/*A axis*/] = (double)A *0.01;

    if (Interpreter->ReadAndSyncCurPositions(&ps->current_x, &ps->current_y, &ps->current_z,
    &ps->AA_current, &ps->BB_current, &ps->CC_current)) return;

    Fix = ps->origin_index - 1;

    Vars[5221 + Fix * 20 + 0] += ps->current_x;
    Vars[5221 + Fix * 20 + 3] += ps->AA_current;

    // make sure Settings are in sync with any modified Vars
    Interpreter->p_setup->origin_index = -1; // set invalid so it updates
    Interpreter->ChangeFixtureNumber(fixtureNo);
    }

    any ideas what is missing here?
    the above func used in this seq:
    ...
    SetFixture(1, 50000, 3000); //G54 is fixture "1"
    Interpreter->Interpret(BoardType, InFile, 0, -1, true, StatusCallback, CompleteCallback);
    ....

    then executing G code:
    G0 X800 A60

    machine still moves to absolute pos ("800","60"). Tried to add G54 on top but no chagne
    (there is another strange behaviour of G0 - posting it on separate thread)



  2. #2
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2790
    Downloads
    0
    Uploads
    0

    Default Re: Interpretter- how to programmically set fixture

    Hi funding33,

    I think you are basically doing things correctly except there is an issue with Initializing the Interpreter. There is a function to Initialize the Interpreter.

    Interpreter->InitializeInterp();

    This reads the Var files from the *.var disk file. It also reads all the default Interpreter settings (origin index, origin offset, etc) from the *.set settings file. This initialization will basically overwrite any changes you have made to the Interpreter.

    The Interpreter will automatically initialize under the following 2 conditions: #1 it has never been initialized. #2 you specify the "restart" parameter as true.

    So please make the following 2 changes to your code:

    #1 call Interpreter->InitializeInterp(); when your App starts and before calling your SetFixture() function.

    #2 change the restart parameter in the Interpreter->Interpret() call to false.

    On a side note I don't really understand what you are trying to accomplish with the ReadAndSyncCurPositions() adjustment but I assume you have a reason for this.

    HTH
    Regards

    TK
    http://dynomotion.com


  3. #3
    Registered
    Join Date
    Aug 2006
    Location
    USA
    Posts
    17
    Downloads
    0
    Uploads
    0

    Default

    Hi Tom,

    the InitializeInterp() is called as startup. If I use false in Interpreter->Interpret() the motion instead of commanded position (i.e. A30) goes to (current position+dest_pos)*25.4 despite A axis is in degrees and Interpreter->p_setup->length_units=CANON_UNITS_MM (I'm working in mm)




    Here is general description what my app should do:
    there 2 coord axes X, and A(degrees). Both axes receive native position from KFLOP already gain scaled to mm and degrees.
    It should start and init at fixed state without any possibility to remember anything.
    Before each start to interpret it should reset to that same initial state and via c++ code preset X and A offsets, diameter of A and feedrate. After G code ends, axes are disabled and user can freely move A to any random pos and next start shold be from there( now enabling axes after manual move motors jumps back last pos). Goal is to remove/minimize all external setting files and do all in code.


    This is what I have now and it does not work
    void CMotion::Init()
    {
    SetMotionParams();
    Interpreter->InitializeInterp(); // now that all the parameters are loaded - Initialize the Interpreter
    }
    void CMotion::SetMotionParams()
    {
    MOTION_PARAMS *p = Interpreter->GetMotionParams();

    p->BreakAngle = 90.0;
    p->CollinearTol = 0.01;
    p->CornerTol = 0.01;
    p->FacetAngle = 1.2;
    p->TPLookahead = 1.0;
    p->RadiusA = 100.0/25.4;// <= TUBE RADIUS (some dfault 100.0)
    p->RadiusB = 1.0;
    p->RadiusC = 1.0;
    p->MaxAccelX = 10000.0/25.4;
    p->MaxAccelY = 1.0;// not used
    p->MaxAccelZ = 1.0;// not used
    p->MaxAccelU = 1.0;// not used
    p->MaxAccelV = 1.0;// not used
    p->MaxAccelA = 20000.0; // degresds per min
    p->MaxAccelB = 1.0;// not used
    p->MaxAccelC = 1.0;// not used
    p->MaxVelX = 150/25.4;
    p->MaxVelY = 1.0;// not used
    p->MaxVelZ = 1.0;// not used
    p->MaxVelU = 1.0;// not used
    p->MaxVelV = 1.0;// not used
    p->MaxVelA = 300.0;// degresds per min
    p->MaxVelB = 1.0;// not used
    p->MaxVelC = 1.0;// not used
    p->CountsPerInchX = 1.0*25.4;
    p->CountsPerInchY = 1.0;// not used
    p->CountsPerInchZ = 1.0// not used
    p->CountsPerInchU = 1.0;// not used
    p->CountsPerInchV = 1.0;// not used
    p->CountsPerInchA = 1.0;
    p->CountsPerInchB = 1.0;// not used
    p->CountsPerInchC = 1.0;// not used
    strcpy_s(Interpreter->ToolFile, "");
    strcpy_s(Interpreter->SetupFile, "");
    strcpy_s(Interpreter->GeoFile, "");
    strcpy_s(Interpreter->VarsFile, "");
    p->DegreesA = true;
    p->DegreesB = false;
    p->DegreesC = false;
    p->ArcsToSegs = true;
    p->MaxRapidFRO = 1.0;
    p->DoRapidsAsFeeds = false;
    p->SoftLimitPosY = 1.0e+30;
    p->SoftLimitNegY = -1.0e+30;
    p->SoftLimitPosZ = 1.0e+30;
    p->SoftLimitNegZ = -1.0e+30;

    Interpreter->p_setup->arc_radius_tol = 0.2;
    Interpreter->p_setup->arc_radius_small_tol = 25.4e-12; // was 1.0e-12 inch
    Interpreter->CoordMotion->SetTPParams();
    Interpreter->CoordMotion->m_Simulate = false;
    Interpreter->CoordMotion->m_DisableSoftLimits = false;
    Interpreter->p_setup->length_units = CANON_UNITS_MM;
    }

    bool CMotion::ExecuteLoadedPart(void)
    {
    int BoardType = BOARD_TYPE_UNKNOWN;
    CTube* pldTube = m_pparentStatCtrl->GetTubeSet()->GetLoadedTube();
    CPart* pldPart = m_pparentStatCtrl->GetTubeSet()->GetLoadedPart();

    SetMotionParams(); // set interpreter motion params
    Interpreter->InitializeInterp();
    Interpreter->GetMotionParams()->RadiusA = ((double)(pldTube->GetDiameter()))*0.01*0.5/25.4; // set diameter to interpretter
    SetFixture(1, -pldPart->GetX0(), -pldPart->GetA()); //G54 is fixture "1"

    if (!m_pparentStatCtrl->GetProfileSet()->GetActiveProfile()->GetParamByIndex(PR_CUTSPEED)->GetValid()) return false;
    double feedRate = 0.01 * (double)m_pparentStatCtrl->GetProfileSet()->GetActiveProfile()->GetParamByIndex(PR_CUTSPEED)->GetVal();
    Interpreter->p_setup->feed_rate = feedRate; // set feed rate in units/min

    if (Interpreter->CoordMotion->KMotionDLL->CheckKMotionVersion(&BoardType)) return false;

    Interpreter->CoordMotion->ClearAbort();
    Interpreter->CoordMotion->m_AxisDisabled = false;
    Interpreter->CoordMotion->ClearHalt();
    USES_CONVERSION;
    CStringA InFile = CT2A(m_pparentStatCtrl->GetStorage()->StorGetActiveFileName());
    Interpreter->Interpret(BoardType, InFile, 0, -1, false, StatusCallback, CompleteCallback);
    return true;
    }

    void CMotion::SetFixture(int fixtureNo, int X, int A)
    {
    setup_pointer ps = Interpreter->p_setup;
    double *Vars = ps->parameters;

    int Fix = fixtureNo - 1; // G54 is fixture "1", so it 1 based
    Vars[5221 + Fix * 20 + 0/*X axis*/] = (double)X *0.01 ;
    Vars[5221 + Fix * 20 + 3/*A axis*/] = (double)A *0.01;

    //// left over from KMotionCNC////////////////
    // if (Interpreter->ReadAndSyncCurPositions(&ps->current_x, &ps->current_y, &ps->current_z,
    // &ps->AA_current, &ps->BB_current, &ps->CC_current)) return;
    //
    // Fix = ps->origin_index - 1;
    //
    // Vars[5221 + Fix * 20 + 0] += ps->current_x;
    // Vars[5221 + Fix * 20 + 3] += ps->AA_current;

    // for inches round to 6 digits for mm round to 4 digits
    RoundReasonable(Vars[5221 + Fix * 20 + 0/*X axis*/]);
    RoundReasonable(Vars[5221 + Fix * 20 + 3/*A axis*/]);

    // make sure Settings are in sync with any modified Vars
    Interpreter->p_setup->origin_index = -1; // set invalid so it updates
    Interpreter->ChangeFixtureNumber(fixtureNo);
    }



  4. #4
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2790
    Downloads
    0
    Uploads
    0

    Default Re: Interpretter- how to programmically set fixture

    Hi funding33,

    If I use false in Interpreter->Interpret() the motion instead of commanded position (i.e. A30) goes to (current position+dest_pos)*25.4 despite A axis is in degrees and Interpreter->p_setup->length_units=CANON_UNITS_MM (I'm working in mm)
    I'm sorry I don't understand what you mean by this. Can you give an example?

    I do see you set CANON_UNITS_MM in the function SetMotionParams(); but then call Interpreter->InitializeInterp(); which will reset the Interpreter to all the defaults in the *.set file.

    It should start and init at fixed state without any possibility to remember anything.
    Before each start to interpret it should reset to that same initial state and via c++ code preset X and A offsets, diameter of A and feedrate.
    I don't understand what you mean by this either.

    After G code ends, axes are disabled and user can freely move A to any random pos and next start shold be from there( now enabling axes after manual move motors jumps back last pos).
    Do you have Servos with encoders? Or open loop? With Servos enabling the axis should set the Destination to the current Encoder Position. You might test this with EnableAxis0 on the console screen. Does the axis remain where it was?

    Regards

    TK
    http://dynomotion.com


  5. #5
    Registered
    Join Date
    Aug 2006
    Location
    USA
    Posts
    17
    Downloads
    0
    Uploads
    0

    Default

    Hi Tom,

    Thanks for input.

    #1
    I dont know why but all the mess when using "false" in Interpreter->Interpret() was caused by the altering single motion param after InitializeInterp(). Possibly it then causes some other parameters and vars including units to be messed up
    was:
    Interpreter->InitializeInterp();
    Interpreter->GetMotionParams()->RadiusA = 100.00; // set diameterto interpretter

    changing the order fixed issue:

    Interpreter->GetMotionParams()->RadiusA = 100.00; // set diameterto interpretter
    Interpreter->InitializeInterp();

    #2 issue -(enabling axes after manual move motors jumps back last pos)
    Interpreter->ReadAndSyncCurPositions() for some reason takes a destination value from KFLOP, not the actual; position as seen in pic. Then when axis enabled the interpreter rewrites that old destinaltion back to kflop causing a violent jump. Reading and seting actual pos manually fixes that.

    Tharead is solved
    Interpretter- how to programmically set fixture-screen-jpg



  6. #6
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2790
    Downloads
    0
    Uploads
    0

    Default Re: Interpretter- how to programmically set fixture

    Hi funding33,

    Regarding #1 after modifying any of the MotionParams you must make a call to:

    CoordMotion->SetTPParams();

    in order for the Trajectory Planner to "take" the new settings. The Interpreter->InitializeInterp(); also makes this call and updates any changes to MotionParams. So for example after changing the RadiusA call SetTPParams() to update. This will update the MotionParams without resetting the Interpreter to the default state.

    Regarding #2: Yes ReadAndSyncCurPositions() syncs to the last theoretical commanded positions. The assumption is that this is the best representation of the position of the axis without including any random servo errors. It also works with open loop systems that don't have position feedback. Enabling the Axes before doing the sync should also solve the problem.

    Regards

    TK
    http://dynomotion.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

Interpretter- how to programmically set fixture

Interpretter- how to programmically set fixture