Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-23 Thread Sebastian Kuzminsky
On 09/23/2016 09:22 AM, Florian Rist wrote:
> Hi,
> thinks more or less work now, but I'd like to have LinuxCNC take care of
> homing and limits.
>
> Here's what I did:
>
> I disconnected the axis axis.3.motor-pos-cmd pin from the
> emcmot.03.pos-cmd signal and connected a pin of my new component. I set
> FERROR and MIN_FERROR to 999.
>
> Now I can control the position of axis 3 from my Python script and AXIS
> displays axis position. That's nice and work well.
>
> Now the only think that I'm missing is someone taking care of the travel
> limit of my axis. I have a homing switch and set-up homing and
> soft-limits for the axis, but as I'm not using AXIS to control the axis
> this does not have an effect any more.
>
> Is there away to get back the travel limiting in a easy way?

There's no easy way to home a joint without letting LinuxCNC's Motion 
component control it.

You can limit position, velocity, and acceleration by using the limit3 
component between your command signal and the joint actuator (stepgen or 
whatever):  http://linuxcnc.org/docs/2.7/html/man/man9/limit3.9.html


Maybe you could rig something up where Motion controls the joint while 
it's unhomed, and it switches to your control signal when it's homed?

I'm not sure if that would work, but it's probably work trying.

Try having axis.3.motor-pos-cmd and the output of your 
sensor-to-position component go into a mux2 component 
(http://linuxcnc.org/docs/2.7/html/man/man9/mux2.9.html).  The select 
pin would be netted to axis.3.homed, and the output would go to the 
limit3 input, and from limit3 to the stepgen command input.

This way, when the joint it unhomed it tracks Motion's homing commands, 
and when it finishes homing it goes to your sensor-to-position 
component's commanded position, all while obeying the limit3 
constraints, including during the switch-over from motion's homing to 
your sensor-to-position command.

If the joint unhomes (for example if it's marked VOLATILE_HOME and the 
joint controller loses power from an E-stop) then it will stop tracking 
your sensor-to-position component, go back to where Motion left it 
(probably near the home switch) while obeying the limit3 constraints, 
and be ready for you to re-home it.  Once you re-home it, it will go 
back to following your sensor-to-position component's commands.

If you try this, let us know if it works!  If you make a video we can 
make a showcase for the www.linuxcnc.org front page :-)


-- 
Sebastian Kuzminsky

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-23 Thread Florian Rist
Hi,
thinks more or less work now, but I'd like to have LinuxCNC take care of 
homing and limits.

Here's what I did:

I disconnected the axis axis.3.motor-pos-cmd pin from the 
emcmot.03.pos-cmd signal and connected a pin of my new component. I set 
FERROR and MIN_FERROR to 999.

Now I can control the position of axis 3 from my Python script and AXIS 
displays axis position. That's nice and work well.

Now the only think that I'm missing is someone taking care of the travel 
limit of my axis. I have a homing switch and set-up homing and 
soft-limits for the axis, but as I'm not using AXIS to control the axis 
this does not have an effect any more.

Is there away to get back the travel limiting in a easy way?

Thanks for you help.

See you
Flo

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Chris Morley




From: Florian Rist 
Sent: September 20, 2016 8:14 PM
To: Enhanced Machine Controller (EMC)
Subject: Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

Hi,
thank you all for you help.

> A pin created by a python userspace component can be linked to a signal
> with the "net" command, just like any other HAL pin.

I thought about that, but I could not find 'net' command.

Can this be done from the Python script without calling halcmd?


I just tried this and it worked very well:

h=hal.component("mycomp")
h.newpin("com-pos", hal.HAL_FLOAT, hal.HAL_IN)
h.ready()
msg=Popen('halcmd net emcmot.03.pos-cmd mycomp.com-pos', shell=True,
stdout=PIPE).stdout.read()

h['com-pos'] = newpos


you can make a signal name in python with:
hal.new_sig.(SIGNAME,hal.HAL_PIN_TYPE)

you can connect pin to signal in python with:
hal.connect(PINNAME,SIGNAME)

there are a couple other methods to check for component names and whether a pin 
has a writer.
It's in the source - not officially documented.
Pncconf uses these things - or did I mean.

