Connection between components doesn't work

Hello, I'm trying to create 2 OROCOS components and to make a connection between them using ROS. So, I've created 2 files : component1.cpp and component2.cpp and an XML file to define a mapping between them. The structure of those components looks like :

class Component1 : public RTT::TaskContext {
private:
  OutputPort<std_msgs::Float64> outportDistance;
  InputPort<sensor_msgs::LaserScan> inport_laser;
  InputPort<sensor_msgs::Range> inport_infrared_left;
  InputPort<sensor_msgs::Range> inport_infrared_right;
public:
  Component1(const std::string& name):
    TaskContext(name),
    inport_laser("laser_in"),
    inport_infrared_left("infrared_left_in"),
    inport_infrared_right("infrared_right_in"),
    outportDistance("VS_out")
  {
        ports()->addPort(inport_laser);
        ports()->addPort(inport_infrared_left);
        ports()->addPort(inport_infrared_right);
        ports()->addPort(outportDistance);
  }
  ~Component1() {}
private:
  void updateHook() {
    //...
      }
};
 
ORO_CREATE_COMPONENT(Component1)
[\code]
 
[code]
class Component2 : public RTT::TaskContext {
private:
  InputPort<std_msgs::Float64> inport;
  OutputPort<geometry_msgs::Twist> outport;
 
public:
  Component2(const std::string& name):
    TaskContext(name),
    inport("Distance_in"),
    outport("twist_out")
  {
    ports()->addPort(inport);
    ports()->addPort(outport);
  }
  ~Component2() {}
private:
  void updateHook() {
    //...
  }
};
ORO_CREATE_COMPONENT(Component2)
[\code]
 
Component2 uses a value returned by component1. To realize the mapping between those components, I've configured an XML file:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "cpf.dtd">
<properties>
<simple name="Import" type="string"><value>2ComponentsExample</value></simple>
 
<struct name="VS_Connection" type="ConnPolicy">
  <simple name="type" type="short"><value>0</value></simple>
  <simple name="size" type="short"><value>1</value></simple>
  <simple name="transport" type="short"><value>3</value></simple>
  <simple name="name_id" type="string"><value>float_rtt</value></simple>
</struct>
 
<struct name="ROSConTwistOut" type="ConnPolicy">
  <simple name="type" type="short"><value>0</value></simple>
  <simple name="size" type="short"><value>1</value></simple>
  <simple name="transport" type="short"><value>3</value></simple>
  <simple name="name_id" type="string"><value>/ATRV/Motion_Controller</value></simple>
</struct>
<struct name="ROSConLaserIn" type="ConnPolicy">
  <simple name="type" type="short"><value>0</value></simple>
  <simple name="size" type="short"><value>1</value></simple>
  <simple name="transport" type="short"><value>3</value></simple>
  <simple name="name_id" type="string"><value>/ATRV/Sick</value></simple>
</struct>
<struct name="ROSConInfraRedLeftIn" type="ConnPolicy">
  <simple name="type" type="short"><value>0</value></simple>
  <simple name="size" type="short"><value>1</value></simple>
  <simple name="transport" type="short"><value>3</value></simple>
  <simple name="name_id" type="string"><value>/ATRV/InfraRedLeft</value></simple>
</struct>
<struct name="ROSConInfraRedRightIn" type="ConnPolicy">
  <simple name="type" type="short"><value>0</value></simple>
  <simple name="size" type="short"><value>1</value></simple>
  <simple name="transport" type="short"><value>3</value></simple>
  <simple name="name_id" type="string"><value>/ATRV/InfraRedRight</value></simple>
</struct>
 
 
<struct name="Comp2" type="Component2">
  <struct name="Activity" type="PeriodicActivity">
    <simple name="Period" type="double"><value>1</value></simple>
    <simple name="Priority" type="short"><value>0</value></simple>
    <simple name="Scheduler" type="string"><value>ORO_SCHED_RT</value></simple>
  </struct>
  <simple name="AutoConf" type="boolean"><value>1</value></simple>
  <simple name="AutoStart" type="boolean"><value>1</value></simple>
 
  <struct name="Ports" type="PropertyBag">
    <simple name="Distance_in" type="string"><value> VS_Connection </value></simple>
    <simple name="twist_out" type="string"><value> ROSConTwistOut </value></simple>
  </struct>
 
  <struct name="Peers" type="PropertyBag">
    <simple type="string"> <value> Comp1 </value> </simple>
  </struct>
 
