how to get the data from control.c

More
09 Jul 2014 13:49 #48559 by tiffany
I tried send the data - joint_data by sockets


joint_data was used in control.c

it seemed that joint_data couldn't be used directly by

include "motion.h"
include "mot_priv.h"

how could I get it and use it in sockets.c??

thank you all!!!
Attachments:

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

More
09 Jul 2014 15:52 #48568 by ArcEye
Hi

joint_data is of a typedef struct hal_joint_t, which is local to the emcmotController.

It is purely local to that process, if you look at the objects produced by compilation, there is not even a control.o, it is already assimilated into another object.

Most of the data you want is available in HAL pins www.linuxcnc.org/docs/devel/html/man/man9/axis.9.html for example

Again it is a case of partial information can only illicit partial response.

If you share what it is you want to do, rather than asking how the method you have chosen can be made to work, without any overview of any of the other factors, you will get a better response and the answer may not be the one you thought of.

This is an open-source project, nothing you take from it can be claimed as copyright , so there is no need to be secretive about your own code, whilst happily taking whatever you want from the sources.

regards

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

More
09 Jul 2014 16:04 #48569 by tiffany
I just don't know how to describe my question rather than other reasons;
what I want to do is just want to send the position and velocity of joints to windows by sockets(DCP/IP); I need this data in windows
but I don't know how to send the HAL pin data to windows by sockets; HAL pin data how could be used as a varioble parameters in .cc file? I have no idea....
so I decided to send the data form source code, and it's failed.
If someone have any idea get the datas by HAL, I think that's best;

sorry I have so many stupid question, I just couldn't handle all this file.

Hi

joint_data is of a typedef struct hal_joint_t, which is local to the emcmotController.

It is purely local to that process, if you look at the objects produced by compilation, there is not even a control.o, it is already assimilated into another object.

Most of the data you want is available in HAL pins www.linuxcnc.org/docs/devel/html/man/man9/axis.9.html for example

Again it is a case of partial information can only illicit partial response.

If you share what it is you want to do, rather than asking how the method you have chosen can be made to work, without any overview of any of the other factors, you will get a better response and the answer may not be the one you thought of.

This is an open-source project, nothing you take from it can be claimed as copyright , so there is no need to be secretive about your own code, whilst happily taking whatever you want from the sources.

regards

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

More
09 Jul 2014 16:32 - 09 Jul 2014 16:45 #48570 by DaBit
You can do that with a userspace HAL component. A userspace component can create pins which you can connect in HAL to the corresponding axis.N pins, and has access to all (?) userspace stuff such as the socket API. I wrote my first HAL-component last week, and I found it pretty simple even for a not-so-experienced programmer like myself.

See the 'comp' documentation for some more information.

So basically you write a component:

component datatowindows;
option userspace;

pin in float xaxis_pos;
pin in float xaxis_vel;
..
void userinit(argc,argv) {
ParseOptions (argc, argv);
SetupTCPLink();
}
..
void user_mainloop(void) {
while(1) {

FOR_ALL_INSTS() {
AsssemblePacket (&ourpacket, xaxis_pos, xaxis_vel, ...);
TransmitOverSocket (&ourpacket);
}
}
}

Then, in HAL;

loadusr -W datatowindows --destination=mywindowsmachine.lan:12345
net xpos axis.0.joint-pos-cmd => datatowindows.0.xaxis-pos
net ypos axis.1.joint-pos-cmd => datatowindows.0.yaxis-pos
...
Last edit: 09 Jul 2014 16:45 by DaBit.

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

More
09 Jul 2014 16:55 #48571 by tiffany
waw,
it's seems very interesting;
but why we couldn't use the data axis.0.joint-pos-cmd directly?
and I still could not understant how do you connect the pin datatowindows.0.xaxis-pos with xaxis_pos??
could you tell me more details?

beat regards!

You can do that with a userspace HAL component. A userspace component can create pins which you can connect in HAL to the corresponding axis.N pins, and has access to all (?) userspace stuff such as the socket API. I wrote my first HAL-component last week, and I found it pretty simple even for a not-so-experienced programmer like myself.

See the 'comp' documentation for some more information.

So basically you write a component:

component datatowindows;
option userspace;

pin in float xaxis_pos;
pin in float xaxis_vel;
..
void userinit(argc,argv) {
ParseOptions (argc, argv);
SetupTCPLink();
}
..
void user_mainloop(void) {
while(1) {

FOR_ALL_INSTS() {
AsssemblePacket (&ourpacket, xaxis_pos, xaxis_vel, ...);
TransmitOverSocket (&ourpacket);
}
}
}

Then, in HAL;

loadusr -W datatowindows --destination=mywindowsmachine.lan:12345
net xpos axis.0.joint-pos-cmd => datatowindows.0.xaxis-pos
net ypos axis.1.joint-pos-cmd => datatowindows.0.yaxis-pos
...

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

More
09 Jul 2014 17:40 #48572 by DaBit

waw,
it's seems very interesting;
but why we couldn't use the data axis.0.joint-pos-cmd directly?


Why can't you send an Ethernet frame to the NIC directly? That's just the way the software was designed.
It already starts with the fact that the motion controller runs in kernel space as RT process, and from there you don't have access to regular userspace stuff such as the socket API.

I suppose that if you put enough effort in it you can directly use the internal struct members of LinuxCNC, but why would you if a simple and clean method that also keeps working when LinuxCNC development progresses already exists?

and I still could not understant how do you connect the pin datatowindows.0.xaxis-pos with xaxis_pos??
could you tell me more details?


Have a look at the various HAL tutorials.

In a nutshell: what HAL basically does is connecting 'black boxes' together with 'wires', just like you hook up your TV to your DVD player.
The 'black boxes' are the HAL components, the cables are 'nets'.

