[This is a precursor for the next installment in the 'How are the young turks 
going to break LinuxCNC as we know it' miniseries. I already touched upon how 
GUI support code can be morphed to support messaging besides shared memory 
mode, hopefully without bringing down the house.

To explain how HAL messaging can cover NML functionality as far as status 
reporting from the motion and iocontrol modules goes, one first needs to 
understand the current flow. This what I attempt here. Since it is quite 
complex, I separate the 'status quo' and 'how to do it with HAL messaging' 
aspects into separate mails. Even if you're not interested in the latter, the 
former does help to understand how linuxCNC currently operates.

I am excluding on purpose for now the important but mundane case of 'how are 
NML commands sent _to_ motion and iocontrol' because that is much simpler 
conceptually, and easily covered in the messaging scenario.]


---

Let's look at how things currently works - what is reported, by whom, and 
through which mechanism is it communicated.

What using code - UI's, interpreter, task etc - are interested in is a global 
picture of machine and task state; what is sometimes called the 'world model'. 
All that is held in the EMC_STAT [1] structure which is globally accessible to 
interested programs through NML. It contains several substructures, one for the 
task coordinator, one for motion, and one for iocontrol; some of them nested, 
i.e. containing other structures.

Do not get confused by the 'M' in NML - in this case it is better to view 
EMC_STAT as global shared memory, rather than a message; there's no copying and 
queuing going on here.


How do values in EMC_STAT get set? 
----------------------------------

Depending on the origin of the information, like so:

- for EMC_TASK_STAT, which reflects the state of the milltask task coordinator 
itself, this is done within milltask[11]. For instance, on an abort operation 
(like hitting escape), EMC_TASK_STAT is cleaned up in the emcTaskAbort() 
function[2] in milltask.

- for EMC_MOTION_STAT, reflecting motmod state, this happens in milltask in 
emcMotionUpdate() through a somewhat baroque operation (see note [3]).

- for EMC_IO_STAT, this happens in emcIoUpdate() [4].


How are values in EMC_STAT consumed by using programs, like UI's?
-----------------------------------------------------------------

This boils down to two steps: 
1. accessing the NML EMC_STAT message through the NML library
2. making the values in EMC_STAT available to the using code.

A good example for 2) is the Python linuxcnc module [5]. It fishes out values 
from EMC_STAT, and makes them available as Python attributes [6]. For instance, 
the "actual_postion" attribute is retrieved by accessing 
s->status.motion.traj.actualPosition [6] which is in the 
EMC_MOTION_STAT.EMC_TRAJ_STAT member structure. 


Wait, say again, how did that work?
-----------------------------------

Confusing? Sure. Let's follow a single value set by motion through the whole 
foodchain.

We use as a simple example the motion 'probe tripped' boolean, from the motion 
HAL pin 'probe-input' to the Python stat.probe_tripped attribute in, say, a GUI.

So we have:

- the probeTripped value is defined in  struct emcmot_status_t [7] (remember 
note [3] why it is there and not in EMC_MOTION_STAT).
- it is set in the motion/control.c by looking at the probe_input HAL pin.
- task finally gets around to look at struct emcmot_status_t, carries it over 
into EMC_TRAJ_STAT [9]
- when task is done with the copying, it makes the resulting EMC_STAT message 
visible to other parties.

- a UI needs to call the emcstatus poll() method periodically to fetch updated 
values from EMC_STAT[10]
- thereafter the current value of the probe pin is available as the 
linuxcnc.stat.probe_tripped value.

---

So, quite a journey for a single bit. Still counting hoops ;-?

This concludes the introduction needed before I lay out how this process will 
be subsumed in a NML-free zone by HAL messaging. Please bear with me, it will 
become simpler, not more complex.

- Michael


-------

[1] structure definitions - note these are nested structures, some containing 
arrays of other structures, like the EMC_AXIS_STAT array in EMC_MOTION_STAT :

EMC_STAT: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/nml_intf/emc_nml.hh;h=c0cc86600455cdb7b7b8d954655fe55e75038405;hb=refs/heads/v2.5_branch#l2011
EMC_MOTION_STAT: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/nml_intf/emc_nml.hh;h=c0cc86600455cdb7b7b8d954655fe55e75038405;hb=refs/heads/v2.5_branch#l1134
EMC_IO_STAT: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/nml_intf/emc_nml.hh;h=c0cc86600455cdb7b7b8d954655fe55e75038405;hb=refs/heads/v2.5_branch#l1942
EMC_TASK_STAT: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/nml_intf/emc_nml.hh;h=c0cc86600455cdb7b7b8d954655fe55e75038405;hb=refs/heads/v2.5_branch#l1386

[2] emcTaskAbort(): 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/task/emctask.cc;h=e84b63b0dfb92d2b73c770f4bd4985a62b5a7481;hb=refs/heads/v2.5_branch#l166

[3] emcMotionUpdate(): 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/task/taskintf.cc;h=110d46eb398e8217db61403671e2195087d9036b;hb=refs/heads/v2.5_branch#l1428

Since Motion is a kernel module, and NML messages wont work in-kernel due to 
being written in C++, some hoops were to be jumped: the interaction is 
two-step, motion and task interoperate through a shared memory segment, and 
motion writes to the shared memory segment using a C-defined struct 
emcmot_status_t defined here: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/motion/motion.h;h=d4055ebc1518ac92442823b27c182fd6f5329ce5;hb=refs/heads/v2.5_branch#l561
 . Note that many of the fields are identical in meaning between 
emcmot_status_t and EMC_MOTION_STAT. EmcMotionUpdate() contains rather boring 
code copying fields from emcmot_status_t to EMC_MOTION_STAT; the only reason 
being NML message definitions being kernel-incompatible.

[4]: emcIoUpdate(): 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/task/iotaskintf.cc;h=da9e434ca8a4e75eded01893bd675c4dc5996a86;hb=refs/heads/v2.5_branch#l448

here the case is a bit easier since iocontrol is a userland process and NML 
actually works as advertised between milltask and iocontrol.

[5]: Python linuxcnc module source: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/usr_intf/axis/extensions/emcmodule.cc;h=597e2786ff43eacdb703214b36de03dfe35bf52d;hb=refs/heads/v2.5_branch

[6]:http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/usr_intf/axis/extensions/emcmodule.cc;h=597e2786ff43eacdb703214b36de03dfe35bf52d;hb=refs/heads/v2.5_branch#l434

[7]: probeTripped declaration: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/motion/motion.h;h=d4055ebc1518ac92442823b27c182fd6f5329ce5;hb=refs/heads/v2.5_branch#l609
[8]: probeTripped set depending on probe_input: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/motion/control.c;h=f6e7ac7c44312c4cddbb57bafad1b5f0c8ae117f;hb=refs/heads/v2.5_branch#l354
[9]: emcmot_status_t:probeTripped (kernel compatible) copied over to 
EMC_TRAJ_STAT.probe_tripped (NML message, not kernel compatible): 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/task/taskintf.cc;h=110d46eb398e8217db61403671e2195087d9036b;hb=refs/heads/v2.5_branch#l1180
[10]: updating the local copy of EMC_STAT in the Python linuxcnc poll() method: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/usr_intf/axis/extensions/emcmodule.cc;h=597e2786ff43eacdb703214b36de03dfe35bf52d;hb=refs/heads/v2.5_branch#l279

[11]: emcTaskUpdate(): 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/emc/task/emctask.cc;h=e84b63b0dfb92d2b73c770f4bd4985a62b5a7481;hb=refs/heads/v2.5_branch#l616
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to