kuka-isir / rtt_lwr

OROCOS/ROS components for light weight robots at ISIR

Home Page:http://rtt-lwr.rtfd.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rosnode to orocos component

cfpperche2 opened this issue · comments

Hello, I need help to transform a node ros into a component orocos.
Why I need is turn this ros node file to a component orocos.

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include "RoadLineProcessing.hpp"

int main(int argc, char **argv)
{
  ros::init(argc, argv, "image_listener");
  ros::NodeHandle nh;

  image_transport::ImageTransport it(nh);
  RoadLineProcessing myRoad(nh);
  image_transport::Subscriber sub = it.subscribe("/image_raw", 1,boost::bind(&RoadLineProcessing::imageCallback, &myRoad, _1));
  ros::spin();
  return 0;
}

Exists any way to do this ?

Thanks.

class MyNode: public RTT::TaskContext
{
   MyNode(const std::string& name):
    RTT::TaskContext(name)
    {
       this->ports()->addPort("image_in",port_image_in).doc("The orocos input port");
    };
   void updateHook()
   {
      sensor_msgs::Image img;
      port_image_in.read(image);
   }
}

And in the orocos script :

import("rtt_ros")
ros.import("rtt_sensor_msgs")
# Load your component , configure it, and then
stream("my_component.image_in", ros.comm.topic("/image_raw"))
my_component.start()

Does that answer your question ?

Thanks for helping me,

This, does not do anything when I run my component

What I need do to convert this line?

image_transport::Subscriber sub = it.subscribe("/image_raw", 1,boost::bind(&RoadLineProcessing::imageCallback, &myRoad, _1));

RoadLineProcessing is a nodehandle class

RoadLineProcessing(ros::NodeHandle nh);

My component

TaskCamera::TaskCamera(std::string const& name) :
   RTT::TaskContext(name)
{
    RTT::log(RTT::Info) << "TaskCamera Constructor up !" << RTT::endlog();

    non_rt_ros_nh_.reset(new ros::NodeHandle(""));
    non_rt_ros_nh_->setCallbackQueue(&non_rt_ros_queue_);
    this->non_rt_ros_queue_thread_ =
            boost::thread( boost::bind( &TaskCamera::serviceNonRtRosQueue,this ) );

    it_.reset(new image_transport::ImageTransport(*non_rt_ros_nh_));
    myRoad_.reset(new RoadLineProcessing(*non_rt_ros_nh_));

    this->ports()->addPort("image_in", port_image_in).doc("The orocos input port");
}

void TaskCamera::updateHook()
{
    RTT::log(RTT::Info) << "TaskCamera updateHook up!" << RTT::endlog();
    sensor_msgs::Image image;
    port_image_in.read(image);
}
import("rtt_ros")
// Need rtt_rosnode so ros::init is called
ros.import("rtt_rosnode")
ros.import("rtt_sensor_msgs")
ros.import("vilma_camera")
loadComponent("task_camera", "VILMA::TaskCamera")
setActivity("task_camera", 0.001, 20, ORO_SCHED_RT)
stream("task_camera.image_in", ros.comm.topic("/image_raw"))
task_camera.configure()
task_camera.start()

I can't understand what I need to do with RoadLineProcessing::imageCallback inside my orocos component and what to do with myRoad_ and it_ nodes that was created in my constructor

I'm based my constructor in this example

interesting... the ros_control components should work the same way.
do you have a link to your code ?

I'm closing the issue as I suppose it is now unrelevant (?)