Go to the documentation of this file.00001
00028 #include "sr_robot_lib/sensor_updater.hpp"
00029 #include <boost/foreach.hpp>
00030 #include <boost/thread/mutex.hpp>
00031 #include <boost/smart_ptr.hpp>
00032 #include <iostream>
00033 #include <vector>
00034
00035 namespace generic_updater
00036 {
00037 template<class CommandType>
00038 SensorUpdater<CommandType>::SensorUpdater(std::vector<UpdateConfig> update_configs_vector,
00039 operation_mode::device_update_state::DeviceUpdateState update_state)
00040 : GenericUpdater<CommandType>(update_configs_vector, update_state)
00041 {
00042 }
00043
00044 template<class CommandType>
00045 operation_mode::device_update_state::DeviceUpdateState SensorUpdater<CommandType>::build_init_command(
00046 CommandType *command)
00047 {
00048 if (!this->mutex->try_lock())
00049 {
00050 return this->update_state;
00051 }
00052
00053 if (this->update_state == operation_mode::device_update_state::INITIALIZATION)
00054 {
00055 if (this->initialization_configs_vector.size() > 0)
00056 {
00058
00059
00060 this->which_data_to_request++;
00061
00062 if (this->which_data_to_request >= this->initialization_configs_vector.size())
00063 {
00064 this->which_data_to_request = 0;
00065 }
00066
00067
00068 command->tactile_data_type = this->initialization_configs_vector[this->which_data_to_request].what_to_update;
00069 ROS_DEBUG_STREAM("Updating sensor initialization data type: " << command->tactile_data_type << " | [" <<
00070 this->which_data_to_request << "/" << this->initialization_configs_vector.size() << "] ");
00071 }
00072 }
00073 else
00074 {
00075
00076
00077
00078
00079 ROS_DEBUG_STREAM("Important data size: " << this->important_update_configs_vector.size());
00080
00081
00082 command->tactile_data_type = TACTILE_SENSOR_TYPE_WHICH_SENSORS;
00083 ROS_DEBUG_STREAM("Updating sensor initialization data type: " << command->tactile_data_type << " | [" <<
00084 this->which_data_to_request << "/" << this->important_update_configs_vector.size() << "] ");
00085 }
00086 this->mutex->unlock();
00087
00088 return this->update_state;
00089 }
00090
00091 template<class CommandType>
00092 operation_mode::device_update_state::DeviceUpdateState SensorUpdater<CommandType>::build_command(CommandType *command)
00093 {
00094 if (!this->mutex->try_lock())
00095 {
00096 return this->update_state;
00097 }
00098
00100
00101
00102 this->which_data_to_request++;
00103
00104 if (this->which_data_to_request >= this->important_update_configs_vector.size())
00105 {
00106 this->which_data_to_request = 0;
00107 }
00108
00109 if (!this->unimportant_data_queue.empty())
00110 {
00111
00112 command->tactile_data_type = this->unimportant_data_queue.front();
00113 this->unimportant_data_queue.pop();
00114
00115 ROS_DEBUG_STREAM("Updating sensor unimportant data type: " << command->tactile_data_type << " | queue size: " <<
00116 this->unimportant_data_queue.size());
00117 }
00118 else
00119 {
00120
00121 command->tactile_data_type = this->important_update_configs_vector[this->which_data_to_request].what_to_update;
00122 ROS_DEBUG_STREAM("Updating sensor important data type: " << command->tactile_data_type << " | [" <<
00123 this->which_data_to_request << "/" << this->important_update_configs_vector.size() << "] ");
00124 }
00125
00126 this->mutex->unlock();
00127
00128 return this->update_state;
00129 }
00130
00131 template<class CommandType>
00132 bool SensorUpdater<CommandType>::reset()
00133 {
00134
00135
00136 boost::mutex::scoped_lock l(*(this->mutex));
00137 for (unsigned int i = 0; i < 2; ++i)
00138 {
00139 this->unimportant_data_queue.push(TACTILE_SENSOR_TYPE_RESET_COMMAND);
00140 }
00141 return true;
00142 }
00143
00144
00145 template
00146 class SensorUpdater<ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_COMMAND>;
00147
00148 template
00149 class SensorUpdater<ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND>;
00150
00151 template
00152 class SensorUpdater<ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND>;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162