C program control issues

Moderators: TomKerekes, dynomotion

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: C program control issues

Post by TomKerekes » Wed Dec 30, 2020 3:48 pm

Hi Peter,

You learn quickly.
As you can see, the Spindle has quite a sizeable Following Error (if that's the correct term) and I cannot reduce it significantly using the Integral term as I was able to do quite successfully with both X and Z. In fact it becomes unstable before it has had any significant effect at all. X & Z behaved themselves pretty much like 'text book' cases.

Since it is the Spindle, perhaps it won't matter so much, although I would like to be able to do single point thread cutting with it. Maybe I can play around with the motor drives later and see what I can find there, but for now it will do.
Correct there usually isn't any need for a Spindle to be positionally accurate even when Threading.
Regards,

Tom Kerekes
Dynomotion, Inc.

hatcat
Posts: 13
Joined: Sun Aug 05, 2018 8:39 am

Re: C program control issues

Post by hatcat » Thu Dec 31, 2020 1:12 am

Hi Tom,

I'm needing some help with a C program please. The object of this is to increase my knowledge of using the C programs to control the machine. I realise that the answer to my question is probably quite simple, but I cannot work it out yet.

I have powered the machine up and have downloaded the Axis 0 Configuration. I presume that that should connect DAC5 to (Axis) Channel 0.
Axis 0 Config.png
Then I run the following (basically nonsense) program which is one of the standard supplied programs with some mods so I can watch it and control its operation from the KMotion C Programs window. The program clearly runs, because I can watch the dig bits do what they should on the Dig I/O window and on the Console window. It waits for me to operate one of the home switches (Bit 141) and then proceeds and finishes. All that is working as I expect.
SimpleHomePM.png
The problem I'm having is that the Jog lines do not cause a change in the DAC5 output. (I'm checking this with a multimeter on the actual Kanalog output connection.) I guess that I just have to make another 'connection' somewhere between the Jog statements and the DAC5 output, but where please? What have I missed?

Another unrelated thought I had was whether Single Point Threading is a situation where one might use a Master/Slave Axis arrangement, so that it doesn't matter how far off the 'proper' path the Spindle is, as long as the Z Axis (i.e. the cutting tool) is faithfully following it (at some specific 'gear ratio'), then all will be well?

Thanks & have a great evening.
Peter

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: C program control issues

Post by TomKerekes » Thu Dec 31, 2020 1:36 am

Hi Peter,

Is Axis 0 enabled? Check the Axis Screen.

When Jogging is Axis 0 Destination changing? Check the Axis Screen.

Is the DAC being commanded to a voltage? Check the Analog Screen.

Otherwise how the DAC output changes depends on how the axis is tuned. PID gains, Filters and so forth on the Step Response and Filters Screens. How is the servo tuned? Show us the Step Response and Filters Screens.

Image
Regards,

Tom Kerekes
Dynomotion, Inc.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: C program control issues

Post by TomKerekes » Thu Dec 31, 2020 2:00 am

Another unrelated thought I had was whether Single Point Threading is a situation where one might use a Master/Slave Axis arrangement, so that it doesn't matter how far off the 'proper' path the Spindle is, as long as the Z Axis (i.e. the cutting tool) is faithfully following it (at some specific 'gear ratio'), then all will be well?
Yes that is how Threading works.
Regards,

Tom Kerekes
Dynomotion, Inc.

hatcat
Posts: 13
Joined: Sun Aug 05, 2018 8:39 am

Re: C program control issues

Post by hatcat » Wed Feb 03, 2021 12:21 pm

Hi Tom,

Thanks very much for your help with the previous issue. I'm finally getting back to this again and having a problem I'd appreciate some help with please.

I have now got my axes jogging correctly from the KMotionCNC Jog buttons, and so I'm trying to get an axis homing routine for X & Z set up with some limited success. I have been having some strange things happening. At least they seem strange to me, but you'll probably see what's going on. I'll describe it as best I can.

I started by using SimpleHomeIndexFunction.c & SimpleHomeIndexFunctionTest.c. I set up the correct call parameters for my Z axis only (I prefer to deal with one problem at a time) in the Test program, remmed out the X & Y sections of the code and got that working successfully. I don't currently have an Index signal, so I'm just using the Limit switch for both functions. So far, so good.

I then swapped the Z axis parameters for the X axis ones and that worked too.

