How to invoke comp userspace modules in 0,1,2,3,0,1,2,3,... sequention.

More
09 Oct 2017 15:14 #100119 by Sylvester
Hello everybody,

I have problem with writing comp modules which are connected to another hal or comp module.

I have four simple comp modules. All of this have few inputs and bus type output, and are similar but not the same.
All the buses of modules are connected to another comp module which have input bus and output bus.
So, it looks like this:

-->input01 | COMPmoduleNo0 |
-->input02 | COMPmoduleNo0 | BUS_0output -->
-->input03 | COMPmoduleNo0 |

-->input11 | COMPmoduleNo1 |
-->input12 | COMPmoduleNo1 | BUS_1output --> .. |
-->input13 | COMPmoduleNo1 |.............................. |
............................................................................... | --> InputBUS_COMP_moduleX
-->input21 | COMPmoduleNo2 |.............................. |
-->input22 | COMPmoduleNo2 | BUS_2output --> .. |
-->input23 | COMPmoduleNo2 |

-->input31 | COMPmoduleNo3 |
-->input32 | COMPmoduleNo3 | BUS_3output -->
-->input33 | COMPmoduleNo3 |

All of comp modules are of userspace type.

Is there any posibility to work like multiplexer? When linuxcnc starts its invoke some modules. In my problem i want to
my module work as:
-first iteration of linuxcnc servo-thread loop: read inputs of comp module No0 and write its value thru BUS_0output to
input bus of component moduleX

-second iteration of linuxcnc servo-thread loop: read inputs of comp module No1 and write its value thru BUS_1output to
input bus of component moduleX

-third iteration of linuxcnc servo-thread loop: read inputs of comp module No2 and write its value thru BUS_2output to
input bus of component moduleX

-forth iteration of linuxcnc servo-thread loop: read inputs of comp module No3 and write its value thru BUS_3output to
input bus of component moduleX

-fifth iteration of linuxcnc servo-thread loop: read inputs of comp module No0 and write its value thru BUS_0output to
input bus of component moduleX

and so on... So it is iteration modulus 4.

Simply, i want have some order when data comes from COMPmodule inputs to input bus of comp moduleX.

In my hal module i loaded my comp modules:
loadusr -W COMPmoduleNo0
loadusr -W COMPmoduleNo1
loadusr -W COMPmoduleNo2
loadusr -W COMPmoduleNo3

loadusr -W moduleX


and i dont know what is next.
I don't know how to run in correct sequention 0,1,2,3,0,1,2,3...
I can use mux_generic to switch output bus to input bus but i don't know how to change mux select input in sequention (mod 4) /meybe use siggen or stepgen? /.
I can make some nets from Bus_0output to InputBUS_COMP_moduleX but i'm not sure if this is correct way.

Meybe is there any better solution?


P.S. Sorry for my very bad english.

Greatings,
Sylvester

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

More
09 Oct 2017 19:40 #100127 by bkt
somethings like these:

linuxcnc.org/docs/2.4/html/man/man9/mux2.9.html

there is for 4, 16 and generic.

giorgio

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

More
11 Oct 2017 00:00 #100187 by andypugh
For the amount of data you are transferring it might be better to create a shared-memory region for both halves of the component to use.
Look at streamer.c, streamer.h and streamer_usr.c here:
github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components
There can be more than one shmen_key, one for the HAL shared memory and one for a private segment.

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

More
11 Oct 2017 09:50 #100198 by andypugh
To answer the main question.
If it is a "userspace" module then it is not linked with the servo thread at all. Anything that you want to be tied to a realtime thread needs to be a realtime module.

If you can code your sequence as a realtime component then it gets easier, but that means writing it in C, no file-system access and no non-threadsafe calls to external libraries.

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

More
11 Oct 2017 21:22 - 11 Oct 2017 21:24 #100235 by Sylvester
Thank you for your reply.
I'm a bit closer to solve my problem. I made simple hal configuration with 1ms test thread and some nets. I supose that my simple comp's are working quite good becouse of 0,1,0,1,.. sequence (at this time for proof-of concept this sequence is OK, and i think i can modify my code to get 0,1,2,3,... sequence without big problem). Unfortunately i haven't a lot of time to test it as good as posible at this moment.

I wrote my components in C with "comp" preprocessor. I can make one of my components as realtime, but the second one must have been as userspace becouse of some ethernet UDP functions and some non RT headers.


I have next question, it is posible to make some "bunch of nets" in hal? For example i have 64 outputs (in some wirtual component, not real external port) and i want to connect it to 64 inputs of next component. So i have to make some wire bus with code:
net wire-out-to-in-0 output-component.0.out-0 input-component.0.in-0
net wire-out-to-in-1 output-component.0.out-1 input-component.0.in-1
net wire-out-to-in-2 output-component.0.out-2 input-component.0.in-2
...
...
net wire-out-to-in-63 output-component.0.out-63 input-component.0.in-63
It is posible to make some group assigment (for example similar to verilog code) in one line instead of 64 lines as:
net wire-out-to-in-[63:0] output-component.0.out-[63:0] input-component.0.in-[63:0]
or it is not posible?

At this time i'm out of internet, so i probably write next answer in few next days.

Greatings,
Sylvester
Last edit: 11 Oct 2017 21:24 by Sylvester. Reason: typo

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

More
11 Oct 2017 22:45 - 11 Oct 2017 22:49 #100241 by dgarrett
Programming constructs like loops, conditionals, and
computations can be implemented using haltcl files.

Ref:
linuxcnc.org/docs/2.7/html/hal/haltcl.html

Example:
[HAL]
HALFILE = one.hal
HALFILE = two.hal
HALFILE = tre.tcl
$ cat tre.tcl
for {set i 0} {$i < 64} {incr i} {
    net wire-out-to-in-$i output-component.0.out-$i input-component.0.in-$i

}
Last edit: 11 Oct 2017 22:49 by dgarrett.

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

Time to create page: 0.078 seconds
Powered by Kunena Forum