c++ grab in position signal

More
04 Sep 2014 23:09 #50774 by bkt
Replied by bkt on topic c++ grab in position signal
Thank for your note but sudo comp --install retun this error....
error: implicit declaration of function ‘kill’

at least can you tell me in which folder I have to create the symlink of signal.h, stdio.h etc etc for LinuxCNC ..... at this point I'm not sure what I did ..... I think your correction need not be completed because I did not use the libraries signal.h and the other .... because of the mistakes that I listed above.

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

More
04 Sep 2014 23:38 #50776 by ArcEye
Replied by ArcEye on topic c++ grab in position signal
Hi

Your #includes are a swamp of alligators, there is every signal.h for every operating system in there and all your errors are redefinition errors, which are bound to happen.

My main problem is that I do not use Ubuntu 10.04 and do not have it installed anywhere
I have a copy backed up on my NAS so looked at that

As far as I am aware you just need to #include <sys/signal.h>, no symlinks or other includes required
This in fact calls <signal.h> in the parent dir which includes the definition of kill()

The bigger question is what exactly are you trying to achieve in the program?
I am still not clear what the overall end objective is

The use of threads, UNIX signals etc all seems a very convoluted way of trying to communicate between 2 apps, when perhaps there need only be one, that is rtai aware, ie a component.

regards
The following user(s) said Thank You: bkt

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

More
04 Sep 2014 23:51 - 04 Sep 2014 23:54 #50778 by bkt
Replied by bkt on topic c++ grab in position signal
what I try to do is to put on a new component of the LinuxCNC file test1.c.

Only that kill should be launched each time hal.h sends a false signal to motion.in-position ...... I'd like to get a better signal but I do not think there are others available separately motion.in-position or axis.N.in-position.

test1.c code
#include <stdio.h>    
#include <stdlib.h> 
#include <stdint.h>   
#include <string.h>   
#include <unistd.h>   
#include <fcntl.h>    
#include <errno.h>    
#include <signal.h>



int main(void)
{
    kill(17175, SIGUSR1);
    printf("\n signal send \n");
    return 0;
}

in any case, in previous post, all the various libraries are commented out (/ * ... * /) ... I know I make some noise in my tests but not so much. I'd use only one group at time. are many, because not knowing which way to turn I've tried some.

Thanks a lot
Last edit: 04 Sep 2014 23:54 by bkt.

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

More
05 Sep 2014 18:03 - 05 Sep 2014 18:27 #50801 by ArcEye
Replied by ArcEye on topic c++ grab in position signal
Hi

Your test program compiles and runs Ok on my machine so I have incorporated it.

The below component is based upon the shell of earlier ones.

It waits for machine.is-on, homing, and then motion.in-position being 0, which indicates a move happening.

Thereafter it kills the predefined signal whenever motion.in-position is 1, then sets a flag which only unsets once motion.in-position is 0, to prevent a cycle of continual kill() calls
when motion.in-position is 1, which after all is the normal state of the pin.

You may need to add an enable pin to it, to prevent premature kill() calls, if you do moves after homing and before your routine starts.

I have compiled it and tested it, by having it print to stderr every time a kill() call would be made.
component threadkill                  "This component waits for machine.in-position and kills a pre-defined thread process";

pin in bit commandfinished = 1        "signal last command completed - connect to motion.in-position";
pin in bit homed = 0                  "signal that machine is homed and ready for commands - connect to last axis to home - halui.joint.2.is-homed";
pin in bit machineon = 0              "signal to ensure machine is on - connect to halui.machine.is-on"; 
option singleton yes;               
option userspace yes;

author "ArcEye <arceyeATmgwareDOTcoDOTuk>";
license "GPL";
;;

#include <stdio.h>    /* Standard input/output definitions */
#include <stdlib.h> 
#include <stdint.h>   /* Standard types */
#include <string.h>   /* String function definitions */
#include <unistd.h>   /* UNIX standard function definitions */
#include <fcntl.h>    /* File control definitions */
#include <errno.h>    /* Error number definitions */
#include <signal.h>

int done = 0;

void adios(int sig) { done = 1; }


void user_mainloop(void)
{
int progress = 1;  // start at a state which requires commandfinished to be false before doing anything
int status_changed = 0;
   
signal(SIGINT, adios);
signal(SIGTERM, adios);
      
    while(!done)
        {
        usleep(250000);
        
        FOR_ALL_INSTS()  
            { 
            if(homed && machineon)
                {
                switch(progress)
                    {
                    case 0: // commandfinished will be true until a command has begun
                            // prevent cycling by having a status_changed flag which is set when it
                            // is not true, allowing another kill() to be sent
                            
                            if(commandfinished && status_changed)
                                {
                                kill(17175, SIGUSR1);
                                //fprintf(stderr, "\nKill() called\n");
                                status_changed = 0;
                                progress = 1;
                                }
                            break;                
                            
                    case 1: if(!commandfinished)
                                {
                                status_changed = 1;
                                progress = 0;
                                }
                        
                    default:
                            break;               
                
                    }
                }
            }
        }
    exit(0);
}


regards
Last edit: 05 Sep 2014 18:27 by ArcEye.
The following user(s) said Thank You: bkt

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

More
05 Sep 2014 21:01 - 05 Sep 2014 21:08 #50807 by bkt
Replied by bkt on topic c++ grab in position signal
you have been very kind. Thank you very much for the help you have given me.

Unfortunately, I had just given a look at the document "component generator" ... this penalized me ... on the other hand I was able to change deltakins.c limit3 entering in the code and the other two functions without problems. I thought then to be able to do everything without studying it carefully.

Thank you so much for all of the code example that you put ... it will be me and all the other very helpful.

