generic_updater.cpp
Go to the documentation of this file.
00001 
00029 #include "sr_robot_lib/generic_updater.hpp"
00030 #include <boost/foreach.hpp>
00031 #include <iostream>
00032 #include <vector>
00033 
00034 namespace generic_updater
00035 {
00036   template<class CommandType>
00037   GenericUpdater<CommandType>::GenericUpdater(std::vector<UpdateConfig> update_configs_vector,
00038                                               operation_mode::device_update_state::DeviceUpdateState update_state)
00039           : nh_tilde("~"), which_data_to_request(0), update_state(update_state), update_configs_vector(
00040           update_configs_vector)
00041   {
00042     mutex = boost::shared_ptr<boost::mutex>(new boost::mutex());
00043 
00044     BOOST_FOREACH(UpdateConfig config, update_configs_vector)
00045           {
00046             if (config.when_to_update == -2.0)
00047             {
00048               initialization_configs_vector.push_back(config);
00049             }
00050             else if (config.when_to_update != -1.0)
00051             {
00052               double tmp_dur = config.when_to_update;
00053               ros::Duration duration(tmp_dur);
00054 
00055               timers.push_back(
00056                       nh_tilde.createTimer(
00057                               duration,
00058                               boost::bind(&GenericUpdater::timer_callback, this, _1, config.what_to_update)));
00059             }
00060             else
00061             {
00062               important_update_configs_vector.push_back(config);
00063             }
00064           }
00065     ROS_DEBUG_STREAM("Init config size" << initialization_configs_vector.size());
00066     ROS_DEBUG_STREAM("Important config size" << important_update_configs_vector.size());
00067 
00068     // If there isn't any command defined as initializingcommand (-2), state switches to operation
00069     if (initialization_configs_vector.size() == 0)
00070     {
00071       ROS_INFO_STREAM("No init command. Switching to operation");
00072       update_state = operation_mode::device_update_state::OPERATION;
00073     }
00074   }
00075 
00076   template<class CommandType>
00077   void GenericUpdater<CommandType>::timer_callback(const ros::TimerEvent &event, int32u data_type)
00078   {
00079     if (update_state == operation_mode::device_update_state::OPERATION)
00080     {
00081       boost::mutex::scoped_lock l(*mutex);
00082       unimportant_data_queue.push(data_type);
00083 
00084       ROS_DEBUG_STREAM("Timer: data type = " << data_type << " | queue size: " << unimportant_data_queue.size());
00085     }
00086   }
00087 
00088   // Only to ensure that the template class is compiled for the types we are interested in
00089   template
00090   class GenericUpdater<ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_COMMAND>;
00091 
00092   template
00093   class GenericUpdater<ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND>;
00094 
00095   template
00096   class GenericUpdater<ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND>;
00097 }  // end namespace generic_updater
00098 
00099 /* For the emacs weenies in the crowd.
00100  Local Variables:
00101  c-basic-offset: 2
00102  End:
00103  */


sr_robot_lib
Author(s): Ugo Cupcic, Toni Oliver
autogenerated on Mon Jul 1 2019 20:06:26