Richard,<br><br>Thanks for the prompt reply. I understood what you mean and I understood where my idea was wrong. There is however a question that still needs to be answered.<br><br>Imagine you have one domain that contains two types of pdo entries. You have two threads that each work on this same domain although on different sections of it. (The reason they are two in one domain is that (if I understood correctly) having more domains means more overhead in the network, so we are grouping entries that have the same data rate in one domain)<br>
<br>So, the threads go: calculate; exchange I/O; wait (therefore, get input; calculate; write output; wait)<br><br>Now, imagine this sequence:<br>1. Thread 1 finishes calculation and writes output<br>2. Slightly after, Thread 2 finishes calculation and writes output on the SAME domain<br>
3. After Thread1 wakes up, it receives the input<br>4. Slightly after, Thread 2 wakes up and wants to receive input from the SAME domain.<br><br>First question is, would this work with EtherLab? (So, does EtherLab itself understand that at step 2, the exchange data of this domain is in progress and would automatically ignore this step?)<br>
<br>I am assuming this won't work. Even if it does though, a solution such as the following makes more sense to me:<br><br>function: ethercat manager - write output<br> if domain data exchange in progress<br> ignore (because data is already being exchanged)<br>
else<br> domain_queue<br> master_send<br><br>function: ethercat manager - read input<br> if last write already read<br> ignore (and use the latest available data)<br> else if domain data exchange in progress<br>
ignore (if data exchange in progress, it means the other thread has issued data exchange recently)<br> else<br> master_receive<br> domain_process<br><br>Now each thread goes: ethercat manager - read input; calculate; ethercat manager - write output; wait<br>
<br>This way the previous scenario would be like this:<br>1. Thread 1 finishes calculation and writes output<br>
2. Slightly after, Thread 2 finishes calculation and write output is ignored by the ethercat manager<br>
3. After Thread1 wakes up, it receives the input<br>
4. Slightly after, Thread 2 wakes up and uses the same results<br><br>Now, however another problem arises. What if Thread 1's read is ignored because data is still being exchanged, and then while Thread 1 is performing "calculate", Thread 2 performs a successful read and changes the data, ruining Thread 1's work?<br>
<br>The second question is, regardless of the solution of the mentioned problem, how do you check "domain data exchange is in progress" to implement the ethercat manager functions in the first place? (That is, when you issue a write output, how can you be sure when the read input is issued, the data HAS actually finished exchanging?)<br>
<br>Thank you very much for your attention,<br>Shahbaz<br><br>P.S. The delay of one cycle is not a problem. That had been a misunderstanding on my side.<br><br>P.S.2. I have been considering separating the pdo entries in more domains so that different threads won't share domains. That however, would be the last resort. If it is possible to have two threads working with the same domain, I would be happier with that solution. If it is impossible, tell me and I'll simply make sure no two threads use data from the same domain.<br>
<br><div class="gmail_quote">On Fri, Oct 14, 2011 at 10:01 AM, Richard Hacker <span dir="ltr"><<a href="mailto:ha@igh-essen.com">ha@igh-essen.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
I am not sure why you want to go through all this trouble. Of coarse, if your<br>
calculation is so long that there is no time to exchange IO, you have trouble<br>
looming anyway!<br>
<br>
So what do you want to do with the data if you receive it in the same cycle<br>
instead of waiting till your next call? For me, there is no point of busily<br>
waiting till your packet arrives, instead of being relaxed and receiving the<br>
packet next cycle.<br>
<br>
The normal run of a control program is:<br>
calculate; exchange io; wait; calculate; exchange io; wait; etc.<br>
where exchange io means: write output and get new inputs. Master receive and<br>
domain process simply fetches and processes the data that was transmitted with<br>
master_send at the end of you pseudo code examples.<br>
<br>
Now, exchange io is done in the background by the network card. This means,<br>
that you could call exchange io right at the start of your cycle and<br>
subsequently calculate. In this case your calculation and exchange io runs in<br>
parallel. This is useful when your calculation is long and you have a lot of<br>
data to exchange, i.e.<br>
exchange io; calculate; wait; exchange io; calculate wait; etc.<br>
<br>
The drawback is that your propagation time from input change to output<br>
reaction is 2 cycles, instead of only 1. That is the price to pay if you have<br>
lots of data and a long calculation - there is no free lunch!!!<br>
<br>
I do not think that you have a problem. Draw your operations on a time line<br>
and convince yourself that once you are in in the loop, you have max 1 cycle<br>
delay from input to output. If that is too long for you, then ethercat is not<br>
your solution. Then you need direct IO like that of microcontrollers and the<br>
like.<br>
<br>
- Richard<br>
<div><div></div><div class="h5"><br>
On Thursday 13 October 2011 17:12:46 Shahbaz Yousefi wrote:<br>
> Hi,<br>
><br>
> I have been working with etherlab recently and got ethercat working up and<br>
> everything is fine.<br>
><br>
> There is a delay issue however that I'm concerned about. As seen in the<br>
> examples, the way you read from the network is like this (imagine you are<br>
> interested in reading sensor values):<br>
><br>
> while (running)<br>
> {<br>
> master receive<br>
> domain process<br>
><br>
> read data<br>
><br>
> domain queue<br>
> master send<br>
><br>
> rt wait period<br>
> }<br>
><br>
> in which case you assume that the task period is long enough to be sure<br>
> that the packet sent in the bottom of the loop has returned when the loop<br>
> starts again and so you can receive the data.<br>
><br>
> However, I was wondering if it is possible to, instead of taking an upper<br>
> bound of the time, simply check to see whether the data has arrived or not.<br>
> After some research, I got to this code:<br>
><br>
> while (running)<br>
> {<br>
> domain queue<br>
> master send<br>
><br>
> do<br>
> {<br>
> sleep a little<br>
><br>
> master receive<br>
> domain process<br>
><br>
> ecrt_domain_state(domain, &state);<br>
><br>
> } while (state.wc_state != EC_WC_COMPLETE && !timeout)<br>
><br>
> read data<br>
><br>
> rt wait period<br>
> }<br>
><br>
> This way, after sending the packet, you would read the data as soon as they<br>
> arrive.<br>
><br>
> The problem with this was that, besides the fact that early calls to<br>
> master_receive (or domain_process) generated a huge amount of warning about<br>
> working counter changing to 0/1 and back to 1/1 again, the kernel started<br>
> to at some point keep crashing.<br>
><br>
> I would like to know, how can I detect when the packet has arrived without<br>
> knowing an upper bound about it and wait blindly by that much?<br>
><br>
> Note: This is most useful for me for this reason:<br>
><br>
> I may have different threads requesting data from a domain which includes<br>
> different sensors. Each type of sensor produces data at a different rate<br>
> and I would like to read the data at different rates to. I don't want to<br>
> (and I don't think is even possible) to have different threads requesting<br>
> data from the same domain (because they may send the packet while the one<br>
> for the previous thread hasn't yet arrived). So what I want to is this:<br>
><br>
> ethercat coordinator:<br>
><br>
> domain_updating = no<br>
><br>
> send_request_for_domain<br>
> {<br>
> if (domain_updating == no)<br>
> {<br>
> domain_updating = yes<br>
> domain queue<br>
> master send<br>
> }<br>
> // else, do nothing, it is being updated!<br>
> }<br>
><br>
> receive_from_domain()<br>
> {<br>
> while (ecrt_domain_data_not_yet_received) // this is the function I need<br>
> wait<br>
> domain_updating = no<br>
> // data available<br>
> }<br>
><br>
> and then, each thread that wants something from the domain would look like<br>
> this:<br>
><br>
> thread:<br>
> send_request_for_domain<br>
> receive_from_domain<br>
> read data<br>
><br>
> This way, if two threads call send_request_for_domain at the same time,<br>
> only one of them would actually do the<br>
><br>
> domain queue<br>
> master send<br>
><br>
> and both of them use the result.<br>
><br>
> I would appreciate it if you could shed some light on this matter.<br>
> Shahbaz<br>
><br>
<br>
</div></div>Mit freundlichem Gruß<br>
<br>
Richard Hacker<br>
<br>
--<br>
------------------------------------------------------------------------<br>
<br>
Richard Hacker M.Sc.<br>
<a href="mailto:richard.hacker@igh-essen.com">richard.hacker@igh-essen.com</a><br>
Tel.: <a href="tel:%2B49%20201%20%2F%2036014-16" value="+492013601416">+49 201 / 36014-16</a><br>
<br>
Ingenieurgemeinschaft IgH<br>
Gesellschaft für Ingenieurleistungen mbH<br>
Heinz-Bäcker-Str. 34<br>
D-45356 Essen<br>
Amtsgericht Essen HRB 11500<br>
USt-Id.-Nr.: DE 174 626 722<br>
Geschäftsführung:<br>
- Dr.-Ing. S. Rotthäuser,<br>
- Dr.-Ing. T. Finke,<br>
- Dr.-Ing. W. Hagemeister<br>
Tel.: <a href="tel:%2B49%20201%20%2F%20360-14-0" value="+49201360140">+49 201 / 360-14-0</a><br>
<a href="http://www.igh-essen.com" target="_blank">http://www.igh-essen.com</a><br>
<br>
------------------------------------------------------------------------<br>
</blockquote></div><br>