Hi,
I'm new to orocos and just trying to familiarize myself with how it works. I've tried to create two simple components, each with one unbuffered input and output. The first component just adds an offset to the input value, and the second component multiplies it by a gain.
When I try to play with it in TaskBrowser, it seems to be working at first. I can connect to the Data_R input port of MyOffsetTask and give it a value, and the output is correctly value+offset. If I then cd gain_task, it too is properly multiplying that by its gain. The issue is when I switch back to the offset task (cd offset_task) and try to change the value again, I'm getting a segmentation fault. I'm reconnecting to the input port (.connect Data_R) because the connection seems to be lost when I switch over to a different component. Does connecting to the same port twice not work, or is there something wrong with my code? (Code is below)
Thanks for reading.
#include <rtt/os/main.h> #include <ocl/TaskBrowser.hpp> #include <rtt/PeriodicActivity.hpp> #include <rtt/Ports.hpp> #include <stdio.h> #include <assert.h> using namespace RTT; /* Test component applies a P-gain to unbuffered input */ class MyGainTask : public TaskContext { Attribute<double> gain; ReadDataPort<double> indatPort; WriteDataPort<double> outdatPort; public: MyGainTask(std::string name) : TaskContext(name), gain("gain",2.0), indatPort("channel"), outdatPort("Data_W") { this->attributes()->addAttribute( &gain ); this->ports()->addPort( &indatPort, "Input Data Port"); this->ports()->addPort( &outdatPort, "Output Data Port"); } bool configureHook() { return true; } bool startHook() { return true; } void updateHook() { outdatPort.Set( gain.get() * indatPort.Get() ); } void stopHook() { } void cleanupHook() { } }; /* Test component to add an offset to incoming unbuffered data */ class MyOffsetTask : public TaskContext { Attribute<double> offset; ReadDataPort<double> indatPort; WriteDataPort<double> outdatPort; public: MyOffsetTask(std::string name) : TaskContext(name), offset("offset",-1.0), indatPort("Data_R"), outdatPort("channel") { this->attributes()->addAttribute( &offset ); this->ports()->addPort( &indatPort, "Input Data Port"); this->ports()->addPort( &outdatPort, "Output Data Port"); } bool configureHook() { return true; } bool startHook() { return true; } void updateHook() { outdatPort.Set( offset.get() + indatPort.Get() ); } void stopHook() { } void cleanupHook() { } }; int ORO_main(int argc, char** argv) { // Create the two tasks, operating in sync TaskContext* g_task = new MyGainTask("gain_task"); TaskContext* o_task = new MyOffsetTask("offset_task"); g_task->setActivity( new PeriodicActivity( 5, 0.01) ); o_task->setActivity( new PeriodicActivity( 5, 0.01) ); // Start the tasks g_task->start(); o_task->start(); // Connect the two tasks o_task->ports()->getPort("channel")->connectTo( g_task->ports()->getPort("channel") ); connectPeers( o_task, g_task ); // Set up a TaskBrowser for interaction with the user OCL::TaskBrowser browser(o_task); browser.loop(); // End the tasks g_task->stop(); o_task->stop(); return 0; }
segfault in TaskBrowser
On Jun 11, 2009, at 11:47 , ndamore [..] ... wrote:
> Hi,
>
> I'm new to orocos and just trying to familiarize myself with how it
> works. I've tried to create two simple components, each with one
> unbuffered input and output. The first component just adds an
> offset to the input value, and the second component multiplies it by
> a gain.
>
> When I try to play with it in TaskBrowser, it seems to be working at
> first. I can connect to the Data_R input port of MyOffsetTask and
> give it a value, and the output is correctly value+offset. If I
> then cd gain_task, it too is properly multiplying that by its gain.
> The issue is when I switch back to the offset task (cd offset_task)
> and try to change the value again, I'm getting a segmentation
> fault. I'm reconnecting to the input port (.connect Data_R) because
> the connection seems to be lost when I switch over to a different
> component. Does connecting to the same port twice not work, or is
> there something wrong with my code? (Code is below)
>
> Thanks for reading.
>
>
segfault in TaskBrowser
Thanks for the replies. Yes, I was using '.connect' and switching to plain DataPort types gets me around the issue.
I don't have much experience with gdb, but here's a backtrace. I changed the updateHooks to virtual and replaced o_task->ports()->... with connectPorts(...) as suggested.
segfault in TaskBrowser
On Thu, Jun 11, 2009 at 22:52, <ndamore [..] ...> wrote:
> Thanks for the replies. Yes, I was using '.connect' and switching to plain DataPort types gets me around the issue.
>
> I don't have much experience with gdb, but here's a backtrace. I changed the updateHooks to virtual and replaced o_task->ports()->... with connectPorts(...) as suggested.
Thanks for the info, I created a bug report on
https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=670
Peter
segfault in TaskBrowser
On Thu, Jun 11, 2009 at 17:47, <ndamore [..] ...> wrote:
> Hi,
>
> I'm new to orocos and just trying to familiarize myself with how it works. I've tried to create two simple components, each with one unbuffered input and output. The first component just adds an offset to the input value, and the second component multiplies it by a gain.
>
> When I try to play with it in TaskBrowser, it seems to be working at first. I can connect to the Data_R input port of MyOffsetTask and give it a value, and the output is correctly value+offset. If I then cd gain_task, it too is properly multiplying that by its gain. The issue is when I switch back to the offset task (cd offset_task) and try to change the value again, I'm getting a segmentation fault. I'm reconnecting to the input port (.connect Data_R) because the connection seems to be lost when I switch over to a different component. Does connecting to the same port twice not work, or is there something wrong with my code? (Code is below)
Probably you've hit a bug. I'm assuming here that you used the
'.connect' feature of the taskbrowser ?
You can work around that by using plain DataPort<double> types which
you can then directly write, without doing the .connect trickery. That
should keep you away from these crashes for now.
Sylvain, If you'd be reading this, how did you test your components
with the new data port (InputPort) branch ? Could you write values to
InputPorts from the taskbrowser ?
Peter