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 :
>

> 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.
 
Which is wrong. You should have used in your CMakeLists.txt file this:
orocos_component( Component1.cpp )
orocos_component( Component2.cpp )
 
Which creates 2 component libraries.
 
> 
> 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.
 
This error is related to opening the file, not to an XML error.
 
> 
> So I removed:
>   <struct name="Peers" type="PropertyBag">
>     <simple type="string"> <value> Comp1 </value> </simple>
>   </struct>
> from the xml file in a structure Comp2.
 
That was actually correct, although you must remove the spaces around the 
Comp1 value.
 
> 
> But I still have errors:
> Unable to create Orocos Component 'Component2': unknown component type.
 
Will be fixed if you put the component in different libraries as shown above.
 
> 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.
 
The easiest way is *not* to use XML but to use an RTT script 
http://www.orocos.org/wiki/orocos/toolchain/getting-started/toolchain-
tutorials/configuring-and-starting-components-orocos   (or Lua script 
http://www.orocos.org/wiki/orocos/toolchain/orocostoolchainluacookbook ).
 
For connecting ports using ros topics in scripts or XML see 
http://www.ros.org/wiki/rtt_ros_integration
 
Peter

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.