problem with exercises

hi

i'm having some problems with the hello exercises and the components' manual.

1. i dont know why, but i cant find/use some of the methods explained in the manual. Like for example collectIfDone(...) and ret(), in class SendHandle.

2. when i try to run the HelloWorld of exercise 6 (scripting) i get the following error: ./HelloWorld-gnulinux: error while loading shared libraries: librtt-scripting-gnulinux.so.2.3.2: cannot open shared object file: No such file or directory

3. is it possible to access all atributes, methods, ports (and its methods), etc of a component from a .ops program? (the component loads the program) like for example:

    while (name_of_component.inputport.read(helloData) != 0) yield;
4. how can i manage the send (sending operations) when i pass values by reference or pointers? for example, if i have this operation:
    void op1 (int &num1, int *num2){...}
   how can i access these values from a sendhandle?
5. i'm am brand new in the cmake, makefiles, etc. environment. when you say "in the Makefile: link with rtt-marshalling-<target> found in lib/orocos/plugins and also add the lib/orocos/plugins directory to the RPATH.", what exactly should i do in the Makefile?

finally, is there any place where i could find all the exercises solved to know if i am doing right?

problem with exercises

On Tuesday 28 June 2011 13:57:39 luca [dot] gherardi [..] ... wrote:
>

focke_85 wrote:
Hi Peter, thanks for the reply.
>
> 1. I am usin c++ with eclipse. Since I didnt see this methods in the header
> file of the class and the autocompletion didnt show them I thought they
> were not there. I used the ret() method and it compiled, but the
> collectIfDone() doesnt appear.
>
> ...
>
> thanks again
>
> santiago

>
> I have the same problem.
> The components builder's manual also said that the methods are provided in
> two forms, with parameters and without parameters. I can't use also the
> parameters form of collect() and collectIfDone().
>

What do you mean, you get compilation errors ? Can you give a concrete code
example ?

Peter

problem with exercises

On Tuesday 28 June 2011 16:15:34 luca [dot] gherardi [..] ... wrote:
>

peter wrote:
On Tuesday 28 June 2011 13:57:39 luca [dot] gherardi [..] ... wrote:
> >
focke_85 wrote:
Hi Peter, thanks for the reply.
> >
> > 1. I am usin c++ with eclipse. Since I didnt see this methods in the
> > header file of the class and the autocompletion didnt show them I
> > thought they were not there. I used the ret() method and it compiled,
> > but the collectIfDone() doesnt appear.
> >
> > ...
> >
> > thanks again
> >
> > santiago

> >
> > I have the same problem.
> > The components builder's manual also said that the methods are provided
> > in two forms, with parameters and without parameters. I can't use also
> > the parameters form of collect() and collectIfDone().
>
> What do you mean, you get compilation errors ? Can you give a concrete code
> example ?
>
> Peter
>

>
> Yes, of course.
>
> This is the piece of code that works.
>
> &#10;&gt; string sentence = &quot;Orocos&quot;;&#10;&gt; sayItHandler = sayIt_method.send(sentence,answer);&#10;&gt; SendStatus ss = sayItHandler.collect();&#10;&gt; if(ss == SendSuccess){&#10;&gt;    returnValue = sayItHandler.ret();&#10;&gt; }&#10;&gt; log(Info) &lt;&lt; &quot;Answer result: &quot; &lt;&lt; answer &lt;&lt; &quot; - SendStatus: &quot; &lt;&lt; ss &lt;&lt; &quot; -&#10;&gt; RetVal: &quot; &lt;&lt;returnValue &lt;&lt; endlog();
>
> When I replace collect() with collectIfDone() (in the third line), I
> receive the following compilation output:

...

I would remove this feature from the documentation. IMHO, it's an
implementation artifact that leaked to the public API. We need
collect(void)/ret(args) internally, but I don't think there's a clear use case
for plain user code. So always provide the proper arguments to collect() and
collectIfDone(). Ie, return value and out arguments (=pure reference
arguments).

Peter

Re: problem with exercises

peter wrote:
On Tuesday 28 June 2011 13:57:39 luca [dot] gherardi [..] ... wrote: >
focke_85 wrote:
Hi Peter, thanks for the reply. > > 1. I am usin c++ with eclipse. Since I didnt see this methods in the header > file of the class and the autocompletion didnt show them I thought they > were not there. I used the ret() method and it compiled, but the > collectIfDone() doesnt appear. > > ... > > thanks again > > santiago
> > I have the same problem. > The components builder's manual also said that the methods are provided in > two forms, with parameters and without parameters. I can't use also the > parameters form of collect() and collectIfDone(). >

What do you mean, you get compilation errors ? Can you give a concrete code example ?

