ros::Timer in ModelPlugin
Hi everyone!
I want to set a timer's callback for ModelPlugin. What is the better way to do it?
I tried such way but got error:
"error: invalid use of incomplete type ‘class ros::NodeHandle’ timer = nh->createTimer(ros::Duration(0.1), timerCallback);"
Code:
namespace gazebo
{
class VelodynePlugin : public ModelPlugin
{
...
private: ros::NodeHandlePtr nh;
ros::Timer timer;
public: void timerCallback()
{
cout << "Hi Vlad!" << endl;
}
public: virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
...
nh = boost::make_shared<ros::NodeHandle>();
timer = nh->createTimer(ros::Duration(0.1), timerCallback);
}
...
}
Where is a mistake?
Asked by Vlad222 on 2017-04-29 17:36:33 UTC
Answers
The error invalid use of incomplete type
means the compiler knows the class ros::NodeHandle
exists, but it doesn't have enough information about it to know how to call the createTimer
method. This happens when you have a forward declaration (A line looking like this class ros::NodeHandle;
) but not a class definition. The header containing the definition of ros::NodeHandle
hasn't been included. Add #include <ros/ros.h>
to the top of your file.
Asked by sloretz on 2017-05-01 09:04:54 UTC
Comments