C program

Moderators: TomKerekes, dynomotion

Post Reply
Ben Are
Posts: 1
Joined: Thu Oct 29, 2020 8:42 am

C program

Post by Ben Are » Wed Dec 09, 2020 5:53 pm

Hi.

Do i need to be a c-code expert to retrofit kflop/kanalog on my old heidenhain/TOS mill?

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

Re: C program

Post by TomKerekes » Wed Dec 09, 2020 5:56 pm

Hi Ben,

You don't need to be an expert, but you must be able to read, understand, and modify examples. You might read this.
Regards,

Tom Kerekes
Dynomotion, Inc.

larryjamessmith
Posts: 22
Joined: Mon Dec 23, 2019 9:18 pm

Re: C program

Post by larryjamessmith » Thu Jul 14, 2022 9:46 pm

I have a simple question which has turned into a great puzzle for me as I have not been able to find an answer anywhere in the documentation or in this forum. I am looking for the C functions to return the integer and fractional portions of a number. Within the standard C math.h definitions I have found the floor(x) and modf(x, double *ip) functions which should do the trick. However, in KMotionDef.h I see external declarations for many of the standard math functions but not for these functions.

1) Are all functions in ANSII C available to the Dynomotion C compiler?
2) If external declarations are understood by the compiler why are the not included in any reference documents?

I may just try using these and see if the compiler objects or they fail to work....

larryjamessmith
Posts: 22
Joined: Mon Dec 23, 2019 9:18 pm

Re: C program

Post by larryjamessmith » Thu Jul 14, 2022 10:34 pm

I tried to add an external reference for floor(x) function.... compile error.

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

Re: C program

Post by TomKerekes » Fri Jul 15, 2022 12:47 am

Hi Larry,

modf is available. But needs to be defined with:
double modf(double, double*); // returns integer and fractional parts with more than 32-bit precision

There is also:
float fractionf(double x); // returns fractional part as a float

floor is not included.

You might also see the Modulo360.c example

It would be helpful to know what you are trying to accomplish.
Regards,

Tom Kerekes
Dynomotion, Inc.

larryjamessmith
Posts: 22
Joined: Mon Dec 23, 2019 9:18 pm

Re: C program

Post by larryjamessmith » Fri Jul 15, 2022 5:45 pm

Tom,

Thank you for your suggestion. That should work. It would be useful to have a complete reference for all operations and functions supported by the compiler since KMotionDef.h is apparently not comprehensive.

Here is the problem I am trying to solve: I have a servo motor driving a spindle via a timing belt. The encoder with an index signal is attached to the motor shaft. The pulley on the motor has 32 teeth and the pulley on the spindle side has 22 teeth. I need to establish a zero location for the spindle based on zero of the motor. Essentially the spindle angle matches the motor angle once every 11 rotations of the spindle (180224 position counts). So, I need to calculate how far to move from the current position to bring the spindle to its zero reference.

CountsToSpindleRef = 180224-(CurrentPos-IntegerPart(CurrentPos/180224)* 180224)

Thank You,
Larry

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

Re: C program

Post by TomKerekes » Fri Jul 15, 2022 8:54 pm

Hi Larry,

I'm curious do you really need both to be at the same angle? In most cases one only cares about the Spindle so it would be at the same angle every 22/32*16384 = 11264 counts.
Regards,

Tom Kerekes
Dynomotion, Inc.

larryjamessmith
Posts: 22
Joined: Mon Dec 23, 2019 9:18 pm

Re: C program

Post by larryjamessmith » Fri Jul 15, 2022 9:32 pm

Tom,

You are probably correct and I may end up with that being adequate. However I am relying on a proximity edge detector to give me a rough reference on the spindle (slot at bottom of BT30 holder) and I want the option of re-zeroing the spindle with each tool change, knowing that the best reference (index on motor shaft) is being used. I could rely on the original reference established during initial homing but that would trust that the position accumulates no error due to spurious edges from the encoder on a long job. Also, I have not checked the numbers to see how large the position could get on a long job at this high resolution and if it could overrun a double variable.

I think I will take your suggestion and implement at modulo 11264 instead of modulo 180224 to begin with.

By the way, I enjoy working with your controller and love the personal touch you add in this forum. This is my second CNC router/mill designed around your hardware and built from the ground up and I will continue to work with Dynomotion.

Larry

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

Re: C program

Post by TomKerekes » Fri Jul 15, 2022 9:43 pm

Hi Larry,

Thanks you made my day.

I think it works out to 250+ years at 3000RPM to overflow the double's 52 bits of precision :)
Regards,

Tom Kerekes
Dynomotion, Inc.

larryjamessmith
Posts: 22
Joined: Mon Dec 23, 2019 9:18 pm

Re: C program

Post by larryjamessmith » Fri Jul 15, 2022 9:46 pm

I hope none of my jobs will take that long! :)

Post Reply