</struct>
 
<struct name="Comp1" type="Component1">
    <struct name="Activity" type="PeriodicActivity">
    <simple name="Period" type="double"><value>1</value></simple>
    <simple name="Priority" type="short"><value>0</value></simple>
    <simple name="Scheduler" type="string"><value>ORO_SCHED_RT</value></simple>
  </struct>
  <simple name="AutoConf" type="boolean"><value>1</value></simple>
  <simple name="AutoStart" type="boolean"><value>1</value></simple>
 
  <struct name="Ports" type="PropertyBag">
    <simple name="VS_out" type="string"><value> VS_Connection </value></simple>
    <simple name="laser_in" type="string"><value> ROSConLaserIn </value></simple>
    <simple name="infrared_left_in" type="string"><value> ROSConInfraRedLeftIn </value></simple>
    <simple name="infrared_right_in" type="string"><value> ROSConInfraRedRightIn </value></simple>
  </struct>
</struct>
</properties>
[\code]
 
While compiling, I got this message : "multiple definition of `createComponent' "
So I removed ORO_CREATE_COMPONENT(Component2) from Component2.cpp.
 
After creating the ROS node and after the "make" command, when I try "rosrun ocl deployer-gnulinux -s example.xml" 
I got those errors : 
 
0.409 [ ERROR  ][TinyDemarshaller] Could not load example.xml Error: Failed to open file
0.409 [ ERROR  ][DeploymentComponent::loadComponents] Some error occured while parsing example.xml
0.409 [ ERROR  ][Logger] Failed to load a component: aborting kick-start.
 
So I removed:  
  <struct name="Peers" type="PropertyBag">
    <simple type="string"> <value> Comp1 </value> </simple>
  </struct>
from the xml file in a structure Comp2.
 
But I still have errors:
Unable to create Orocos Component 'Component2': unknown component type.
2.083 [ Warning][DeploymentComponent::loadComponents] Could not configure 'Comp2': No such peer.
2.089 [ ERROR  ][Logger] Failed to load a component: aborting kick-start.   
 
Can you help me please? I need an example with 2 components connected through ROS topics.
Thank you.
Selma.

Connection between components doesn't work