So we have a 'motion controller' box and a 'datatowindows' box. Now we must wire the two together with a cable. Just like you wire the DVD player's video out to the TV's video in.
So we stick a cable in the motioncontrollers 'joint 0 position out' socket, and plug it in the datatowindows 'joint 0 position in' socket. We do that 'cabling thing' like lthis:

net mycablename axis.0.joint-pos-cmd => datatowindows.0.xaxis-pos.


So, basically your job is to create a 'VCR' box that dumps it's data to Windows and hook it up in LinuxCNC. Much easier and cleaner than hacking into the motioncontroller

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

More
09 Jul 2014 18:01 - 09 Jul 2014 18:25 #48575 by tiffany
I‘will try the HAL component now, I write the HAL component like this?
but gserver.h and axis_pos so much error..........
#include "rtapi.h"		/* RTAPI realtime OS API */
#include "rtapi_app.h"		/* RTAPI realtime module decls */
#include "hal.h"		/* HAL public API decls */
#include <float.h>
#include <rtapi_math.h>
#include <rtapi_string.h>

#include "gserver.h"

component datatowindows;
option userspace;

pin in double axis_pos;
pin in double axis_vel;


static int ini_gserver_init(void)
{
  int sockfd;
   
  sockfd = 0;
  sockfd = init_gserver();
  if (sockfd != 1) {
      rtapi_print_msg(RTAPI_MSG_ERR,"Unable to open socket\n");
    return 0;
    }

  rtapi_print_msg(RTAPI_MSG_ERR,"ini_gserver_init is run\n");

  return 1;
}


void user_mainloop(void) {

	ini_gserver_init();  //initial sockets;

	while(1) {

	char szdata[128] = {0};
        int joint_num;

	int num_joints = EMCMOT_MAX_JOINTS;

		for (joint_num = 0; joint_num < num_joints; joint_num++) {

		generate_formatted_data_int(szdata, joint_num, axis_pos, axis_vel);// data package
		send_data(szdata);// send data

		}
	}

}

besides,
if I connect like this?
net Xpos <= axis.0.motor-pos-cmd
net Ypos <= axis.1.motor-pos-cmd

how could I use the signal: Ypos in halui.cc or orther userspace as a signal?

very thank for your patient......


waw,
it's seems very interesting;
but why we couldn't use the data axis.0.joint-pos-cmd directly?


Why can't you send an Ethernet frame to the NIC directly? That's just the way the software was designed.
It already starts with the fact that the motion controller runs in kernel space as RT process, and from there you don't have access to regular userspace stuff such as the socket API.

I suppose that if you put enough effort in it you can directly use the internal struct members of LinuxCNC, but why would you if a simple and clean method that also keeps working when LinuxCNC development progresses already exists?

and I still could not understant how do you connect the pin datatowindows.0.xaxis-pos with xaxis_pos??
could you tell me more details?


Have a look at the various HAL tutorials.

In a nutshell: what HAL basically does is connecting 'black boxes' together with 'wires', just like you hook up your TV to your DVD player.
The 'black boxes' are the HAL components, the cables are 'nets'.

So we have a 'motion controller' box and a 'datatowindows' box. Now we must wire the two together with a cable. Just like you wire the DVD player's video out to the TV's video in.
So we stick a cable in the motioncontrollers 'joint 0 position out' socket, and plug it in the datatowindows 'joint 0 position in' socket. We do that 'cabling thing' like lthis:

net mycablename axis.0.joint-pos-cmd => datatowindows.0.xaxis-pos.


So, basically your job is to create a 'VCR' box that dumps it's data to Windows and hook it up in LinuxCNC. Much easier and cleaner than hacking into the motioncontroller

Last edit: 09 Jul 2014 18:25 by tiffany.

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

More
09 Jul 2014 18:30 #48576 by DaBit
Read the 'comp' documentation first, and have a look at the existing HAL component sources in the LinuxCNC source tree. That will answer a lot of questions.

Also, you might be able to get away using 'halsampler'/'sampler' and pipe it's output to NetCat. If that works for you there is no need to write any C code at all.

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

More
09 Jul 2014 19:00 - 09 Jul 2014 19:00 #48577 by tiffany
no..
for my work,

I must use the position and velocity of joints in c file;

so , any methods could help me get the data?

the data in HAL, I still could use it in C file?

best regards!

Read the 'comp' documentation first, and have a look at the existing HAL component sources in the LinuxCNC source tree. That will answer a lot of questions.

Also, you might be able to get away using 'halsampler'/'sampler' and pipe it's output to NetCat. If that works for you there is no need to write any C code at all.

Last edit: 09 Jul 2014 19:00 by tiffany.

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

More
09 Jul 2014 19:16 #48579 by ArcEye

I must use the position and velocity of joints in c file;

so , any methods could help me get the data?

the data in HAL, I still could use it in C file?


I see DaBit has given you some ideas.

A component IS a C file, it is just written within a macro for ease of use, this is expanded to give the HAL aware code required, without the user needing to specifically write it.

You just need to create the pins to receive the data you want and connect them in a hal file to the pins which carry the data within linuxcnc.
Just as DaBit showed you net signalname yourcomponent.yourpinname <= axis.N.whateverpinyouarewanting

Then your component can disseminate this info however you want.

As he says this needs to be userpace if you are going to be using sockets, serial ports etc etc with the existing code methods available.

There is a proper way to get pin values programmatically, but this relies upon getting and releasing the rtapi_mutex, which limits it to realtime components and is not something you want to be doing repeatedly.

regards

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

Time to create page: 0.204 seconds
Powered by Kunena Forum