Halcompile - #include <unistd.h> not found

More
07 Oct 2016 15:13 #81349 by Henk
Hi

I hope someone can help me. Im new to writing custom components with Halcompile but i managed to get my tool turret on a lathe working.

Attempting to use usleep() function on compiling gives the following error. I have included unistd.h as in the example in the documentation.

Any help would be appreciated

Thanks
Attachments:

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

More
08 Oct 2016 07:50 - 08 Oct 2016 08:31 #81383 by gaston48
Hello,
Not in a real time environment, you must be
in a userspace environment.
Look better the documention and the example
Last edit: 08 Oct 2016 08:31 by gaston48.
The following user(s) said Thank You: Henk

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

More
09 Oct 2016 09:57 #81451 by Henk
Thanks
H

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

More
09 Oct 2016 21:37 #81482 by andypugh

tempting to use usleep() function on compiling gives the following error. I have included unistd.h as in the example in the documentation.


A realtime component must never sleep.

You have to handle pauses a different way.

Remember that your real-time code is called regularly every mS. It has to do things fast, then exit, or the whole PC locks up.

Normally you do this with a state machine. The code sets a flag to say "I am currently waiting" and exits. For the next few (hundred) iterations it will check something, not see the desired result, and exit again. Then when the condition is true it will carry on.

There is an example of a three-state system here:
github.com/LinuxCNC/linuxcnc/blob/af15a4...mot2/resolver.c#L360

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

More
10 Oct 2016 11:42 #81500 by Henk
Thanks Andypugh
The turret is working now

henk

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

More
10 Oct 2016 12:11 #81503 by gaston48
Hello henk,
Can you publish your file.comp
and hal instructions
for un exemple for me

thanks

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

More
10 Oct 2016 16:21 #81513 by Henk
Sure, but remember, it is still a work in progress!

It seems to work OK now but there are a couple of improvements....

The button signal is true, the turret declamps and rotates untill the button is released, then clamped at the next tool, but Axis is not updated with the new tool number... havnt figured out how to do that yet. It does give a message to remind me of that. If you issue a new M6 command it will set the correct tool.

there may (or probably will) be other bugs that i have not noticed yet.

Henk
Attachments:

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

More
13 Oct 2016 15:41 - 13 Oct 2016 18:13 #81612 by gaston48
Hello,
Under realtime, some instructions are not properly taken into account,
as loops. it is often necessary to adapt the code.
When the realtime is not essential, I think it is better to compile the component in userspace.
I did not understand everything syntax (I started in C) but the principle is to create
a global loop with the sleeps that is desired.
the component is compiled and installed with this instruction:
(close linuxcnc before)
sudo halcompile --install --userspace toolchanger.comp
And in the HAL file, the component is loaded by a single instruction
loadusr -W toolchanger

here is your suitable file. You need can be set a period for the global loop.

File Attachment:

File Name: toolchanger_comp.txt
File Size:5 KB
Attachments:
Last edit: 13 Oct 2016 18:13 by gaston48.

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

Time to create page: 0.070 seconds
Powered by Kunena Forum