User defined type in script

I have created my own data type in C++ : doubleRT.
I am trying to use it in Orocos script language.

Using the documentation (and Peter's help !)
http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v1.6.x/doc-xml/orocos-toolkit-plugin.html#id2503600

I have registered the constructor and I can do :
var doubleRT d_rt = doubleRT(3.0); // constructor from 'double'
set d_rt = d_rt * 5.0; // operator*(doubleRT, double)

I have added a new dot opertaor like this
template
struct isValid
: public std::unary_function
{
bool operator()(T data ) const
{
return data.isValid();
}
};
OperatorRepository::shared_ptr oreg = OperatorRepository::Instance();
oreg->add( newDotOperator( "valid", get_valid() ) );
And I can do :
var doubleRT d_rt = ....
if( d_rt.isValid) then ...

But I still have the following problems :

1: I can not do these operations ( = or dot operator) in the TaskBrowser

2: If I create a port with type doubleRT (myPort) I can not use the dot operator on its value in a script :
if( myPort.Get().isValid ) then ... // parse error when I load the programm
The only way is to use a local variable :
doubleRT_d_rt = myPort.Get();
if( d_rt.isValid ) then ...

3: I can not modify a variable through a method in script.
doubleRT d_rt = ...
d_rt.setDate;
d_rt.setValue(123);
(I have tried to take data as a reference in the struct : operator()(T & data), it does not compile)

My question: Are my observations a normal limit of Orocos scripting capabilities or can I do something in a better way to have access to these functionalities ?

Thank you
Renaud Heitz

User defined type in script

On Monday 16 February 2009 12:15:33 renaud [dot] heitz [..] ... wrote:
...
>
>
> But I still have the following problems :
>
> 1: I can not do these operations ( = or dot operator) in the TaskBrowser

That's probably because your toolkit is not loaded at that point in time.
Can you do it if you load a component which registers the type+operators ?

You should be able to write 'doubleRT(3.0)' and use the isValid operation for
example. The TB does not allow the full program syntax (set ..., var..., )
like a true shell would allow.

>
> 2: If I create a port with type doubleRT (myPort) I can not use the dot
> operator on its value in a script : if( myPort.Get().isValid ) then ... //
> parse error when I load the programm The only way is to use a local
> variable :
> doubleRT_d_rt = myPort.Get();
> if( d_rt.isValid ) then ...

Yes. This is a (unnecessary) restriction in our parser. This could be fixed.

>
> 3: I can not modify a variable through a method in script.
> doubleRT d_rt = ...
> d_rt.setDate;
> d_rt.setValue(123);
> (I have tried to take data as a reference in the struct : operator()(T &
> data), it does not compile)

This is a limitation of how the dotoperator works and is quite fundamental. I
wrote this up in the plugin manual, but the 'devel' server is down at the
moment. You could check it out later this link:
http://people.mech.kuleuven.be/~orocos/pub/devel/rtt/latest/doc-xml/orocos-
toolkit-plugin.html

You'll have to use constructor syntax to work around most of these issues
* instead of using d_rt.setDate, use d_rt = doubleRT( d_rt.value, true); //
true == sets date
* instead of d_rt.setValue(123), use d_rt = doubleRT( d_rt.value ); // keeps
date

or something similar...

>
> My question: Are my observations a normal limit of Orocos scripting
> capabilities or can I do something in a better way to have access to these
> functionalities ?

For most things there is a work-around, but it are indeed limitations of the
current scripting syntax.

Peter

User defined type in script

On Monday 16 February 2009 15:45:23 Peter Soetens wrote:
> You'll have to use constructor syntax to work around most of these issues
> * instead of using d_rt.setDate, use d_rt = doubleRT( d_rt.value, true);
> // true == sets date
> * instead of d_rt.setValue(123), use d_rt = doubleRT( d_rt.value ); //
> keeps date

That should have been:

* instead of d_rt.setValue(123), use d_rt = doubleRT( 123 ); // keeps date

Peter