Struggling with custom kinematics...

More
25 Sep 2024 23:10 - 25 Sep 2024 23:15 #310800 by dave.franchino@gmail.com
Hey kind folks,  

LinuxCNC newby here - please be gentle... I'm clearly over my head here... 

I am trying to learn to use LinuxCNC to run a 2-axis cable robot - each joint features a "drum" of known diameter.  The cables from two drums truncate at a single point.  

Eventually I hope to turn this into a low-cost hot-wire foam cutter that would allow you to use G-code to cut out shapes from large sheets of foam. Here is my crude prototype (not working in cartesian coordinates yet). 

photos.app.goo.gl/z3gUimXLRd3yP33W6


I have my mechanism up and running using "trivial" kinematics and if I simply hang a weight from the left drum (mapped to the X axis in trivial kinematics)  and instruct it to move 10mm, the drum will indeed wrap up enough cable to move the weight up 10mm - so I believe I have correctly computed the parameters to account for the various gear reductions, drum diameter, etc.  

So my understanding is that I need to use a custom kinematics file to provide the kinematics / math needed to translate from the desired cartesian coordinates to the resulting joint rotations.  The math is a bit complicated because the cables wrap around the drum and I need to account for both the length of the tangent line as well as the part of the cable wrapped around the drum. 

Never the less - I believe I have correctly ascertained the math necessary to compute the left and right drum rotation (from home position of 0,0) to achieve a desired X,Y location for the truncation of the two cables. I believe these are inverse kinematics, correct? 

Beyond this, I understand LinuxCNC is looking for the "Forward" kinematics -  (given a left and right cable length, what is the resulting X,Y location.  This math is a bit more complicated and required numerical methods (Newton Raphison - basically "guess and check").

I believe I have "solve" both forward and inverse kinematics conceptually - I have verified that my math is basically working - I wrote a simple program using Processing and I can feed in a desired X,Y location and my Processing program will  correctly spit back the change in cable length from home of 0,0.  Likewise, I have confirmed that my Forward kinematics seem to be working - I can input the change in cable lengths (from home) and my processing program will output the resulting X,Y. 

My custom kinematics (attached) will compile but It's not working yet but I have some conceptual blocks that I could use some assistance on that might help me debug.

the man file states:   3) If required, add hal pins following examples in
the template code

I honestly don't really understand what a hal pin is and whether these are required. I'm running my code on a Raspberry pi if it matters.

I don't really understand why LinuxCNC requires Forward kinematics (even though I think I've solved them). I will be feeding this program G-Code with desired cartesian coordinates and relying on LinuxCNC and my kinematics to resolve these to the desired drum rotations (Inverse kinematics, right?). I don't have any feedback in my device so what does LinuxCNC do with the Forward kinematics?

My inverse kinematics routine computes the drum rotations FROM HOME to a desired X,Y. Is this correct?

I'm not sure how all of this works with "homing" With a conventional CNC I understand you would use limit switches to "home" each of the axis but I don't really have that option since there is no physical "home" for either drum (both of which turn multiple turns). My general approach was going to be to manually "drive" the two drums to the known 0,0 and then manually "home" . Is this viable? Any advice?

My CableKins.comp file is attached. I'm basically breaking out of the forward kinematics since that was erroring out but I'm not getting expected results. If you see any glaring issues I'd appreciate any guidance.

Thanks for any nudges in the right direction!
Attachments:
Last edit: 25 Sep 2024 23:15 by dave.franchino@gmail.com. Reason: drawing didn't come through

Please Log in or Create an account to join the conversation.

More
26 Sep 2024 08:44 #310815 by Aciera

Never the less - I believe I have correctly ascertained the math necessary to compute the left and right drum rotation (from home position of 0,0) to achieve a desired X,Y location for the truncation of the two cables. I believe these are inverse kinematics, correct?

correct

I honestly don't really understand what a hal pin is and whether these are required. I'm running my code on a Raspberry pi if it matters.

hal pins are used to connect signals in the hal layer. If your kinematic does do not need real time information from hal (eg tool length) then you do not need to add any pins.

I don't have any feedback in my device so what does LinuxCNC do with the Forward kinematics?

I believe in your case the forward kinematic is only used until the machine is homed. (ie to calculate the initial XY position) But I might be wrong about that.

Note: Looks like it is possible to also run either inverse / forward kinematics only (but I have never used that or seen it used):
linuxcnc.org/docs/devel/html/motion/kine...rward-transformation
    KINEMATICS_IDENTITY (each joint number corresponds to an axis letter)
    KINEMATICS_BOTH (forward and inverse kinematics functions are provided)
    KINEMATICS_FORWARD_ONLY
    KINEMATICS_INVERSE_ONLY

My inverse kinematics routine computes the drum rotations FROM HOME to a desired X,Y. Is this correct?

That is correct, for HOME = (0,0) and provided you have not built any offsets into your model (eg a tool-offset)

My CableKins.comp file is attached. I'm basically breaking out of the forward kinematics since that was erroring out but I'm not getting expected results. If you see any glaring issues I'd appreciate any guidance.

So what is the error you are getting?
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
29 Sep 2024 03:48 #311012 by dave.franchino@gmail.com
Thanks for the comments - they were very useful.  Here is what is happening when I try running LinuxCNC with my custom kinematics. 

I am running in simulation mode - no hardware is connected or moving
When I launch LinuxCNC, the GUI only lists Joint0 and Joint[1]  - not X and Y (1st image) 
When I "home" the machine, X and Y appear on the GUI however the position of the unit jumps to x1.106, y1.895 (image 2) 
At the same time, the forward kinematics are executing and coverging, but not exactly where I expected them (very close though) 
Am then getting a "Joint Following Error" and the inverse kinematics are executing but returning zeros for every calculation. 
My cablekins.comp file is attached. 