Chris M

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users
Emc-users Info Page - 
SourceForge<https://lists.sourceforge.net/lists/listinfo/emc-users>
lists.sourceforge.net
This list is for users of the Enhanced Machine Controller (EMC). Topics include 
how to obtain, install, configure, and use EMC, as well as other general EMC 
related ...


--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Jeff Epler
You would place the "net" command in one of the .hal files that linuxcnc
executes when starting up.

Jeff

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Florian Rist
Hi,
thank you all for you help.

> A pin created by a python userspace component can be linked to a signal
> with the "net" command, just like any other HAL pin.

I thought about that, but I could not find 'net' command.

Can this be done from the Python script without calling halcmd?

I just tried this and it worked very well:

h=hal.component("mycomp")
h.newpin("com-pos", hal.HAL_FLOAT, hal.HAL_IN)
h.ready()
msg=Popen('halcmd net emcmot.03.pos-cmd mycomp.com-pos', shell=True, 
stdout=PIPE).stdout.read()

h['com-pos'] = newpos


It's fast and feels responsive. Nice. Real time is not a requirement.

However I have the feeling that that's not the nicest solution. I guess 
I should use the 'loadusr' hal coammnd in my .hal file to load the scrip 
and use the '-Wn mycom' parameter to wait for the creation of my 
component and than create the link between the signal and my pin in the 
.hal file.

See you
Florian

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Sebastian Kuzminsky
On 09/20/2016 08:36 AM, Florian Rist wrote:
>> http://linuxcnc.org/docs/2.7/html/hal/halmodule.html
>
> I know that documentation page. But I don't get it
>
> How to access an existing signal?

Your python program creates a pin for the sensor reading, and you link 
the pin to the signal in the usual way.  Probably the easiest way is to 
do it in the same hal file that starts your python program:

loadusr py-sensor-reader
net py-sensor-reader.value => sensor-value


-- 
Sebastian Kuzminsky

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Jeff Epler
A pin created by a python userspace component can be linked to a signal
with the "net" command, just like any other HAL pin.

The documentation shows that Python Userspace Components create pins:
http://linuxcnc.org/docs/2.7/html/hal/halmodule.html

.. but it does not explicitly state to "net" the pins to do useful
things.  Here is an example that shows that the output of a Python
component can be hooked to the input of a realtime component (abs):

halcmd: loadusr passthrough
halcmd: loadrt abs
halcmd: loadrt threads
halcmd: addf abs.0 thread1 
halcmd: start
halcmd: net v passthrough.out abs.0.in
halcmd: setp passthrough.in -3.14
halcmd: show pin
Component Pins:
Owner   Type  Dir Value  Name
12  float IN  -3.14  abs.0.in <== v
12  bit   OUT  TRUE  abs.0.is-negative
12  bit   OUT FALSE  abs.0.is-positive
12  float OUT  3.14  abs.0.out
12  bit   OUT  TRUE  abs.0.sign
12  s32   OUT   378  abs.0.time
 4  float IN  -3.14  passthrough.in
 4  float OUT -3.14  passthrough.out ==> v
16  s32   OUT   378  thread1.time

Jeff

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Sebastian Kuzminsky
On 09/20/2016 08:12 AM, Florian Rist wrote:
> Hi John,
> thanks for you message.
>
>> You can control with the python interface.
>> http://linuxcnc.org/docs/2.7/html/config/python-interface.html
>
> That refers to the LinuxCNC Python interface, but that does not give me
> access to HAL, right? I tried to implement my sensor following thing
> using MDI, so I send sommands like:
>
>c.mdi("G0 A{:f}".format(newpos))
>
> This does work in some way, but i require either to wait until each
> command is finished before the next commanded position is approached or
> to about the running command. This make it to slow and does not give
> smooth motions.

My guess is you won't get smoother motion by bypassing the G-code 
interpreter and going directly to HAL, but you can try.  Like the 
`linuxcnc` python module JT linked you to, there's also a hal module:

http://linuxcnc.org/docs/2.7/html/hal/halmodule.html

I think you'll get the smoothest results by getting rid of python (which 
is not realtime) and writing a realtime component instead.  This 
realtime component will read your sensor and put the value on a hal pin. 
  Then link that hal pin directly to joint.N.position-command or 
