adding standard datatypes to Orocos

Hello,

This is about orocos-rtt 1.10.4 and orocos-ocl-1.10.2

I have several Attributes which are of type std::uint8_t Also, there are
some methods that take a std::uint8_t as argument.

All these uint8_t types show up as unknown_t in TaskBrowser and I am
unable to call the methods from the TaskBrowser (Orocos grumbles that
the method expects argument of type unknown_t whereas an int was provided)

How do I add the datatypes from <cstdint> like uint16_t sint32_t and so
on? I read

http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v1.1...

Do I need to redefine the cstdint types again as structs? That doesn't
feel right. If I do, then it means that I will need to change the types
from std::uint8_t to struct uint8_t with other possible collisions.

Am I missing something?

Thanks in advance,
Sagar

adding standard datatypes to Orocos

On Sunday 24 April 2011 18:42:08 Sagar Behere wrote:
> Hello,
>
> This is about orocos-rtt 1.10.4 and orocos-ocl-1.10.2
>
> I have several Attributes which are of type std::uint8_t Also, there are
> some methods that take a std::uint8_t as argument.
>
> All these uint8_t types show up as unknown_t in TaskBrowser and I am
> unable to call the methods from the TaskBrowser (Orocos grumbles that
> the method expects argument of type unknown_t whereas an int was provided)
>
> How do I add the datatypes from <cstdint> like uint16_t sint32_t and so
> on? I read
>
> http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v1.10.x
> /doc-xml/orocos-toolkit-plugin.html
>
> Do I need to redefine the cstdint types again as structs? That doesn't
> feel right. If I do, then it means that I will need to change the types
> from std::uint8_t to struct uint8_t with other possible collisions.
>
> Am I missing something?

The struct is the classical case for 'user defined types'. For 'system' types,
you may add them without using a struct, just the type name. For example:

&#10;RTT::types()-&gt;addType( new TemplateTypeInfo&lt;std::uint8_t&gt;(&quot;uint8_t&quot;));&#10;

However, the taskbrowser will not know how to convert the 'int' to an
'uint8_t'. For this you must extend the uint8_t type info with 'constructors',
which define how to construct a uint8_t from an int.

For example:

&#10;std::uint8_t int_to_uint8( int i ) { return i; }&#10;RTT::types()-&gt;type(&quot;uint8_t&quot;)-&gt;addConstructor( newConstructor(&amp;int_to_uint8));&#10;

Cheers,
Peter

adding standard datatypes to Orocos

On 04/26/2011 02:50 PM, Peter Soetens wrote:
> On Sunday 24 April 2011 18:42:08 Sagar Behere wrote:
>> Hello,
>>
>> This is about orocos-rtt 1.10.4 and orocos-ocl-1.10.2
>>
>> I have several Attributes which are of type std::uint8_t Also, there are
>> some methods that take a std::uint8_t as argument.
>>
>> All these uint8_t types show up as unknown_t in TaskBrowser and I am
>> unable to call the methods from the TaskBrowser (Orocos grumbles that
>> the method expects argument of type unknown_t whereas an int was provided)
>>
>> How do I add the datatypes from<cstdint> like uint16_t sint32_t and so
>> on? I read
>>
>> http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v1.10.x
>> /doc-xml/orocos-toolkit-plugin.html
>>
>> Do I need to redefine the cstdint types again as structs? That doesn't
>> feel right. If I do, then it means that I will need to change the types
>> from std::uint8_t to struct uint8_t with other possible collisions.
>>
>> Am I missing something?
>
> The struct is the classical case for 'user defined types'. For 'system' types,
> you may add them without using a struct, just the type name. For example:
>
> &#10;&gt; RTT::types()-&gt;addType( new TemplateTypeInfo&lt;std::uint8_t&gt;(&quot;uint8_t&quot;));&#10;&gt;

When I added that code, the TaskBrowser showed me

uint8_t SystemState = (uint8_t)

Since it did not show the actual value, I changed the code line to
(added true to template)

&#10;RTT::types()-&gt;addType( new TemplateTypeInfo&lt;std::uint8_t,true&gt;(&quot;uint8_t&quot;));&#10;

Then the TaskBrowser showed

uint8_t SystemState = (nothing, followed by a newline)

So then, just before my ORO_main() function, I added

&#10;std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const std::uint8_t&amp; var) {&#10;         return os &lt;&lt; (int)var;&#10;}&#10;&#10;std::istream&amp; operator&gt;&gt;(std::istream&amp; is, std::uint8_t&amp; var) {&#10;         return is &gt;&gt; var;&#10;}&#10;

But I am still unable to see the value in the TaskBrowser. I tried
debugging by making the << operator emit a text string just before the
value is shown [ return os << "FOO" << (int)var;] but there was no
difference in the output and I did not see the FOO string. Its like the
overloaded function is never called.

How should I debug this?

