Gazebo | Ignition | Community
Ask Your Question
1

How to replace event::ConnectionPtr with ros::Timer in gazebo model PLUGIN?

asked 2015-04-27 09:09:25 -0600

winston gravatar image

In example gazebo plugin codes, it seems to be a convention that people use event::Events::ConnectWorldUpdateBegin to let a portion of code running every simulation iteration. For example, I want to let World_Model::update method to run like this:

update_connection_ = event::Events::ConnectWorldUpdateBegin(boost::bind(&World_Model::update, this));

where update_connection is of type event::ConnectionPtr. But since I have 3 plugins in the model and it makes the simulaton work pretty slow, I don't want all the 3 plugins to run every simulation iteration. Instead, I think I can use ros::Timer as an alternative solution, so I modify the code above to this:

worldmodel_update_timer_ = nh->createTimer(ros::Duration(0.03),&World_Model::update,this);

where worldmodelupdatetimer is of type ros::Timer. Now the running of method World_Model::update does not depend on gazebo simulation update rate; now it should be handled by ros::Timer. I think it should work, but there comes the compilation error:

    In file included from /usr/include/boost/bind/mem_fn.hpp:215:0,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/bind/bind.hpp:26,
                 from /usr/include/boost/bind.hpp:22,
                 from /home/winston/workspace/nubot_gazebo_ws_extended/src/nubot/nubot_simulation/world_model/include/nubot/world_model/world_model.h:4,
                 from /home/winston/workspace/nubot_gazebo_ws_extended/src/nubot/nubot_simulation/world_model/src/world_model.cpp:5:
/usr/include/boost/bind/mem_fn_template.hpp: In instantiation of ‘R boost::_mfi::mf0<R, T>::call(U&, const void*) const [with U = const ros::TimerEvent; R = void; T = nubot::World_Model]’:
/usr/include/boost/bind/mem_fn_template.hpp:63:38:   required from ‘R boost::_mfi::mf0<R, T>::operator()(const U&) const [with U = ros::TimerEvent; R = void; T = nubot::World_Model]’
/usr/include/boost/function/function_template.hpp:225:11:   required from ‘static void boost::detail::function::function_void_mem_invoker1<MemberPtr, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with MemberPtr = void (nubot::World_Model::*)(); R = void; T0 = const ros::TimerEvent&]’
/usr/include/boost/function/function_template.hpp:934:38:   required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = void (nubot::World_Model::*)(); R = void; T0 = const ros::TimerEvent&]’
/usr/include/boost/function/function_template.hpp:722:7:   required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = void (nubot::World_Model::*)(); R = void; T0 = const ros::TimerEvent&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1069:16:   required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = void (nubot::World_Model::*)(); R = void; T0 = const ros::TimerEvent&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/home/winston/workspace/nubot_gazebo_ws_extended/src/nubot/nubot_simulation/world_model/src/world_model.cpp:96:93:   required from here
/usr/include/boost/bind/mem_fn_template.hpp:40:43: error: no matching function for call to ‘get_pointer(const ros::TimerEvent&)’
         BOOST_MEM_FN_RETURN (get_pointer(u)->*f_)();
                                           ^
/usr/include/boost/bind/mem_fn_template.hpp:40:43: note ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2015-04-28 06:46:09 -0600

winston gravatar image

I finally find out the answer. Actually, I can safely replace event::ConnectionPtr with ros::Timer and let the method run every ros::Duration. The only problem is in the declaration and definition of the callback function.

In gazebo event::ConnectionPtr case, I define the method as:

void World_Model::update(void)

However, if I want to use ros::Timer, the method should be defined as:

void World_Model::update(const ros::TimerEvent& event)

That is to say, I have to put a ros::TimerEvent parameter to the update method.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2015-04-27 09:09:25 -0600

Seen: 1,021 times

Last updated: Apr 28 '15

Related questions