Discussion:
ROS & Qt - no callbacks
Peter Müller
2009-08-19 23:23:30 UTC
Permalink
Hi,

I have written a simple Qt GUI, which is supposed receive sensor_msgs::LaserScan messages.
The GUI is developed in Eclipse using qmake. The rest of my Application, which sends out the LaserScans is using rosmake. The compilation works and the GUI connects successfully to roscore and subscribes.
The following code is used to start the application:

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  ros::init(argc, argv, "RosGUI");
  RosGUI w;
  w.init();
  w.show();
  return a.exec();
}

RosGUI methods to subscribe and receive callbacks:

class RosGUI {

ros::NodeHandle handle;
ros::Subscriber laserDataSub;

void RosGUI::init()
{
  laserDataSub = handle.subscribe(LASER_DATA_KEY, 1, &RosGUI::laserScanCallback, this);
}

void RosGUI::laserScanCallback(const sensor_msgs::LaserScanConstPtr& msg)
{
  //never called
}

};

My problem is that RosGUI::laserScanCallback is never called.

I usually use ros::spin() event loop in the main-method for the callbacks in my other nodes.
Is that the problem?
Josh Faust
2009-08-19 23:30:08 UTC
Permalink
Yes -- you'll need to either add a ros::spinOnce() in a Qt Timer, or start a
thread to call ros::spin() -- in this case the callbacks will happen from
that other thread.

Josh
Post by Peter Müller
Hi,
I have written a simple Qt GUI, which is supposed receive
sensor_msgs::LaserScan messages.
The GUI is developed in Eclipse using qmake. The rest of my Application,
which sends out the LaserScans is using rosmake. The compilation works and
the GUI connects successfully to roscore and subscribes.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ros::init(argc, argv, "RosGUI");
RosGUI w;
w.init();
w.show();
return a.exec();
}
class RosGUI {
ros::NodeHandle handle;
ros::Subscriber laserDataSub;
void RosGUI::init()
{
laserDataSub = handle.subscribe(LASER_DATA_KEY, 1,
&RosGUI::laserScanCallback, this);
}
void RosGUI::laserScanCallback(const sensor_msgs::LaserScanConstPtr& msg)
{
//never called
}
};
My problem is that RosGUI::laserScanCallback is never called.
I usually use ros::spin() event loop in the main-method for the callbacks
in my other nodes.
Is that the problem?
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
ros-users mailing list
https://lists.sourceforge.net/lists/listinfo/ros-users
Klaus Petersen
2009-08-20 02:33:32 UTC
Permalink
It might be preferable to completely separate the gui and the ros part
of the program. That means have a thread call spin and handle the
callbacks and then save the information in a data structure that is
synchronized to the main (gui) thread by QMutex. I would think that
otherwise you might end up having performance issues if you do things
involving more computation / higher framerates.

Klaus
Post by Josh Faust
Yes -- you'll need to either add a ros::spinOnce() in a Qt Timer, or
start a thread to call ros::spin() -- in this case the callbacks will
happen from that other thread.
Josh
Hi,
I have written a simple Qt GUI, which is supposed receive
sensor_msgs::LaserScan messages.
The GUI is developed in Eclipse using qmake. The rest of my
Application, which sends out the LaserScans is using rosmake. The
compilation works and the GUI connects successfully to roscore and
subscribes.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ros::init(argc, argv, "RosGUI");
RosGUI w;
w.init();
w.show();
return a.exec();
}
class RosGUI {
ros::NodeHandle handle;
ros::Subscriber laserDataSub;
void RosGUI::init()
{
laserDataSub = handle.subscribe(LASER_DATA_KEY, 1,
&RosGUI::laserScanCallback, this);
}
void RosGUI::laserScanCallback(const sensor_msgs::LaserScanConstPtr& msg)
{
//never called
}
};
My problem is that RosGUI::laserScanCallback is never called.
I usually use ros::spin() event loop in the main-method for the
callbacks in my other nodes.
Is that the problem?
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
ros-users mailing list
https://lists.sourceforge.net/lists/listinfo/ros-users
------------------------------------------------------------------------
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
------------------------------------------------------------------------
_______________________________________________
ros-users mailing list
https://lists.sourceforge.net/lists/listinfo/ros-users
Loading...