Go to the documentation of this file.00001 #include "robodyn_controllers/RosMsgTreeId.h"
00002
00003 RosMsgTreeId::RosMsgTreeId()
00004 {
00005 }
00006
00007 RosMsgTreeId::~RosMsgTreeId()
00008 {
00009 }
00010
00011 int RosMsgTreeId::setBaseFrame(const r2_msgs::StringArray& baseMsg, std::string& baseFrame)
00012 {
00013
00014 unsigned int n = baseMsg.data.size();
00015
00016 if (n > 0)
00017 {
00018 if (baseFrame == baseMsg.data[0])
00019 {
00020 n = -1;
00021 }
00022 else
00023 {
00024 baseFrame = baseMsg.data[0];
00025 }
00026 }
00027
00028 return n;
00029 }
00030
00031 void RosMsgTreeId::setJointData(const sensor_msgs::JointState& actualState,
00032 const sensor_msgs::JointState& desiredStates,
00033 const r2_msgs::WrenchState& wrenchState,
00034 JointDynamicsData& jd)
00035 {
00036 JntDynData data;
00037 std::map<std::string, JntDynData>::iterator jntIt;
00038 std::map<std::string, KDL::Wrench>::iterator wrenchIt;
00039
00040 if (desiredStates.name.empty())
00041 {
00042
00043 jntIt = jd.jointDataMap.begin();
00044 data.vel = 0.0;
00045 data.acc = 0.0;
00046
00047 while (jntIt != jd.jointDataMap.end())
00048 {
00049 jntIt->second = data;
00050 ++jntIt;
00051 }
00052 }
00053 else
00054 {
00055
00056 for (unsigned int j = 0; j < desiredStates.name.size(); ++j)
00057 {
00058 jntIt = jd.jointDataMap.find(desiredStates.name[j]);
00059
00060 if (jntIt != jd.jointDataMap.end())
00061 {
00062
00063 data.vel = desiredStates.velocity[j];
00064 data.acc = desiredStates.effort[j];
00065
00066
00067 jntIt->second = data;
00068 }
00069 }
00070 }
00071
00072
00073 for (unsigned int i = 0; i < wrenchState.name.size(); ++i)
00074 {
00075 wrenchIt = jd.extForceMap.find(wrenchState.name[i]);
00076
00077 if (wrenchIt != jd.extForceMap.end())
00078 {
00079 wrenchIt->second.force(0) = -wrenchState.wrench[i].force.x;
00080 wrenchIt->second.force(1) = -wrenchState.wrench[i].force.y;
00081 wrenchIt->second.force(2) = -wrenchState.wrench[i].force.z;
00082 wrenchIt->second.torque(0) = -wrenchState.wrench[i].torque.x;
00083 wrenchIt->second.torque(1) = -wrenchState.wrench[i].torque.y;
00084 wrenchIt->second.torque(2) = -wrenchState.wrench[i].torque.z;
00085 }
00086 }
00087
00088
00089 for (unsigned int i = 0; i < actualState.name.size(); ++i)
00090 {
00091
00092 jntIt = jd.jointDataMap.find(actualState.name[i]);
00093
00094 if (jntIt != jd.jointDataMap.end())
00095 {
00096 jntIt->second.pos = actualState.position[i];
00097 }
00098 }
00099
00100 return;
00101 }
00102
00103 void RosMsgTreeId::getJointCommand(const JointDynamicsData& jd, sensor_msgs::JointState& tauFF)
00104 {
00105 std::map<std::string, double>::const_iterator it = jd.jointTorqueCommandMap.begin();
00106
00107
00108 tauFF.header.stamp = ros::Time::now();
00109
00110
00111 tauFF.name.resize(jd.jointTorqueCommandMap.size());
00112 tauFF.effort.resize(jd.jointTorqueCommandMap.size());
00113
00114
00115
00116 unsigned int i = 0;
00117
00118 while (it != jd.jointTorqueCommandMap.end())
00119 {
00120 tauFF.name[i] = it->first;
00121 tauFF.effort[i] = -it->second;
00122 i++;
00123 it++;
00124 }
00125
00126 return;
00127 }
00128
00129 void RosMsgTreeId::getSegmentForces(const JointDynamicsData& jd, r2_msgs::WrenchState& segForceMsg)
00130 {
00131 std::map<std::string, KDL::Wrench>::const_iterator it = jd.segForceMap.begin();
00132
00133
00134 segForceMsg.header.stamp = ros::Time::now();
00135
00136
00137 segForceMsg.name.clear();
00138 segForceMsg.wrench.clear();
00139
00140 geometry_msgs::Wrench wData;
00141
00142 while (it != jd.segForceMap.end())
00143 {
00144 segForceMsg.name.push_back(it->first);
00145
00146 wData.force.x = it->second.force(0);
00147 wData.force.y = it->second.force(1);
00148 wData.force.z = it->second.force(2);
00149 wData.torque.x = it->second.torque(0);
00150 wData.torque.y = it->second.torque(1);
00151 wData.torque.z = it->second.torque(2);
00152 segForceMsg.wrench.push_back(wData);
00153
00154 it++;
00155 }
00156
00157 return;
00158 }
00159
00160 void RosMsgTreeId::setEmptyTorqueMsg(const JointDynamicsData& jd, sensor_msgs::JointState& tauFF)
00161 {
00162 std::map<std::string, double>::const_iterator it = jd.jointTorqueCommandMap.begin();
00163
00164
00165 tauFF.header.stamp = ros::Time::now();
00166
00167
00168 tauFF.name.resize(jd.jointTorqueCommandMap.size());
00169 tauFF.effort.resize(jd.jointTorqueCommandMap.size());
00170
00171
00172
00173 unsigned int i = 0;
00174
00175 while (it != jd.jointTorqueCommandMap.end())
00176 {
00177 tauFF.name[i] = it->first;
00178 tauFF.effort[i] = 0.0;
00179 i++;
00180 it++;
00181 }
00182
00183 return;
00184 }
00185
00186 void RosMsgTreeId::getJointInertias(const JointDynamicsData& jd, sensor_msgs::JointState& Hv)
00187 {
00188 std::map<std::string, double>::const_iterator it = jd.jointInertiaMap.begin();
00189
00190
00191 Hv.header.stamp = ros::Time::now();
00192
00193
00194 Hv.name.resize(jd.jointInertiaMap.size());
00195 Hv.position.resize(jd.jointInertiaMap.size());
00196
00197
00198 unsigned int i = 0;
00199
00200 while (it != jd.jointInertiaMap.end())
00201 {
00202 Hv.name[i] = it->first;
00203 Hv.position[i] = it->second;
00204 i++;
00205 it++;
00206 }
00207
00208 return;
00209 }
00210
00211 bool RosMsgTreeId::GetCompletionMessage(RateLimiter& yl, r2_msgs::StringArray& completionMsg)
00212 {
00213 if (yl.getCompletionCondition() == 1)
00214 {
00215 completionMsg.header.stamp = ros::Time::now();
00216 completionMsg.data.clear();
00217 completionMsg.data.push_back("base_frame");
00218
00219 return true;
00220 }
00221
00222 return false;
00223
00224 }