whatever is appropriate.


-- 
Sebastian Kuzminsky

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Florian Rist
Hi Sebastian

> My guess is you won't get smoother motion by bypassing the G-code
> interpreter and going directly to HAL, but you can try.

Well calling halcmd is allready much better than the MDI approach, and I 
guess using the Python interface and eliminating the system call would 
improve things further.


>  Like the
> `linuxcnc` python module JT linked you to, there's also a hal module:
> 
> http://linuxcnc.org/docs/2.7/html/hal/halmodule.html

I know that documentation page. But I don't get it

How to access an existing signal?


> I think you'll get the smoothest results by getting rid of python 
> (which
> is not realtime) and writing a realtime component instead.

Certainly. But this thing has to be simple and quick and it's moving 
slowly.

See you
Florian

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Florian Rist
Hi John,
thanks for you message.

> You can control with the python interface.
> http://linuxcnc.org/docs/2.7/html/config/python-interface.html

That refers to the LinuxCNC Python interface, but that does not give me 
access to HAL, right? I tried to implement my sensor following thing 
using MDI, so I send sommands like:

   c.mdi("G0 A{:f}".format(newpos))

This does work in some way, but i require either to wait until each 
command is finished before the next commanded position is approached or 
to about the running command. This make it to slow and does not give 
smooth motions.

See you
Florian

--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread John Thornton
You can control with the python interface.
http://linuxcnc.org/docs/2.7/html/config/python-interface.html
some examples
http://gnipsel.com/linuxcnc/gui/index.html

JT


On 9/20/2016 6:05 AM, Florian Rist wrote:
> Hi,
> I'm trying to control an axis position using an user space Python
> script, but I don't relay understand the Python hal library.
>
> So, I want to use Python to periodically set the command position of an
> axis (3 in my case) based on a sensor read out.
>
> To do so I disconnected axis.3.motor-pos-cmd from emcmot.03.pos-cmd by
> removing these lines from my .hal file:
>
> net emcmot.03.pos-cmd  <= axis.3.motor-pos-cmd
> net motor.03.pos-fb <= hpg.stepgen.03.position-fb
>
> I kept these:
>
> net emcmot.03.pos-cmd => hpg.stepgen.03.position-cmd
> net motor.03.pos-fb => axis.3.motor-pos-fb
>
>
> Now I manged to set emcmot.03.pos-cmd by calling halcmd from Python:
>
> msg = Popen('halcmd sets  emcmot.03.pos-cmd  {:f} '.format(newpos),
>   shell=True, stdout=PIPE).stdout.read()
>
> This works as expected and changes the command position, the axis starts
> to move to the new position.
>
> Now I'd like to do the same using the Python HAL interface and get rid
> of the shell command.
>
> I can create a new HAL component and a new pin but how can I access the
> existing signal? Any idea where I night be able to find an example?
>
> See you
> Florian
>
>
> --
> ___
> Emc-users mailing list
> Emc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/emc-users


--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


[Emc-users] Accessing a Signal using the Python HAL Interface?

2016-09-20 Thread Florian Rist
Hi,
I'm trying to control an axis position using an user space Python 
script, but I don't relay understand the Python hal library.

So, I want to use Python to periodically set the command position of an 
axis (3 in my case) based on a sensor read out.

To do so I disconnected axis.3.motor-pos-cmd from emcmot.03.pos-cmd by 
removing these lines from my .hal file:

   net emcmot.03.pos-cmd  <= axis.3.motor-pos-cmd
   net motor.03.pos-fb <= hpg.stepgen.03.position-fb

I kept these:

   net emcmot.03.pos-cmd => hpg.stepgen.03.position-cmd
   net motor.03.pos-fb => axis.3.motor-pos-fb


Now I manged to set emcmot.03.pos-cmd by calling halcmd from Python:

   msg = Popen('halcmd sets  emcmot.03.pos-cmd  {:f} '.format(newpos),
 shell=True, stdout=PIPE).stdout.read()

This works as expected and changes the command position, the axis starts 
to move to the new position.

Now I'd like to do the same using the Python HAL interface and get rid 
of the shell command.

I can create a new HAL component and a new pin but how can I access the 
existing signal? Any idea where I night be able to find an example?

See you
Florian


--
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users