Mesa 5i25/6i25 my own component: how to begin?
I prepared the 5i25 firmware and discussed this with P. Wallace in this thread
www.linuxcnc.org/index.php/english/forum...ignment-on-mesa-5i25 .
It works so far and I can read out all pins (Encoder and GPIOs) as I need using halrun commands.
Now I want to move to HAL components as I want to implement my own realtime modules for the MESA card in order to use them in my application.
So suppose, I want to read out encoder velocity and postion in C.
But where to begin?
Shall I look at github.com/araisrobo/linuxcnc/blob/maste...a-hostmot2/encoder.c and then adopt it for my needs?
Or, maybe, this github.com/araisrobo/linuxcnc/blob/maste...components/sampler.c is a better choice for the beginning?
Yes, I know about the way over halcompile, but I do not get how I code the pin names known to me from the halrun show pin.
Maybe, it is because I did not see yet any example for pin HALNAME?
Thanks for you attention.
Please Log in or Create an account to join the conversation.
If you just want a printout of values to file, the sampler / halsampler method may be easier.
If you want to do stuff in real time, based upon the values in encoder.N.position and encoder.N.velocity, you need to interrogate the pins.
Whilst you can make hal calls to get a pin value, this involves getting and releasing the mutex each time, which is not ideal.
The easiest way, is just to create a component with float IN pins to receive the values and net them to the encoder pins, either via fresh signals, or use the existing signals
if they are already linked.
Then your pins will be updated in real time with the values in the encoder pins and you can do whatever you wish with the data.
Very basic skeleton
component test;
pin in float velocity;
pin in float position;
function _ ;
license "GPL2";
;;
FUNCTION(_)
{
// do stuff with position and velocity here
}
loadrt test
addf test.0 servo-thread
net vel encoder.0.velocity test.0.velocity
net pos encoder.0.position test.0.position
# assumes no existing connections
regards
Please Log in or Create an account to join the conversation.
I made a rather simple small programm to be run in userspace,
as I was not sure if I'd get problems with printing out float numbers in the kernel space:
component test;
option userspace yes;
pin in float velocity;
pin in float position;
//function _ ;
license "GPL2";
author "CPS";
;;
#include "rtapi.h"
#include <unistd.h>
void user_mainloop(void)
{
// do stuff with position and velocity here
usleep(500000);
FOR_ALL_INSTS() rtapi_print("Velocity=%f, Position= %f\n", velocity, position);
}
The following linuxcnc.org/docs/html/hal/comp.html#_co...side_the_source_tree
I tried:
$ sudo comp test.comp
Traceback (most recent call last):
File "/usr/bin/comp", line 1337, in <module>
main()
File "/usr/bin/comp", line 1306, in main
process(f, mode, outfile)
File "/usr/bin/comp", line 1180, in process
a, b = parse(filename)
File "/usr/bin/comp", line 411, in parse
a, b = f.split("\n;;\n", 1)
ValueError: need more than 1 value to unpack
Does this mean that my system (Debian Wheezy) misses some Python libs?
Please Log in or Create an account to join the conversation.
Does this mean that my system (Debian Wheezy) misses some Python libs?
Unlikely, they are comp parsing errors because it is not finding what it expects.
NB. Even though your comp was 'wrong' it still built for me, so there must be something else wrong with the actual file as opposed to what you pasted.
This compiles OK, so you can use it as a start template.
Note because it is a userspace comp, you use printf, not the realtime rtai_print() function
If you put your code within a loop, it allows you to initialise things first in the same function.
You can even tie the loop condition variable to SIGINT / SIGTERM so that the loop exits and the function closes on them.
component test;
option userspace yes;
pin in float velocity;
pin in float position;
license "GPL2";
author "CPS";
;;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void user_mainloop(void)
{
while(1)
{
usleep(250000);
FOR_ALL_INSTS()
{
printf("Velocity=%f, Position= %f\n", velocity, position);
}
}
}
Please Log in or Create an account to join the conversation.
I edited my comp source under Windows and tried to compile it under Linux,
forgot that python can be very sensitive about line feeds and so on.
Now I got rid of these parsing errors.
Please Log in or Create an account to join the conversation.
Your hint was right.
I edited my comp source under Windows and tried to compile it under Linux,
forgot that python can be very sensitive about line feeds and so on.
Now I got rid of these parsing errors.
I was just going to reinforce exactly that point, just had it come up on another forum.
Windows LF/CR pair the culprit
Please Log in or Create an account to join the conversation.
I made a rather simple small programm to be run in userspace,
as I was not sure if I'd get problems with printing out float numbers in the kernel space:
Good call. You can't print floats in kernel space. rtapi_print does the best it can, which is printing the mantissa and exponent in Hex.
Please Log in or Create an account to join the conversation.
as these two explain to me how to transfer data from the kernel space to the user space -- maybe, with some adoptions.
But I do not understand the options of sampler:
loadrt sampler depth=depth1[,depth2...] cfg=string1[,string2...]
What is the unit of depthN?
Suppose, I want to sample only encoder position and encoder velocity:
74 float OUT 0 hm2_5i25.0.encoder.00.position 0.000010 0
74 float OUT 0 hm2_5i25.0.encoder.00.velocity 0.000010 0
should I then write:
loadrt sampler depth=SomeDepthNumber cfg=FF
And then connect hm2_5i25.0.encoder.00.position and hm2_5i25.0.encoder.00.velocity to sampler.N.pin.M like that:
net encPosition sampler.0.pin.0 hm2_5i25.0.encoder.00.position
net encVelocity sampler.0.pin.1 hm2_5i25.0.encoder.00.velocity
Thanks in advance for your answers.
Please Log in or Create an account to join the conversation.
sampler will sample every time it is called (every servo-period for float data) but there is no way to know when halsampler will get round to seeing that data, so you need to tell t how many values to buffer.
You basically want the depth to be enough that sampler.N.overruns stays at zero, but any higher is a waste of shared memory.
Please Log in or Create an account to join the conversation.
And was this part correct:
And then connect hm2_5i25.0.encoder.00.position and hm2_5i25.0.encoder.00.velocity to sampler.N.pin.M like that:
?net encPosition sampler.0.pin.0 hm2_5i25.0.encoder.00.position net encVelocity sampler.0.pin.1 hm2_5i25.0.encoder.00.velocity
Please Log in or Create an account to join the conversation.