Problem when calling commands from within a TaskContext

Lars-Peter Ellekilde <[email protected]> Thu, 24 May 2007 11:33:18 +0200
Newsgroups gmane.science.robotics.orocos.user
Message-ID <[email protected]>
Hi
I have a problem when attempting to invoke a Command in one TaskContext 
from within another. My code is very similar to the example in the 
Component Builders Manual section 3.9 (see code below). The caller 
invokes the call and continues execution correctly, however when the 
callee starts executing it fails with the message:

"pure virtual method called
terminate called without an active exception
Aborted"

I have tried it both with RTT 1.0 and 1.2, experiencing the same 
behavior. Guess it might be something about the execution flow which I 
have misunderstood, thus I sincerely hope someone can help me figure it 
out. Calling the command from within  "ORO_main" after starting the 
activities works fine.

Best regards and thanks
- Lars-Peter



#include <rtt/TaskContext.hpp>
#include <rtt/PeriodicActivity.hpp>
#include <rtt/Command.hpp>
#include <iostream>
#include <rtt/os/main.h>

using namespace RTT;


class Task1 : public RTT::TaskContext
{
private:
    bool myCmd() { std::cout<<"My Command"<<std::endl; return true; }
    bool myCmdDone() const { std::cout<<"My Command Done"<<std::endl; 
return true; }

    RTT::Command<bool(void)> _mycmd;

public:
    Task1(std::string name):
        RTT::TaskContext(name),
        _mycmd("mycmd", &Task1::myCmd, &Task1::myCmdDone, this) 
    {
         this->commands()->addCommand(_mycmd, "My Command");
    }

    bool startup() { return true; }

    void update() {}

    void shutdown() {}
};


class Task2: public RTT::TaskContext {
public:
    Task2(std::string name): TaskContext(name) {}

    ~Task2() {}

private:
    bool startup() { return true; }

    void update() {
        RTT::TaskContext* task = getPeer("Task1");
        RTT::Command<bool(void)> cmd = 
task->commands()->getCommand<bool(void)>("mycmd");
        bool b = cmd();
    }

    void shutdown() {}

};
**
 * main() function
 */
int ORO_main(int arc, char* argv[])
{

    Task1 task1("Task1");
    Task2 task2("Task2");

    connectPeers(&task1, &task2);

    PeriodicActivity activity1(OS::HighestPriority, 0.01, task1.engine() );
    activity1.start();

    PeriodicActivity activity2(OS::LowestPriority, 1, task2.engine() );
    activity2.start();

    while (true) sleep(10);

    return 0;
}


-- 
Orocos mailing list
[email protected]
http://lists.mech.kuleuven.be/mailman/listinfo/orocos