Time to put them both together - I put the appropriate parameters into the Z & X sections, leaving the Y section still remmed and tried it out. That's where the wheels fell off for me. I was running it as C Program #4 in KMotion and it started out homing the Z axis, but then just stopping in the called routine (I presume) because it no longer printed out the success or otherwise text on the Command Screen as it had previously. It made no attempt to move on to the X axis and the green running 'flag' was left on in the C Programs window.
210203 problem 2.png
I tried adding printf statements through the code to try to diagnose where it had reached before stopping, but these were rather random as to whether they would print or not, which I thought rather strange too. Sometimes it was as if they were being caught in a buffer somewhere and suddenly it would print several of them all at once. It appears that I've got the syntax incorrect on the 'Jog Axis' one, but I can't see why. Eventually, it did nothing (visible) when I hit Run again so I started KMotionCNC to make sure that the I could still jog the axes. They worked, and then the Home program would run the Z axis again each time, but still not the X.

After some testing, I discovered that if I ran the Home program (which homed Z only) then jogged the Z axis in KMCNC, the X axis would then immediately home correctly. It is as if the jogging in KMCNC somehow snaps the Homing program out of its dead spot and it then continues! This probably all makes sense to you, but it surely doesn't to me in my ignorance!

I'd appreciate knowing where I have gone wrong please. My files are attached.

Additionally, there are three 'return's after the 'Homing failed' messages in the SimpleHomeIndexFunctionTest code which I can't make out the reason for. Would you mind please explaining their purpose for me? I've remmed them out and left them in - it makes no difference to the problem.

Thanks very much & have a great day!

Peter
Attachments
SimpleHomeIndexFunctionTestPM2.c
(2.29 KiB) Downloaded 84 times
SimpleHomeIndexFunction.c
(2.39 KiB) Downloaded 85 times
init 210117.c
(4.06 KiB) Downloaded 81 times

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: C program control issues

Post by TomKerekes » Wed Feb 03, 2021 7:33 pm

Hi Peter,

This is wrong:

Code: Select all

	printf("Jog axis ", axis, " at ", speed*dir, "\n");
The way printf works is a single string is specified as the first parameter which printed. This string may contain embedded format codes such as %d, %f, %s for embedded decimal numbers, floating point numbers, or strings. For each format code in the string a parameter should be added that is a variable of that type. In the code above the first parameter is a simple string "Jog axis" contains no format codes so is simply printed as is (with no \n btw) and the other parameters are ignored. Its up to you to put the correct corresponding parameters for each code. If you compile with the TI Compiler it will flag inconsistencies and warn you of such errors.

printf is vary powerful. You might read this reference.

So the correct format would be:

Code: Select all

	printf("Jog axis %d axis at speed %f\n", axis, speed*dir);

This code:

Code: Select all

	Jog(axis,2);							// stop. normally 0, but this dac needs 2 to output 0V
	while (!CheckDone(axis))			 	// loop until motion completes
		if (!chan[axis].Enable) return 1; 	// abort/exit if disabled
Commands the axis to move at a speed of 2 forever and then waits until the axis is stopped or disabled which will never happen so essentially hangs the program until something else stops the axis like releasing a Jog button in KMotionCNC.

You shouldn't be concerned about any DAC offset. If you command the axis to stop, and the axis is tuned properly, the servo feedback will output whatever is necessary to stop the axis at the commanded destination regardless of offsets, gravity, disturbances, etc.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

hatcat
Posts: 13
Joined: Sun Aug 05, 2018 8:39 am

Re: C program control issues

Post by hatcat » Wed Feb 03, 2021 11:23 pm

Hi Tom,

Thanks very much for your advice and patience. That problem is now sorted!

My ignorance is showing again. I'm trying to get it to run GCode now and KMotionCNC is giving me an error on about the simplest program I can write, as shown below.
210204 problem 1.png
I can jog the axes from the KMCNC screen pictured, so I don't think it is a 'can't drive the axes' type error. Would you please enlighten me as to what the problem could possibly be?

Thanks very much,

Peter

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: C program control issues

Post by TomKerekes » Thu Feb 04, 2021 12:44 am

Hi Peter,

That can happen if an Axis resolution is set to zero even if the axis is not in use (Tool Setup | Trajectory Planner | Axis Paramaters | Cnts/inch). We should add a better error message for that.

Otherwise please post your Tool Setup Screens.
Regards,

Tom Kerekes
Dynomotion, Inc.

hatcat
Posts: 13
Joined: Sun Aug 05, 2018 8:39 am

Re: C program control issues

Post by hatcat » Thu Feb 04, 2021 1:04 am

Hi Tom,

Yeah - that was it! I guess I must have innocently changed Y to 0 because it doesn't exist.

Thanks for the help. It would have taken me a VERY long time to find that one!

Peter

Post Reply