On Tuesday 02 August 2011 16:16:45 selma [dot] kchir [..] ... wrote:
> Hello,
> I'm trying to create 2 OROCOS components and to make a connection between
> them using ROS. So, I've created 2 files : component1.cpp and
> component2.cpp and an XML file to define a mapping between them. The
> structure of those components looks like :
> &#10;&gt; class Component1 : public RTT::TaskContext {&#10;&gt; private:&#10;&gt;   OutputPort&lt;std_msgs::Float64&gt; outportDistance;&#10;&gt;   InputPort&lt;sensor_msgs::LaserScan&gt; inport_laser;&#10;&gt;   InputPort&lt;sensor_msgs::Range&gt; inport_infrared_left;&#10;&gt;   InputPort&lt;sensor_msgs::Range&gt; inport_infrared_right;&#10;&gt; public:&#10;&gt;   Component1(const std::string&amp; name):&#10;&gt;     TaskContext(name),&#10;&gt;     inport_laser(&quot;laser_in&quot;),&#10;&gt;     inport_infrared_left(&quot;infrared_left_in&quot;),&#10;&gt;     inport_infrared_right(&quot;infrared_right_in&quot;),&#10;&gt;     outportDistance(&quot;VS_out&quot;)&#10;&gt;   {&#10;&gt;       ports()-&gt;addPort(inport_laser);&#10;&gt;             ports()-&gt;addPort(inport_infrared_left);&#10;&gt;             ports()-&gt;addPort(inport_infrared_right);&#10;&gt;            ports()-&gt;addPort(outportDistance);&#10;&gt;   }&#10;&gt;   ~Component1() {}&#10;&gt; private:&#10;&gt;   void updateHook() {&#10;&gt;     //...&#10;&gt;       }&#10;&gt; };&#10;&gt; &#10;&gt; ORO_CREATE_COMPONENT(Component1)&#10;&gt; [\code]&#10;&gt; &#10;&gt; [code]&#10;&gt; class Component2 : public RTT::TaskContext {&#10;&gt; private:&#10;&gt;   InputPort&lt;std_msgs::Float64&gt; inport;&#10;&gt;   OutputPort&lt;geometry_msgs::Twist&gt; outport;&#10;&gt; &#10;&gt; public:&#10;&gt;   Component2(const std::string&amp; name):&#10;&gt;     TaskContext(name),&#10;&gt;     inport(&quot;Distance_in&quot;),&#10;&gt;     outport(&quot;twist_out&quot;)&#10;&gt;   {&#10;&gt;     ports()-&gt;addPort(inport);&#10;&gt;     ports()-&gt;addPort(outport);&#10;&gt;   }&#10;&gt;   ~Component2() {}&#10;&gt; private:&#10;&gt;   void updateHook() {&#10;&gt;     //...&#10;&gt;   }&#10;&gt; };&#10;&gt; ORO_CREATE_COMPONENT(Component2)&#10;&gt; [\code]&#10;&gt; &#10;&gt; Component2 uses a value returned by component1. To realize the mapping&#10;&gt; between those components, I&#039;ve configured an XML file: [code]&#10;&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&gt; &lt;!DOCTYPE properties SYSTEM &quot;cpf.dtd&quot;&gt;&#10;&gt; &lt;properties&gt;&#10;&gt; &lt;simple name=&quot;Import&quot;&#10;&gt; type=&quot;string&quot;&gt;&lt;value&gt;2ComponentsExample&lt;/value&gt;&lt;/simple&gt;&#10;&gt; &#10;&gt; &lt;struct name=&quot;VS_Connection&quot; type=&quot;ConnPolicy&quot;&gt;&#10;&gt;   &lt;simple name=&quot;type&quot; type=&quot;short&quot;&gt;&lt;value&gt;0&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;size&quot; type=&quot;short&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;transport&quot; type=&quot;short&quot;&gt;&lt;value&gt;3&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;name_id&quot; type=&quot;string&quot;&gt;&lt;value&gt;float_rtt&lt;/value&gt;&lt;/simple&gt;&#10;&gt; &lt;/struct&gt;&#10;&gt; &#10;&gt; &lt;struct name=&quot;ROSConTwistOut&quot; type=&quot;ConnPolicy&quot;&gt;&#10;&gt;   &lt;simple name=&quot;type&quot; type=&quot;short&quot;&gt;&lt;value&gt;0&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;size&quot; type=&quot;short&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;transport&quot; type=&quot;short&quot;&gt;&lt;value&gt;3&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;name_id&quot;&#10;&gt; type=&quot;string&quot;&gt;&lt;value&gt;/ATRV/Motion_Controller&lt;/value&gt;&lt;/simple&gt; &lt;/struct&gt;&#10;&gt; &lt;struct name=&quot;ROSConLaserIn&quot; type=&quot;ConnPolicy&quot;&gt;&#10;&gt;   &lt;simple name=&quot;type&quot; type=&quot;short&quot;&gt;&lt;value&gt;0&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;size&quot; type=&quot;short&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;transport&quot; type=&quot;short&quot;&gt;&lt;value&gt;3&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;name_id&quot; type=&quot;string&quot;&gt;&lt;value&gt;/ATRV/Sick&lt;/value&gt;&lt;/simple&gt;&#10;&gt; &lt;/struct&gt;&#10;&gt; &lt;struct name=&quot;ROSConInfraRedLeftIn&quot; type=&quot;ConnPolicy&quot;&gt;&#10;&gt;   &lt;simple name=&quot;type&quot; type=&quot;short&quot;&gt;&lt;value&gt;0&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;size&quot; type=&quot;short&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;transport&quot; type=&quot;short&quot;&gt;&lt;value&gt;3&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;name_id&quot;&#10;&gt; type=&quot;string&quot;&gt;&lt;value&gt;/ATRV/InfraRedLeft&lt;/value&gt;&lt;/simple&gt; &lt;/struct&gt;&#10;&gt; &lt;struct name=&quot;ROSConInfraRedRightIn&quot; type=&quot;ConnPolicy&quot;&gt;&#10;&gt;   &lt;simple name=&quot;type&quot; type=&quot;short&quot;&gt;&lt;value&gt;0&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;size&quot; type=&quot;short&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;transport&quot; type=&quot;short&quot;&gt;&lt;value&gt;3&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;name_id&quot;&#10;&gt; type=&quot;string&quot;&gt;&lt;value&gt;/ATRV/InfraRedRight&lt;/value&gt;&lt;/simple&gt; &lt;/struct&gt;&#10;&gt; &#10;&gt; &#10;&gt; &lt;struct name=&quot;Comp2&quot; type=&quot;Component2&quot;&gt;&#10;&gt;   &lt;struct name=&quot;Activity&quot; type=&quot;PeriodicActivity&quot;&gt;&#10;&gt;     &lt;simple name=&quot;Period&quot; type=&quot;double&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;     &lt;simple name=&quot;Priority&quot; type=&quot;short&quot;&gt;&lt;value&gt;0&lt;/value&gt;&lt;/simple&gt;&#10;&gt;     &lt;simple name=&quot;Scheduler&quot;&#10;&gt; type=&quot;string&quot;&gt;&lt;value&gt;ORO_SCHED_RT&lt;/value&gt;&lt;/simple&gt; &lt;/struct&gt;&#10;&gt;   &lt;simple name=&quot;AutoConf&quot; type=&quot;boolean&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;AutoStart&quot; type=&quot;boolean&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt; &#10;&gt;   &lt;struct name=&quot;Ports&quot; type=&quot;PropertyBag&quot;&gt;&#10;&gt;     &lt;simple name=&quot;Distance_in&quot; type=&quot;string&quot;&gt;&lt;value&gt; VS_Connection&#10;&gt; &lt;/value&gt;&lt;/simple&gt; &lt;simple name=&quot;twist_out&quot; type=&quot;string&quot;&gt;&lt;value&gt;&#10;&gt; ROSConTwistOut &lt;/value&gt;&lt;/simple&gt; &lt;/struct&gt;&#10;&gt; &#10;&gt;   &lt;struct name=&quot;Peers&quot; type=&quot;PropertyBag&quot;&gt;&#10;&gt;     &lt;simple type=&quot;string&quot;&gt; &lt;value&gt; Comp1 &lt;/value&gt; &lt;/simple&gt;&#10;&gt;   &lt;/struct&gt;&#10;&gt; &#10;&gt; &lt;/struct&gt;&#10;&gt; &#10;&gt; &lt;struct name=&quot;Comp1&quot; type=&quot;Component1&quot;&gt;&#10;&gt;     &lt;struct name=&quot;Activity&quot; type=&quot;PeriodicActivity&quot;&gt;&#10;&gt;     &lt;simple name=&quot;Period&quot; type=&quot;double&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;     &lt;simple name=&quot;Priority&quot; type=&quot;short&quot;&gt;&lt;value&gt;0&lt;/value&gt;&lt;/simple&gt;&#10;&gt;     &lt;simple name=&quot;Scheduler&quot;&#10;&gt; type=&quot;string&quot;&gt;&lt;value&gt;ORO_SCHED_RT&lt;/value&gt;&lt;/simple&gt; &lt;/struct&gt;&#10;&gt;   &lt;simple name=&quot;AutoConf&quot; type=&quot;boolean&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt;   &lt;simple name=&quot;AutoStart&quot; type=&quot;boolean&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/simple&gt;&#10;&gt; &#10;&gt;   &lt;struct name=&quot;Ports&quot; type=&quot;PropertyBag&quot;&gt;&#10;&gt;     &lt;simple name=&quot;VS_out&quot; type=&quot;string&quot;&gt;&lt;value&gt; VS_Connection&#10;&gt; &lt;/value&gt;&lt;/simple&gt; &lt;simple name=&quot;laser_in&quot; type=&quot;string&quot;&gt;&lt;value&gt;&#10;&gt; ROSConLaserIn &lt;/value&gt;&lt;/simple&gt; &lt;simple name=&quot;infrared_left_in&quot;&#10;&gt; type=&quot;string&quot;&gt;&lt;value&gt; ROSConInfraRedLeftIn &lt;/value&gt;&lt;/simple&gt; &lt;simple&#10;&gt; name=&quot;infrared_right_in&quot; type=&quot;string&quot;&gt;&lt;value&gt; ROSConInfraRedRightIn&#10;&gt; &lt;/value&gt;&lt;/simple&gt; &lt;/struct&gt;&#10;&gt; &lt;/struct&gt;&#10;&gt; &lt;/properties&gt;&#10;&gt; [\code]&#10;&gt; &#10;&gt; While compiling, I got this message : &quot;multiple definition of&#10;&gt; `createComponent&#039; &quot; So I removed ORO_CREATE_COMPONENT(Component2) from&#10;&gt; Component2.cpp.&#10;&#10;Which is wrong. You should have used in your CMakeLists.txt file this:&#10;orocos_component( Component1.cpp )&#10;orocos_component( Component2.cpp )&#10;&#10;Which creates 2 component libraries.&#10;&#10;&gt; &#10;&gt; After creating the ROS node and after the &quot;make&quot; command, when I try&#10;&gt; &quot;rosrun ocl deployer-gnulinux -s example.xml&quot; I got those errors :&#10;&gt; &#10;&gt; 0.409 [ ERROR  ][TinyDemarshaller] Could not load example.xml Error: Failed&#10;&gt; to open file 0.409 [ ERROR  ][DeploymentComponent::loadComponents] Some&#10;&gt; error occured while parsing example.xml 0.409 [ ERROR  ][Logger] Failed to&#10;&gt; load a component: aborting kick-start.&#10;&#10;This error is related to opening the file, not to an XML error.&#10;&#10;&gt; &#10;&gt; So I removed:&#10;&gt;   &lt;struct name=&quot;Peers&quot; type=&quot;PropertyBag&quot;&gt;&#10;&gt;     &lt;simple type=&quot;string&quot;&gt; &lt;value&gt; Comp1 &lt;/value&gt; &lt;/simple&gt;&#10;&gt;   &lt;/struct&gt;&#10;&gt; from the xml file in a structure Comp2.&#10;&#10;That was actually correct, although you must remove the spaces around the &#10;Comp1 value.&#10;&#10;&gt; &#10;&gt; But I still have errors:&#10;&gt; Unable to create Orocos Component &#039;Component2&#039;: unknown component type.&#10;&#10;Will be fixed if you put the component in different libraries as shown above.&#10;&#10;&gt; 2.083 [ Warning][DeploymentComponent::loadComponents] Could not configure&#10;&gt; &#039;Comp2&#039;: No such peer. 2.089 [ ERROR  ][Logger] Failed to load a&#10;&gt; component: aborting kick-start.&#10;&gt; &#10;&gt; Can you help me please? I need an example with 2 components connected&#10;&gt; through ROS topics. Thank you.&#10;&gt; Selma.&#10;&#10;The easiest way is *not* to use XML but to use an RTT script &#10;http://www.orocos.org/wiki/orocos/toolchain/getting-started/toolchain-&#10;tutorials/configuring-and-starting-components-orocos   (or Lua script &#10;http://www.orocos.org/wiki/orocos/toolchain/orocostoolchainluacookbook ).&#10;&#10;For connecting ports using ros topics in scripts or XML see &#10;http://www.ros.org/wiki/rtt_ros_integration&#10;&#10;Peter&#10;

Connection between components doesn't work

Thank you Peter, I will try to apply what you told me to do on my example. I hope that it will work.

Thank you again. Selma.