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