Any ideas?   
 
Attachments:

Please Log in or Create an account to join the conversation.

More
29 Sep 2024 11:48 #311020 by Aciera
I'm afraid I don't have time to debug your kinematic model but it looks like your forward and your inverse kinematic models are not 'inverse' to one another and so a joint position of 0/0 (ie after homing) does not result in a cartesian position of X0/Y0 and vice versa as it should.
Note how the Joint1 position has run away after homing:

 

I'm not really familiar with using Jacobian matrices but I would have expected the forward kinematics to use the jacobian matrix and then invert that to derive the inverse kinematics. You seem to use the jacobian for the forward kinematics only.
Attachments:

Please Log in or Create an account to join the conversation.

More
29 Sep 2024 12:58 #311024 by dave.franchino@gmail.com
The Inverse kinematics can be solved purely by math so that's what I did. I'm new to Newton Raphison - this was my first time using it so I only used it for the forward kinematics.  I wrote a simple processing program to try to confirm the math and that seems to yield correct values. But your explaination makes sense. 

Is it a correct assumption that the forward transformation is only called when homing the machine - and beyond that is not referenced?  In my case, with the cable robot it is not possible to add "home" switches to each of the joints so my current strategy is to manually drive the unit to 0,0 and then home manually.

I'm still confused on how LinuxCNC uses the forward and inverse. I will look for an explaination on why the forward transformation and inverse are yielding different values. 

Thanks for your input!! 

Please Log in or Create an account to join the conversation.

More
29 Sep 2024 14:21 #311027 by Aciera

Is it a correct assumption that the forward transformation is only called when homing the machine - and beyond that is not referenced?

That is what I _think_ is happening but I'm not positive. If you home your machine manually I wonder if you could simply set the cartesian position to zero in your forward kinematics:
    pos->tran.x = 0;
    pos->tran.y = 0;

As long as you have no OFFSET or HOME_OFFSET values set in the [JOINT_n] section of your ini file then that should give you a cartesian coordinate of X0/Y0 for joint0.pos_fb = 0/ oint_1.pos_fb = 0. But again I'm really not sure as to what actually happens behind the scenes which I think is here:
github.com/LinuxCNC/linuxcnc/blob/master...emc/motion/control.c

Please Log in or Create an account to join the conversation.

More
29 Sep 2024 14:43 - 29 Sep 2024 14:55 #311028 by Aciera
So to give you a clear idea of my understanding of how things work.

1. before homing the controller is in 'joint' mode and axes (eg X,Y,Z,...) do not exist
2. a successful homing procedure ends with the joints being in a known position (ie each joint position is either zero or offset by the OFFSET or HOME_OFFSET values set in the [JOINT_n] section of your ini file or has a known position from an absolute encoder)
3. these joint position values are then passed to the Forward kinematic model which calculates the initial values for the axes position.
4. Axes are created as setup in the ini file (eg X, Y, Z) and are initialized with the values calculated in step 3
5. The trajectory planner calculates the axis positions and passes them on to the Inverse kinematic model which calculates the joint position values to be passed on to the motor drives (eg by way of step generators, ethercat command, analog voltage, etc).
Last edit: 29 Sep 2024 14:55 by Aciera.

Please Log in or Create an account to join the conversation.

More
30 Sep 2024 15:50 #311072 by dave.franchino@gmail.com
OK, I found an embarassing math mistake that has fixed my forward transformation. But I'm pretty mystified by my inverse tranformation. All of my constants appear be being set to zero.  

For example, in the following cablekins.comp file I have defined:

const double LEFT_DRUM_X = -100.0;
const double LEFT_DRUM_Y = 250.0;

These are being used in the forward transformation and working properly.  However in the inverse transformation i put in print statements:
 
debugPrint("Debug:     LEFT_DRUM_X = %f, LEFT_DRUM_Y = %f\n", LEFT_DRUM_X , LEFT_DRUM_Y);  

and the output is:

Debug:     LEFT_DRUM_X = 0.000000, LEFT_DRUM_Y = 0.000000

Sorry my C sucks.. any idea why this is going on?

thanks! 


 

Please Log in or Create an account to join the conversation.

More
30 Sep 2024 15:55 #311073 by dave.franchino@gmail.com
 

File Attachment:

File Name: cablekins_...-30.comp
File Size:13 KB
 

File Attachment:

File Name: cablekins_...-30.comp
File Size:13 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
04 Oct 2024 06:12 - 04 Oct 2024 06:17 #311267 by Aciera
Try with
rtapi_print(

instead of
debugPrint(
 

[edit]
with the above I get this output:
In kinematics inverse
Debug: x_target = 0.000598, y_target = 0.000315
Debug: 	LEFT_DRUM_X = -100.000000, LEFT_DRUM_Y = 250.000000
Debug: distance_left_drum_center_to_target = 269.258170, distance_right_drum_center_to_target = 471.698383
Debug: left_tangent_length_to_target = 263.433105, right_tangent_length_to_target = 468.397698
Debug: theta1_left = 0.380509, theta2_left = 0.208385, theta_left = 0.588894
Debug: theta1_right = -1.012197, theta2_right = 0.118369, theta_right = -0.893828
Debug: left_arc_length = 32.803895, right_arc_length = -49.789988
Debug: left_cable_length_to_target = 296.237000, right_cable_length_to_target = 418.607709
Debug: left_cable_length_change = 0.000000, right_cable_length_change = 112.767291
Debug: kinematicsInverse joints: j[0] = 0.000000, j[1] = 112.767291
Last edit: 04 Oct 2024 06:17 by Aciera.

Please Log in or Create an account to join the conversation.

Time to create page: 0.155 seconds
Powered by Kunena Forum