Newbie rttlua question: How to print the last data from a port?

With the old deployer, we are in the habit of often manually checking
if sensors are returning reasonable values by looking at the last data
sent on their ports.

How do I do this in rttlua? I have lua completion installed, but that
didn't get me past calling componentName:getPort("portName").

Newbie rttlua question: How to print the last data from a port?

Hi Andrew,

On Mi, Okt 23, 2013 at 05:32:19 +0200, Andrew Wagner wrote:
>With the old deployer, we are in the habit of often manually checking
>if sensors are returning reasonable values by looking at the last data
>sent on their ports.
>
>How do I do this in rttlua? I have lua completion installed, but that
>didn't get me past calling componentName:getPort("portName").

After getting a reference to the port

p1 = comp:getPort("name")

you can call

lua>print(p1:read())

or in the short form

lua>=p1:read()

which will return two values: FlowStatus (as a string) and the last
data.

If speed/real-time safety matters, then you can pass an out-arg to
'read'. In that case only the FlowStatus string is returned.

HTH!

Best regards
Markus

Newbie rttlua question: How to print the last data from a port?

On Wed, Oct 23, 2013 at 8:25 PM, Markus Klotzbuecher
<markus [dot] klotzbuecher [..] ...> wrote:
> After getting a reference to the port
>
> p1 = comp:getPort("name")
>
> you can call
>
> lua>print(p1:read())
>
> or in the short form
>
> lua>=p1:read()
>
> which will return two values: FlowStatus (as a string) and the last
> data.

The stat() syntax is working for me:

> masterTimer:stat()
cameraClock (unknown_t) = ?
imuClock (unknown_t) = ?
controlsPlaybackClock (unknown_t) = ?
imuCameraRatio (int) = 40
deltaIn (double) = NoData
deltaOut (double) = 0

but I can't seem to read from the port:

> pp = masterTimer:getPort("imuCameraRatio")
> pp:read()
stdin:1: attempt to call method 'read' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: ?
> =pp:read()
stdin:1: attempt to call method 'read' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: ?

Any ideas?

Newbie rttlua question: How to print the last data from a port?

On Do, Nov 28, 2013 at 03:07:39 +0100, Andrew Wagner wrote:
>On Wed, Oct 23, 2013 at 8:25 PM, Markus Klotzbuecher
><markus [dot] klotzbuecher [..] ...> wrote:
>> After getting a reference to the port
>>
>> p1 = comp:getPort("name")
>>
>> you can call
>>
>> lua>print(p1:read())
>>
>> or in the short form
>>
>> lua>=p1:read()
>>
>> which will return two values: FlowStatus (as a string) and the last
>> data.
>
>The stat() syntax is working for me:
>
>> masterTimer:stat()
>cameraClock (unknown_t) = ?
>imuClock (unknown_t) = ?
>controlsPlaybackClock (unknown_t) = ?
>imuCameraRatio (int) = 40
>deltaIn (double) = NoData
>deltaOut (double) = 0
>
>but I can't seem to read from the port:
>
>> pp = masterTimer:getPort("imuCameraRatio")
>> pp:read()
>stdin:1: attempt to call method 'read' (a nil value)
>stack traceback:
> stdin:1: in main chunk
> [C]: ?
>> =pp:read()
>stdin:1: attempt to call method 'read' (a nil value)
>stack traceback:
> stdin:1: in main chunk
> [C]: ?
>
>Any ideas?

You can't read a write port. But you can get at it's latest value by
means of the TaskContext service interface:

>=taskcontext:provides("port-name"):last()

Best regards
Markus

Newbie rttlua question: How to print the last data from a port?

Ah yes, that is the one I was looking for. Thanks Markus!

time for another wrapper...

On Thu, Nov 28, 2013 at 3:16 PM, Markus Klotzbuecher
<markus [dot] klotzbuecher [..] ...> wrote:
> On Do, Nov 28, 2013 at 03:07:39 +0100, Andrew Wagner wrote:
>>On Wed, Oct 23, 2013 at 8:25 PM, Markus Klotzbuecher
>><markus [dot] klotzbuecher [..] ...> wrote:
>>> After getting a reference to the port
>>>
>>> p1 = comp:getPort("name")
>>>
>>> you can call
>>>
>>> lua>print(p1:read())
>>>
>>> or in the short form
>>>
>>> lua>=p1:read()
>>>
>>> which will return two values: FlowStatus (as a string) and the last
>>> data.
>>
>>The stat() syntax is working for me:
>>
>>> masterTimer:stat()
>>cameraClock (unknown_t) = ?
>>imuClock (unknown_t) = ?
>>controlsPlaybackClock (unknown_t) = ?
>>imuCameraRatio (int) = 40
>>deltaIn (double) = NoData
>>deltaOut (double) = 0
>>
>>but I can't seem to read from the port:
>>
>>> pp = masterTimer:getPort("imuCameraRatio")
>>> pp:read()
>>stdin:1: attempt to call method 'read' (a nil value)
>>stack traceback:
>> stdin:1: in main chunk
>> [C]: ?
>>> =pp:read()
>>stdin:1: attempt to call method 'read' (a nil value)
>>stack traceback:
>> stdin:1: in main chunk
>> [C]: ?
>>
>>Any ideas?
>
> You can't read a write port. But you can get at it's latest value by
> means of the TaskContext service interface:
>
> >=taskcontext:provides("port-name"):last()
>
> Best regards
> Markus
>
> --
> Orocos-Users mailing list
> Orocos-Users [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users