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 GenericUpdater::GenericUpdater(std::vector<UpdateConfig> update_configs_vector,
00036 operation_mode::device_update_state::DeviceUpdateState update_state)
00037 : nh_tilde("~"), which_data_to_request(0), update_state(update_state), update_configs_vector(
00038 update_configs_vector)
00039 {
00040 mutex = boost::shared_ptr<boost::mutex>(new boost::mutex());
00041
00042 BOOST_FOREACH(UpdateConfig config, update_configs_vector)
00043 {
00044 if (config.when_to_update == -2.0)
00045 {
00046 initialization_configs_vector.push_back(config);
00047 }
00048 else if (config.when_to_update != -1.0)
00049 {
00050 double tmp_dur = config.when_to_update;
00051 ros::Duration duration(tmp_dur);
00052
00053 timers.push_back(
00054 nh_tilde.createTimer(
00055 duration,
00056 boost::bind(&GenericUpdater::timer_callback, this, _1,
00057 static_cast<FROM_MOTOR_DATA_TYPE>(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
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 GenericUpdater::~GenericUpdater()
00074 {
00075 }
00076
00077 void GenericUpdater::timer_callback(const ros::TimerEvent& event, FROM_MOTOR_DATA_TYPE 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
00089
00090
00091
00092
00093