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:

RTT::types()->addType( new TemplateTypeInfo<std::uint8_t>("uint8_t"));

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:

std::uint8_t int_to_uint8( int i ) { return i; }
RTT::types()->type("uint8_t")->addConstructor( newConstructor(&int_to_uint8));

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:
>
>

> RTT::types()->addType( new TemplateTypeInfo<std::uint8_t>("uint8_t"));
> 

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)

RTT::types()->addType( new TemplateTypeInfo<std::uint8_t,true>("uint8_t"));

Then the TaskBrowser showed

uint8_t SystemState = (nothing, followed by a newline)

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

std::ostream& operator<<(std::ostream& os, const std::uint8_t& var) {
         return os << (int)var;
}
 
std::istream& operator>>(std::istream& is, std::uint8_t& var) {
         return is >> var;
}

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:
>
>

> std::uint8_t int_to_uint8( int i ) { return i; }
> RTT::types()->type("uint8_t")->addConstructor( newConstructor(&int_to_uint8));
> 

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:
>>
>>

>> RTT::types()->addType( new TemplateTypeInfo<std::uint8_t>("uint8_t"));
>> 

>
> 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)
>
>
> RTT::types()->addType( new TemplateTypeInfo<std::uint8_t,true>("uint8_t"));
> 

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
>
>

> std::ostream& operator<<(std::ostream& os, const std::uint8_t& var) {
>        return os << (int)var;
> }
>
> std::istream& operator>>(std::istream& is, std::uint8_t& var) {
>        return is >> var;
> }
> 

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:
>>
>>

>> std::uint8_t int_to_uint8( int i ) { return i; }
>> RTT::types()->type("uint8_t")->addConstructor(
>> newConstructor(&int_to_uint8));
>> 

>
> 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