Peter

Yes, of course.

This is the piece of code that works.

string sentence = "Orocos";
sayItHandler = sayIt_method.send(sentence,answer);
SendStatus ss = sayItHandler.collect();
if(ss == SendSuccess){
   returnValue = sayItHandler.ret();
}
log(Info) << "Answer result: " << answer << " - SendStatus: " << ss << " - RetVal: " <<returnValue << endlog();

When I replace collect() with collectIfDone() (in the third line), I receive the following compilation output:

make -C /home/luca/workspace/hello-4-operations/build all 
make: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[1]: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
[  0%] Built target rospack_genmsg_libexe
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
[  0%] Built target rosbuild_precompile
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
Scanning dependencies of target HelloWorld
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
[100%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o
/home/luca/workspace/hello-4-operations/HelloWorld.cpp: In member function ‘virtual void Example::World::updateHook()’:
/home/luca/workspace/hello-4-operations/HelloWorld.cpp:162: error: no matching function for call to ‘RTT::SendHandle<bool(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)>::collectIfDone()’
/opt/ros/diamondback/stacks/orocos_toolchain_ros/rtt/install/include/rtt/internal/../internal/../internal/CollectSignature.hpp:194: note: candidates are: RTT::SendStatus RTT::internal::CollectSignature<2, F, ToCollect>::collectIfDone(typename boost::function_traits<Signature>::arg1_type, typename boost::function_traits<Signature>::arg2_type) [with F = bool(bool&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&), ToCollect = RTT::internal::CollectBase<bool(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)>*]
make[2]: *** [CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o] Error 1
make[1]: *** [CMakeFiles/HelloWorld.dir/all] Error 2
make: *** [all] Error 2
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
make[1]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
make: Leaving directory `/home/luca/workspace/hello-4-operations/build'

The same if i use collectIfDone(returnValue):

make -C /home/luca/workspace/hello-4-operations/build all 
make: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[1]: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
[  0%] Built target rospack_genmsg_libexe
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
[  0%] Built target rosbuild_precompile
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
make[2]: Entering directory `/home/luca/workspace/hello-4-operations/build'
[100%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o
/home/luca/workspace/hello-4-operations/HelloWorld.cpp: In member function ‘virtual void Example::World::updateHook()’:
/home/luca/workspace/hello-4-operations/HelloWorld.cpp:162: error: no matching function for call to ‘RTT::SendHandle<bool(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)>::collectIfDone(bool&)’
/opt/ros/diamondback/stacks/orocos_toolchain_ros/rtt/install/include/rtt/internal/../internal/../internal/CollectSignature.hpp:194: note: candidates are: RTT::SendStatus RTT::internal::CollectSignature<2, F, ToCollect>::collectIfDone(typename boost::function_traits<Signature>::arg1_type, typename boost::function_traits<Signature>::arg2_type) [with F = bool(bool&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&), ToCollect = RTT::internal::CollectBase<bool(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)>*]
make[2]: *** [CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o] Error 1
make[1]: *** [CMakeFiles/HelloWorld.dir/all] Error 2
make: *** [all] Error 2
make[2]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
make[1]: Leaving directory `/home/luca/workspace/hello-4-operations/build'
make: Leaving directory `/home/luca/workspace/hello-4-operations/build'

Another issue, less relevant, is that in the second line the use of the operation returns me the following error: Method 'send' could not be resolved (in eclipse). Anyway for this issue I've not compilation problems.

Thanks, Luca

problem with exercises

On Friday 20 May 2011 11:43:15 focke [dot] 85 [..] ... wrote:
> hi
>
> i'm having some problems with the hello exercises and the components'
> manual.
>
> 1. i dont know why, but i cant find/use some of the methods explained in
> the manual. Like for example collectIfDone(...) and ret(), in class
> SendHandle.

They should be there. Doxygen does not show them because they are inserted
through a template base class. Are you refering to use in C++ ?

>
> 2. when i try to run the HelloWorld of exercise 6 (scripting) i get the
> following error: ./HelloWorld-gnulinux: error while loading shared
> libraries: librtt-scripting-gnulinux.so.2.3.2: cannot open shared object
> file: No such file or directory

This is a bug in the rpath, ie, a setting in HelloWorld-gnulinux that tells
where the 'run-time' path is where the libraries are. Can you check this with
the new release of the exercises ? Download from
http://www.orocos.org/wiki/orocos/toolchain/getting-started/toolchain-
tutorials

>
> 3. is it possible to access all atributes, methods, ports (and its
> methods), etc of a component from a .ops program? (the component loads the
> program) like for example: while
> (name_of_component.inputport.read(helloData) != 0) yield;

Yes. Although you should check with 'NewData' instead of '0'.

>
> 4. how can i manage the send (sending operations) when i pass values by
> reference or pointers? for example, if i have this operation: void op1
> (int &num1, int *num2){...}
> how can i access these values from a sendhandle?

&#10;OperationCaller&lt;void(int&amp;, int*)&gt; op = peer-&gt;provides()-&gt;getOperation(&quot;op1&quot;);&#10;SendHandle&lt;void(int&amp;, int*)&gt; sh = op.send( num1, num2 );&#10;sh.collect(num1, num2);&#10;

Big warning: pointers can't be used across components in different processes.
So this will definately crash when 'peer' is existing in a different process.

>
> 5. i'm am brand new in the cmake, makefiles, etc. environment. when you say
> "in the Makefile: link with rtt-marshalling-<target> found in
> lib/orocos/plugins and also add the lib/orocos/plugins directory to the
> RPATH.", what exactly should i do in the Makefile?

I have created a new release of the exercises with corrected instructions. It
should have informed you about modifying the CMakeLists.txt file, not the
Makefile.

See
http://www.orocos.org/wiki/orocos/toolchain/getting-started/cmake-and-bu...

Item 1 and 2. The wiki example does not set the rpath, so this is still an
issue aparantly... You could add:

link_libraries( ${OROCOS-RTT_RTT-MARSHALLING_LIBRARY} )

Are you using ROS or bare Orocos ?

>
> finally, is there any place where i could find all the exercises solved to
> know if i am doing right?

Solving the exercises is almost copy/pasting the right code from the manual,
but you're not the first one to ask, so we'll try to provide some...

Peter

Re: problem with exercises

Hi Peter, thanks for the reply.

1. I am usin c++ with eclipse. Since I didnt see this methods in the header file of the class and the autocompletion didnt show them I thought they were not there. I used the ret() method and it compiled, but the collectIfDone() doesnt appear.

2. OK

3. I have a program and a state machine trying to access ports, atributes, etc of the tasks loading them. But when I load the program and state machine from the taskBrowser, I get this error:

Hello [R]> scripting.loadPrograms("program.ops")
1978.842 [ Info   ][ProgramLoader::loadProgram] Parsing file program.ops
1978.845 [ ERROR  ][ProgramLoader::loadProgram] program.ops :Parse error at line 28: No method "input" registered for the object or task "Hello".
 = false  

The name of the InputPort in the task Hello is 'input'.The program is the following:

program App {
    while (true) {
        var array inputData = array(10);
        var array outputData = array(10);
        var array gainsData = array(10);
 
        if ( Hello.input.read( inputData ) == NewData ) { 
            gainsData = Hello.gains;
            for (int i = 0; i < 10; i = i+1)
                outputData(i) = gainsData(i) * inputData(i);
            Hello.output.write( outputData );
        }
          yield;
    }
}

5. I'm using ROS, so I guess that changes the command. I put the following code in the cMakeList.txt (just after the 'exercise' note)

find_package(Orocos-RTT REQUIRED rtt-marshalling)
 
if ( OROCOS-RTT_RTT-SCRIPTING_FOUND )
  link_libraries( ${OROCOS-RTT_RTT-SCRIPTING_LIBRARY} )
else( OROCOS-RTT_RTT-SCRIPTING_FOUND )
  message(SEND_ERROR "'rtt-scripting' not found !")
endif( OROCOS-RTT_RTT-SCRIPTING_FOUND )

but i got the following errors when i put 'this->getProvider<Marshalling>("marshalling");' in my class (task) constructor:

CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o: In function `shared_ptr<RTT::ServiceRequester>':
/usr/include/boost/smart_ptr/shared_ptr.hpp:259: undefined reference to `typeinfo for RTT::Marshalling'
 
...
 
/usr/include/boost/smart_ptr/make_shared.hpp:185: undefined reference to `RTT::Marshalling::Marshalling(RTT::TaskContext*)'
 
...
 
make[3]: *** [../HelloWorld-gnulinux] Error 1
make[2]: *** [CMakeFiles/HelloWorld.dir/all] Error 2

thanks again

santiago

Re: problem with exercises

focke_85 wrote:
Hi Peter, thanks for the reply.

1. I am usin c++ with eclipse. Since I didnt see this methods in the header file of the class and the autocompletion didnt show them I thought they were not there. I used the ret() method and it compiled, but the collectIfDone() doesnt appear.

...

thanks again

santiago

I have the same problem. The components builder's manual also said that the methods are provided in two forms, with parameters and without parameters. I can't use also the parameters form of collect() and collectIfDone().

Regards, Luca