Encoder velocities and index signal reading
21 Sep 2019 19:59 #145784
by rodw
Replied by rodw on topic Encoder velocities and index signal reading
If that does not fix, it is time to add a debug pin for destination and observe what is going on in halscope
pin in unsigned repeat_multiple;
pin in float repeat_length;
pin in float event_pos;
/**
* Output pin
*/
pin out bit event_trigger;
pin out float dbg_dest;
function _;
license "GPL";
;;
FUNCTION(_)
{
double destination = (double)repeat_multiple * repeat_length + event_pos;
event_trigger = (current_pos >= destination);
dbg_dest = destination;
}
Please Log in or Create an account to join the conversation.
21 Sep 2019 20:03 - 25 Sep 2019 23:04 #145787
by andypugh
It's always worth checking that a given C function exists in rtapi_math.h
github.com/LinuxCNC/linuxcnc/blob/0f91c5...c/rtapi/rtapi_math.h
These are the only maths functions that you can safely use in realtime code.
Replied by andypugh on topic Encoder velocities and index signal reading
you can just use the fmod(a,b) function to calculate the modulus of two floating point numbers!
It's always worth checking that a given C function exists in rtapi_math.h
github.com/LinuxCNC/linuxcnc/blob/0f91c5...c/rtapi/rtapi_math.h
These are the only maths functions that you can safely use in realtime code.
Last edit: 25 Sep 2019 23:04 by andypugh.
Please Log in or Create an account to join the conversation.
22 Sep 2019 19:54 #145886
by blazini36
Thanks, I'll run that by my friend. He's written me several components for various things, it does compile and load in hal but I haven't bothered testing it yet because I'd like to make it a "one size fits all" component that will allow me to get rid of the hal logic file I use for the other hardware case. It's severely bloated by off the shelf component limitations.
One thing I'm curious about is the time aspect of RT components. Is this handled the same way any other compiled code is, or is there some rtapi consideration? My thought is that a typical time calculation may work differently when considering the RT thread the code is running in, or does halcomp just take care of this internally?
Replied by blazini36 on topic Encoder velocities and index signal reading
I'm not sure if this will help. Try
double destination = (double)repeat_multiple * repeat_length + event_pos;
C is a typed language so it is not usually valid to mix types (unsigned and double) in a calculation so you need to use a cast to explicitly tell C to convert that number to a double before using it.
EDIT: So the code will compile but I would expect to generate a compiler warning and one should always treat warnings as if it was an error if you are programming defensively.
Thanks, I'll run that by my friend. He's written me several components for various things, it does compile and load in hal but I haven't bothered testing it yet because I'd like to make it a "one size fits all" component that will allow me to get rid of the hal logic file I use for the other hardware case. It's severely bloated by off the shelf component limitations.
One thing I'm curious about is the time aspect of RT components. Is this handled the same way any other compiled code is, or is there some rtapi consideration? My thought is that a typical time calculation may work differently when considering the RT thread the code is running in, or does halcomp just take care of this internally?
Please Log in or Create an account to join the conversation.
23 Sep 2019 01:25 #145900
by rodw
Think of the Servo thread being an interrupt service routine (ISR) for a Timer interrupt that fires 1000 times per second. Every Hal component is loaded in a chain and all must execute inside that time period. Bad things will happen if it overruns.There are other system interrupts that depend on this so if you hang or have an endless loop in an ISR, it won't be pretty, even down to the hardware level. Thats why ISRs and HAL components, need to be short, sharp and sweet. Its unlikely they will run early or late.
In every hal component there are two system variables Period (nanoseconds) and fperiod (seconds) that give you the precise period timing invocation per servo thread cycle.
Replied by rodw on topic Encoder velocities and index signal reading
One thing I'm curious about is the time aspect of RT components. Is this handled the same way any other compiled code is, or is there some rtapi consideration? My thought is that a typical time calculation may work differently when considering the RT thread the code is running in, or does halcomp just take care of this internally?
Think of the Servo thread being an interrupt service routine (ISR) for a Timer interrupt that fires 1000 times per second. Every Hal component is loaded in a chain and all must execute inside that time period. Bad things will happen if it overruns.There are other system interrupts that depend on this so if you hang or have an endless loop in an ISR, it won't be pretty, even down to the hardware level. Thats why ISRs and HAL components, need to be short, sharp and sweet. Its unlikely they will run early or late.
In every hal component there are two system variables Period (nanoseconds) and fperiod (seconds) that give you the precise period timing invocation per servo thread cycle.
Please Log in or Create an account to join the conversation.
- Mike_Eitel
- Offline
- Platinum Member
Less
More
- Posts: 1150
- Thank you received: 184
28 Sep 2019 07:50 #146472
by Mike_Eitel
Replied by Mike_Eitel on topic Encoder velocities and index signal reading
Sorry blazini36 if I chime in.
I would advise you to stick with an index on the real hw. I know what I'm talking about as I was the main brain of a digital printing on cd's process around 2001.
eitel.ch/job/digitran/index.html
In case of missing a puls you will have a drift that might ruin your complete batch.
M5c
Mike
I would advise you to stick with an index on the real hw. I know what I'm talking about as I was the main brain of a digital printing on cd's process around 2001.
eitel.ch/job/digitran/index.html
In case of missing a puls you will have a drift that might ruin your complete batch.
M5c
Mike
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19209
- Thank you received: 6438
28 Sep 2019 08:21 #146475
by tommylight
Replied by tommylight on topic Encoder velocities and index signal reading
@mike,
That was quite a chalenge, very nice work.
At that time i was doing the other part of that job, the CD copy machines.
Regards,
Tom.
That was quite a chalenge, very nice work.
At that time i was doing the other part of that job, the CD copy machines.
Regards,
Tom.
Please Log in or Create an account to join the conversation.
- Mike_Eitel
- Offline
- Platinum Member
Less
More
- Posts: 1150
- Thank you received: 184
28 Sep 2019 08:32 #146478
by Mike_Eitel
Replied by Mike_Eitel on topic Encoder velocities and index signal reading
@Tom
Yes fascinating job, but lost 5 years of good looking in 2...
Much calmer today. Mechantronic only as hobby.
But sometimes is miss those days nevertheless...
Mike
Yes fascinating job, but lost 5 years of good looking in 2...
Much calmer today. Mechantronic only as hobby.
But sometimes is miss those days nevertheless...
Mike
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19209
- Thank you received: 6438
28 Sep 2019 09:18 #146481
by tommylight
Replied by tommylight on topic Encoder velocities and index signal reading
Oh hell, i'm 49 and i still enjoy chalenges, a lot.
Please Log in or Create an account to join the conversation.
Time to create page: 0.076 seconds