ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Subscriber from a class compile problems

asked 2012-04-06 13:32:06 -0600

allenh1 gravatar image

updated 2014-01-28 17:11:54 -0600

ngrennan gravatar image

I am having issues with using a subscriber callback in QT. I have adapted the example as follows:

bool QNode::init() {
    ros::init(init_argc,init_argv,"qtest");
    if ( ! ros::master::check() ) {
        return false;
    }
    ros::start(); // explicitly needed since our nodehandle is going out of scope.
    ros::NodeHandle n;
    // Add your ros communications here.
    //chatter_publisher = n.advertise<std_msgs::String>("chatter", 1000);
    goalReciever = n.subscribe("goalString", 100, &QNode::callback);
    start();
    return true;
}

inline pcl::PointXY stringToPoint(std::string sPoint)
{
    //incoming point will be in the format: "(x, y, theta)"
    QString qSPoint = sPoint.c_str();
    QString x = qSPoint.section(',', 0, 0);
    x.remove(0, 1);
    QString y = qSPoint.section(',', 1, 1);
    y.remove(0, 1);
    QString t = qSPoint.section(',', 2, 2);
    t.remove(0, 1); t.remove(t.size() - 1, 1);

    pcl::PointXY toReturn;
    toReturn.x = x.toDouble();
    toReturn.y = y.toDouble();

    return toReturn;
}//converts a string to a PCL point.

void QNode::callback(std_msgs::String msg)
{
    goal = stringToPoint(msg.data);
}

namespace qtest {

/*****************************************************************************
** Class
*****************************************************************************/

class QNode : public QThread {
    Q_OBJECT
public:
    QNode(int argc, char** argv );
    virtual ~QNode();
    bool init();
    bool init(const std::string &master_url, const std::string &host_url);
    void run();

    /*********************
    ** Logging
    **********************/
    enum LogLevel {
             Debug,
             Info,
             Warn,
             Error,
             Fatal
     };

    QStringListModel* loggingModel() { return &logging_model; }
    void log( const LogLevel &level, const std::string &msg);

signals:
    void loggingUpdated();
    void rosShutdown();

private:
    int init_argc;
        void callback(std_msgs::String);
    char** init_argv;
        pcl::PointXY goal;
    ros::Publisher chatter_publisher;
        ros::Subscriber goalReciever;
    QStringListModel logging_model;
};

}  // namespace qtest

Of course there are more methods, but I have omitted them from the above. It refuses to compile with errors showing up in the subscriber line. The qt compiler says that the way I set it up doesn't fit the template. How do I fix this?

Thanks,

-Hunter A.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-04-06 14:40:10 -0600

Eric Perko gravatar image

You need to pass a pointer to your class object. For example, something like

  goalReciever = n.subscribe("goalString", 100, &QNode::callback, this);

See the roscpp docs for details on valid callback signatures.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-04-06 13:32:06 -0600

Seen: 830 times

Last updated: Apr 06 '12