c++ grab in position signal
I, in the meantime, I continued on my way .... in my QT program I have already a TCP socket comunication ... I make a new one (client side) in my component. Than I can have a string of x, y, a coordinate from my QTopencv program when I ask it.
I have mix your old suggested code ( for send kill signal) with this one
component GFXTHkill "This component waits for machine.in-position and kills a pre-defined thread process";
pin in float sign1 = 0 "signal last command completed - connect to axis.N.joint-pos-cmd";
pin in float sign2 = 0 "signal last command completed - connect to axis.N.joint-pos-fb";
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";
pin in bit inposition = 0 "signal motion.in-position";
pin out bit kontrol = 0;
pin out float kont = 0;
option singleton yes;
option userspace yes;
author "GLX - k-1 - gfx";
license "GPL";
;;
#include <stdio.h> /* Standard ...... definitions */
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <netdb.h>
int done = 0;
//int ciclo = 0;
int numero = 100000;
int pid = -1;
int lancio = 0;
int lavoro = 0;
int control1 = 0;
float quota1 = 0;
float quota2 = 0;
//char buff[500]; /* dati di invio e ricezione */
int pass = 0;
//char *bluf = "";
//char riga[80];
void connection()
{
FILE *stream, *fopen();
char buff2[500]; /* dati di invio e ricezione */
int pass = 0;
char *bluf = "";
char *separ = ", ";
char *X = "";
char *Y = "";
char *A = "";
char *parola[90];
char *cp;
char riga[90];
char comandi[90];
char cX[] = " X";
char cY[] = " Y";
char cZ[] = " Z-800'";
char cA[] = " A";
char TA[] = " ' ";
char v100[] = "axis-remote --mdi 'G94 G21 G90 G61 G1 F160000 ";
int i = 0;
int e = 0;
int sda;
struct sockaddr_in server_addr;
char buff[500];
struct hostent *hp;
hp = gethostbyname("169.254.6.211");
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(51040);
server_addr.sin_addr.s_addr = ((struct in_addr*)(hp->h_addr)) -> s_addr;
if((sda = socket(AF_INET, SOCK_STREAM, 0)) < 0)
usleep(10000);
if(connect(sda, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0)
{
pass = 1;
}
usleep(10000);
if (pass == 0)
{
send(sda, "client send", strlen("client send"), 0);
recv(sda, buff, sizeof(buff), 0);
usleep(10000);
bluf = buff;
}
close(sd);
if (bluf != NULL)
{
cp = strtok(bluf, separ);
while (cp != NULL)
{
parola[i] = cp;
cp = strtok(NULL, separ);
i = i + 1;
}
X = parola[0];
Y = parola[1];
A = parola[2];
strcat(riga, v100);
strcat(riga, cX);
strcat(riga, X);
strcat(riga, cY);
strcat(riga, Y);
strcat(riga, cZ);
//strcat(riga, cA);
//strcat(riga, A);
//strcat(riga, TA);
stream = fopen("/home/k1/linuxcnc/P1/0.ngc", "w");
usleep(10000);
fprintf(stream, "%s\n", riga);
usleep(10000);
fflush(stream);
usleep(10000);
fclose(stream);
usleep(10000);
system(riga);
}
strcpy(buff, "");
bluf = "";
return;
}
//void adios(int sig) { done = 1; }
.....
.....
at the beginning I had some problems because it does not put the breaks suitable for all operations (connection and transformations).
But now I can compose strings --mdi directly in file.comp .... but you can write entire sub .ngc in very small time.
but certainly in the future I'm going to use and modify the last code you sent me. Thanks for your tips.
Please Log in or Create an account to join the conversation.
I have just been adding NML access to the previous Qt component, but if you are going to get your position from HAL pins without going into emcStatus->motion.xxxx, that makes this a lot easier.
But now I can compose strings --mdi directly in file.comp .... but you can write entire sub .ngc in very small time.
I think you will find the best way has to be to send the mdi commands from the component, then you can dispense with signalling 'in-position' back to your program and just use the TcpSocket to communicate commands and updates.
You will need to devise a protocol between server and socket, I just used ACK to start and after each command and NAK when commands had finished.
Sending newline terminated strings is the easiest way to use the Qt tcpsocket libs, because you can use getLine() which recognises the '\n' char as the end as the command delimiter and you don't have to go into packets etc.
Hopefully when you get your head around accessing HAL from a Qt component you will make short work of it
Keep us updated
regards
Please Log in or Create an account to join the conversation.
Today situation of my work:
I created with the tips of ArkEye, a component(mycomponent) that have a function that open a tcp connection, bring a string from another PC that has a QTServer. The string is a x,y position of object captured via cam. My component convert the string in double and rewrite a soubroutine with new x,y, position. Mycomponent with certain conditions of logic inputs and outputs, put in run the soubroutine with a mycomponent.signal connected to halui.mdi-command-xx in the myhal file. It work fine, but I'm still not satisfied.
Control linuxcnc from QT is the next step of my work, but now I am looking for smoother operation .... today the subroutine start and stop is ok (no delay or other strange situations) but when the gcode start it start like part as the beginning of a new trajectory.
I would rather that everything was working as an infinite loop. Whit gcode, I think is impossible, so I try a new solution.
My first idea is write a new comp that calculate the tajectory .... or a comp that comunicate with calculation.c that he does the same job. But I don't know this world .... you can get a hint on how to make a suggestion on what to study or to do so ?
or are there other solutions ?
Please Log in or Create an account to join the conversation.
or are there other solutions ?
Without knowing what you are trying to do in detail, I think I would be trying to write a userspace HAL component that output target positions on HAL pins, and then use the built in accel and velocity limits in stepgen to handle the motion planning (or, possibly, use limit3)
I think that a significant complication here with your setup would be the non-trivial kinematics. The only way to make what I described work would be to move the kins into the module.
So, perhaps the solution does need to use G-code and the motion planner.
However, if the machine vision is running in a HAL component, then the G-code can see the pins. your G-code be as simple as
O100 while 1
G0 X #<_hal[mycomponent.x]> Y #<_hal[mycomonent.y]>
O100 endwhile
You would want to turn off G-code preview, or the system will lock up with the infinite loop.
Please Log in or Create an account to join the conversation.
I didn't consider this thing ..... thanks ..... but turn off gcode preview without turn off axis gui is possible? I can simply modify axis GUI code for to do this?G0 X #<_hal[mycomponent.x]> Y #<_hal[mycomonent.y]>
In my modified kins I have already limit3 in kinematics code ...... and work fine.
while #<_half[mycomponent.onoffwilecicle]>
do something
endwhile
is possible choice ..... obviously for gcode preview is the same.
Please Log in or Create an account to join the conversation.
If you wrap your gcode in the appropriate comments, you can disable preview.
I don't think it affects the plot, just does not draw the preview of the anticipated plot, so saves quite a bit of openGL calling and speeds things up
linuxcnc.org/docs/html/gui/axis.html#_axis_preview_control
regards
Please Log in or Create an account to join the conversation.
I try to use exactly this code:
while #<_half[mycomponent.onoffwilecicle]>
do something
endwhile
but I have an error return messages ... "not inizialized parameters #<_half[mycomponent.onoffwilecicle]>" ... or somethings like this ..... I don't find doc for this situation ..... I read that to use the parameters must be initialized in the gcode , but also by doing this:
#51 = [#<_half[mycomponent.onoffwilecicle]>]
while [#51 EQ 1]
I get the same error
Please Log in or Create an account to join the conversation.
I try to use exactly this code:
while #<_half[mycomponent.onoffwilecicle]>
do something
endwhile
but I have an error return messages ... "not inizialized parameters #<_half[mycomponent.onoffwilecicle]>" ...
If that is exactly what you are entering it is wrong
Should be
#<_hal[name.of.component.pin]>
regards
Please Log in or Create an account to join the conversation.
but I have an error return messages ... "not inizialized parameters #<_half[mycomponent.onoffwilecicle]>" ... or somethings like this
I don't know how to deal with this, because I have never seen it.
To get yourself making progress again it is probably easiest to link to the G-code "analog inputs" from your new component and use M66 to read the values.
Please Log in or Create an account to join the conversation.
#<_hal[mycomponent.kstop]> <----- Gcode
...
...
component mycomponent <-----in mycomponent.comp
pin out float kstop = 0; <----I try pin out bit kstop too with the same error
...other pin
;;
...mycode...
in hal file .... nothing about this pin out
for precision the error is:
parameter named #<_hal[mycomponent.kstop]> not defined
Please Log in or Create an account to join the conversation.