Newbie C Code


Results 1 to 5 of 5

Thread: C Code

  1. #1
    Registered
    Join Date
    Sep 2017
    Location
    United States
    Posts
    3
    Downloads
    0
    Uploads
    0

    Question C Code

    I tried all evening to find how to read the current value for the x, y, and z axis. I'm sure it's something very simple, but even though I'm perfectly capable of moving each axis, I can't get the value (in machine coordinates).

    Any hint?

    thanks,
    B.

    Similar Threads:


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

    Default Re: C Code

    Hi B,

    The Commanded Destination for axis 0 is ch0->Dest

    The Measured Position for axis 0 is ch0->Position (only valid if you have feedback)

    See KMotionDef.h for the definitions of all the Axis Channel Parameters

    You might also look at the PrintFollowErr.c example:

    Code:
    #include "KMotionDef.h"
    
    main()
    {
        double vx,vy,speed;
        for (;;)
        {
            Delay_sec(0.5);
            WaitNextTimeSlice();  // ensure we don't get interrupted
    	vx = (ch0->Dest - ch0->last_dest) * (1.0f/TIMEBASE);
            vy = (ch1->Dest - ch1->last_dest) * (1.0f/TIMEBASE);
    	printf("speed = %f %f cnts/sec Err = %12.0f %12.0f %12.0f cnts\n",
    			vx,vy,
    			ch0->LastFollowingError,
    			ch1->LastFollowingError,
    			ch2->LastFollowingError);
        }
    }
    Regards

    Regards
    TK http://dynomotion.com


  3. #3
    Registered
    Join Date
    Sep 2017
    Location
    United States
    Posts
    3
    Downloads
    0
    Uploads
    0

    Default Re: C Code

    Quote Originally Posted by TomKerekes View Post
    axis 0 is ch0->Dest
    ch0->Position (only valid if you have feedback)
    thank you! I looked through the .h file and even found the channels (axis 0 - 8), but I didn't see the ch0->Dest and ch0->Position. where's the struct defintion for ch0?

    I did

    Code:
    printf("Axis :\n\tx: %f\n\ty: %f\n\tz0: %f\n\tz1: %f\n", ch0->Dest, ch1->Dest, ch2->Dest, ch3->Dest);
    printf("Axis :\n\tx: %f\n\ty: %f\n\tz0: %f\n\tz1: %f\n", ch0->Position, ch1->Position, ch2->Position, ch3->Position);
    and got this output

    Axis :
    x: 17620.834697
    y: 17620.834697
    z0: -8852.938141
    z1: -8836.988400
    Axis :
    x: 17620.800263
    y: 17620.834697
    z0: -8852.938141
    z1: -8836.988400

    The current machine coordinates are
    X:4.3347
    Y:2.8302
    Z0:-0.5523
    z1:-0.5533

    How do I get to the machine positions from the chx->Dest numbers?

    Last edited by Borgix; 09-12-2017 at 10:51 AM. Reason: additional question


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

    Default Re: C Code

    Hi B,

    where's the struct defintion for ch0?
    see the CHAN structure definition

    How do I get to the machine positions from the chx->Dest numbers?
    Divide by your system's resolution in counts/unit

    HTH
    Regards

    Regards
    TK http://dynomotion.com


  5. #5
    Registered
    Join Date
    Sep 2017
    Location
    United States
    Posts
    3
    Downloads
    0
    Uploads
    0

    Default Re: C Code

    Quote Originally Posted by TomKerekes View Post
    Divide by your system's resolution in counts/unit
    Duh! Sorry for not seeing this myself. I had even gotten the Axis resolution, but it didn't make sense even dividing it, because I didn't realize that I have 2 channels for x What I assumed is y was the 2nd x motor. Works like a charm!

    Axis Resolutions Found:
    x: 4065.040039
    y: 2540.004883
    z: 16000.000000
    DEST Axis :
    x1: 4.000000
    x2: 4.000000
    y: 4.999976
    z1: -0.553309



    z2: -1.000000



Tags for this Thread

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

C Code

C Code