Gazebo | Ignition | Community
Ask Your Question
0

ros::Timer in ModelPlugin

asked 2017-04-29 17:36:33 -0600

Vlad222 gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-05-01 09:04:54 -0600

sloretz gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-29 17:36:33 -0600

Seen: 759 times

Last updated: May 01 '17