> However, the taskbrowser will not know how to convert the 'int' to an
> 'uint8_t'. For this you must extend the uint8_t type info with 'constructors',
> which define how to construct a uint8_t from an int.
>
> For example:
>
> &#10;&gt; std::uint8_t int_to_uint8( int i ) { return i; }&#10;&gt; RTT::types()-&gt;type(&quot;uint8_t&quot;)-&gt;addConstructor( newConstructor(&amp;int_to_uint8));&#10;&gt;

Thanks, I will get around to this part when the above issue is fixed.

/Sagar

> Cheers,
> Peter

adding standard datatypes to Orocos

On Tue, Apr 26, 2011 at 6:00 PM, Sagar Behere <sagar [dot] behere [..] ...> wrote:
> On 04/26/2011 02:50 PM, Peter Soetens wrote:
>>
>> On Sunday 24 April 2011 18:42:08 Sagar Behere wrote:
>>>
>>> Hello,
>>>
>>> This is about orocos-rtt 1.10.4 and orocos-ocl-1.10.2
>>>
>>> I have several Attributes which are of type std::uint8_t Also, there are
>>> some methods that take a std::uint8_t as argument.
>>>
>>> All these uint8_t types show up as unknown_t in TaskBrowser and I am
>>> unable to call the methods from the TaskBrowser (Orocos grumbles that
>>> the method expects argument of type unknown_t whereas an int was
>>> provided)
>>>
>>> How do I add the datatypes from<cstdint>  like uint16_t sint32_t and so
>>> on? I read
>>>
>>>
>>> http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v1.10.x
>>> /doc-xml/orocos-toolkit-plugin.html
>>>
>>> Do I need to redefine the cstdint types again as structs? That doesn't
>>> feel right. If I do, then it means that I will need to change the types
>>> from std::uint8_t to struct uint8_t with other possible collisions.
>>>
>>> Am I missing something?
>>
>> The struct is the classical case for 'user defined types'. For 'system'
>> types,
>> you may add them without using a struct, just the type name. For example:
>>
>> &#10;&gt;&gt; RTT::types()-&gt;addType( new TemplateTypeInfo&lt;std::uint8_t&gt;(&quot;uint8_t&quot;));&#10;&gt;&gt;
>
> When I added that code, the TaskBrowser showed me
>
> uint8_t SystemState = (uint8_t)
>
> Since it did not show the actual value, I changed the code line to (added
> true to template)
>
> &#10;&gt; RTT::types()-&gt;addType( new TemplateTypeInfo&lt;std::uint8_t,true&gt;(&quot;uint8_t&quot;));&#10;&gt;

Oh yeah, forgot to tell you about that :-)

>
> Then the TaskBrowser showed
>
> uint8_t SystemState = (nothing, followed by a newline)

std::uint8_t == unsigned char. We have the same behavior when printing a char.

>
> So then, just before my ORO_main() function, I added
>
> &#10;&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const std::uint8_t&amp; var) {&#10;&gt;        return os &lt;&lt; (int)var;&#10;&gt; }&#10;&gt;&#10;&gt; std::istream&amp; operator&gt;&gt;(std::istream&amp; is, std::uint8_t&amp; var) {&#10;&gt;        return is &gt;&gt; var;&#10;&gt; }&#10;&gt;

This should work but...

>
> But I am still unable to see the value in the TaskBrowser. I tried debugging
> by making the << operator emit a text string just before the value is shown
> [ return os << "FOO" << (int)var;] but there was no difference in the output
> and I did not see the FOO string. Its like the overloaded function is never
> called.
>
> How should I debug this?

I'm not sure either, but formatting an unsigned char is part of the ostream API.
Did you try to drop the const& in the ostream operator<< ?

The easiest way out is to keep using the 'false' parameter in the
TemplateTypeInfo
declaration and to implement read() and write() yourself. Look in the
TemplateTypeInfo
header on how these are now implemented and create a class
Uint8TypeInfo that inherits
from TemplateTypeInfo<std::uint8_t> and which just implements these
two functions, but
which casts the data to an int before operator<< is called.

>
>> However, the taskbrowser will not know how to convert the 'int' to an
>> 'uint8_t'. For this you must extend the uint8_t type info with
>> 'constructors',
>> which define how to construct a uint8_t from an int.
>>
>> For example:
>>
>> &#10;&gt;&gt; std::uint8_t int_to_uint8( int i ) { return i; }&#10;&gt;&gt; RTT::types()-&gt;type(&quot;uint8_t&quot;)-&gt;addConstructor(&#10;&gt;&gt; newConstructor(&amp;int_to_uint8));&#10;&gt;&gt;
>
> Thanks, I will get around to this part when the above issue is fixed.
>
> /Sagar
>
>> Cheers,
>> Peter
>

Peter
--
Orocos-Users mailing list
Orocos-Users [..] ...
http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users