I say this because I have always tried to compile with myname.c getting a lot of errors ..... but if I compile with myname.comp everything runs smoothly.

In addition definitavemte yesterday I had realized that the component of LinuxCNC are similar to kernel modules (or are they the same thing) then have a schedule different from the standard "C". In a file myname.c the kill signal whit normal schedule, not run in kernel module.

anyway ... now I installed the component threadkill ....
sudo comp --install /home/linuxcnc/thread.comp
sudo comp --compile /home/linuxcnc/thread.comp

output ...
k1@k1-desktop:~$ sudo comp --compile '/home/k1/linuxcnc/PROVA1/threadkill.comp' gcc -Os -g -I. -I/usr/realtime-2.6.32-122-rtai/include -I. -I/usr/realtime-2.6.32-122-rtai/include -D_FORTIFY_SOURCE=0 -mhard-float -DRTAI=3 -fno-fast-math -mieee-fp -fno-unsafe-math-optimizations -DRTAPI -D_GNU_SOURCE -Drealtime -D_FORTIFY_SOURCE=0 -D__MODULE__ -I/usr/include/linuxcnc -Wframe-larger-than=2560 -URTAPI -U__MODULE__ -DULAPI -Os  -o GFXTH_kill /tmp/tmp118qzS/GFXTH_kill.c -Wl,-rpath,/lib -L/lib -llinuxcnchal 

k1@k1-desktop:~$ sudo comp --install '/home/k1/linuxcnc/PROVA1/threadkill.comp' gcc -Os -g -I. -I/usr/realtime-2.6.32-122-rtai/include -I. -I/usr/realtime-2.6.32-122-rtai/include -D_FORTIFY_SOURCE=0 -mhard-float -DRTAI=3 -fno-fast-math -mieee-fp -fno-unsafe-math-optimizations -DRTAPI -D_GNU_SOURCE -Drealtime -D_FORTIFY_SOURCE=0 -D__MODULE__ -I/usr/include/linuxcnc -Wframe-larger-than=2560 -URTAPI -U__MODULE__ -DULAPI -Os  -o GFXTH_kill /tmp/tmpf_O0kT/GFXTH_kill.c -Wl,-rpath,/lib -L/lib -llinuxcnchal 
k1@k1-desktop:~$ 

is all ok??


I plugged in my hal file the row
loadrt threadkill
it says it can not find the component in usr /..../ rtai -....

in fact, on the directories linuxcnc/modules file threadkill.ko not exist.... what is wrong ??
Last edit: 05 Sep 2014 21:08 by bkt.

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

More
05 Sep 2014 21:31 - 05 Sep 2014 22:00 #50808 by ArcEye
Replied by ArcEye on topic c++ grab in position signal
Hi

you have been very kind. Thank you very much for the help you have given me.


You're welcome

I plugged in my hal file the row

loadrt threadkill

it says it can not find the component in usr /..../ rtai -....

in fact, on the directories linuxcnc/modules file threadkill.ko not exist.... what is wrong ??



The component is a userspace one, that is why it is able to use the normal UNIX signals etc.

sudo comp --install threadkill.comp

will install it in /usr/bin because it is a normal binary

Load it in halcmd with loadusr -W threadkill

regards
Last edit: 05 Sep 2014 22:00 by ArcEye.
The following user(s) said Thank You: bkt

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

More
05 Sep 2014 22:39 #50812 by bkt
Replied by bkt on topic c++ grab in position signal
I am sorry ... I not understand very well.. is all my mystake.. I was expecting to create a component that could be loaded with the myhal.hal but with file.comp is possible?
.... now I have started my threadkill in terminal
loadusr -W threadkill
... is that correct? then in my hal file how can I connect the pin to pin axis.3.is-homed component threadkill.ishomed ??

I was expecting some like this
net inpos motion.in-position =>  threadkill.killsignalstart
....
In this way (actualli threadkill.comp run with halcmd loadusr ....) how do I run it? I'm a newbe in this things.

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

More
05 Sep 2014 23:24 #50816 by ArcEye
Replied by ArcEye on topic c++ grab in position signal
Hi

From the start

sudo comp --install threadkill.comp

Then at the end of the .hal file of your config
loadusr -W threadkill

net sig1 threadkill.commandfinished <= motion.in-position
net sig2 threadkill.homed <= halui.joint.2.is-homed
net sig3 threadkill.machineon <= halui.machine.is-on

Then open your config, menu Machine > Hal configuration > Pins > threadkill and you will be able to see the pins changing

regards
The following user(s) said Thank You: bkt

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

More
06 Sep 2014 13:29 #50833 by bkt
Replied by bkt on topic c++ grab in position signal
many thanks ..... so in this way (xxx.comp) is possible open a pipe in "C" style to comunicato to my QT program. It's correct? Or for to do that is better use the standard linuxcnc ethernet comunication?

Thank a lot for your orrecyion :lol: :lol:

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

More
06 Sep 2014 15:06 #50835 by ArcEye
Replied by ArcEye on topic c++ grab in position signal
Hi

Because it is userspace, you can do any of the normal things, use pipes, socket servers etc to communicate inside a userspace .comp.
You could even just create a shared memory space and communicate by reads and writes to it

The restriction is the way you have to structure the program, to fit in with the fact that it runs within a loop.

To use the sockets / signal structure of Qt properly, you have to move outside comp and write the whole program yourself

That is why I used a progress level indicator and a switch() statement, more normally used in realtime kernel modules,
because it is a good way of waiting for an event or a condition to become true and just returning if it has not occured.

regards
The following user(s) said Thank You: bkt

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

Time to create page: 0.092 seconds
Powered by Kunena Forum