On Thursday, May 16, 2019 at 4:53:25 PM UTC+2, mngr wrote:
>
> Hi,
>
> I am trying to build userspace hal components, and I am trying to build
> them with python.
>
> I can find a lot of examples in the repository calling
> machinekit.rtapi.loadrt, but I have the vague idea of using
> machinekit.hal.loadusr
>
> Until now the only solution i have found is something structured like this
> #comp file
> from machinekit import hal
>
> comp=hal.component("name")
> comp.newpin("a", HAL.IN , HAL.BIT)
>
> while 1:
> comp["a"]=comp["b"]
> time.sleep(1)
>
>
>
> and loading
>
> hal.loadusr("comp")
>
>
>
> Is this the way it should be used?
>
I think you're mixing concepts.
a python userspace hal component is a component created in Python (in this
case) which exposes its pins in HAL. It's a userspace component. So you
initiate setting output pins and read input pins from within your python
code. So it's not executed in the same rigid RT time like the realtime
components. You have to take care that you create a loop to do so if you
plan to do it more than once.
>
> I know the hal.addf function, I would like to use it to load function on
> threads. Is it possible to export function from userspace components? I
> haven't found any way of exporting functions from python
>
You do not expose a userland function and add it to a HAL thread as with a
realtime component. You can't, do not want and do not need that. You
execute your code from python. It's running independent from the realtime
thread. You read/write your userspace component pins once, twice, many
times, or not at all. It is not related to the realtime HAL thread..
hal.addf("some_rt_component.funct", "servothread") is the same as using
`halcmd addf some_rt_component.funct servothread`
> I would like to write something like that
> #comp file
> from machinekit import hal
>
> comp=hal.component("name")
> #comp.newpin...
>
> def foo():
> comp["a"]=comp["b"]
>
> hal.export(foo)
>
>
> hal.loadusr("comp")
> hal.addf("foo","servo-thread")
>
>
hal.loadusr("something") is used for loading a userspace script/program
from HAL (you can load halscope for example in this way). In your situation
this has nothing to do with your python script functionality, other perhaps
than starting your python script from HAL, and your python script then
should take care of creating a userspace component with pins, looping and
whatnot.
>
>
> Can you please give me some advice?
>
hope it helped :)
> mngr
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
--
website: http://www.machinekit.io blog: http://blog.machinekit.io github:
https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups
"Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/machinekit.
To view this discussion on the web visit
https://groups.google.com/d/msgid/machinekit/3e56f8ae-e904-4bb3-987b-abc7b4390635%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.