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


sr_robot_lib
Author(s): Ugo Cupcic, Toni Oliver
autogenerated on Thu Aug 27 2015 15:16:37