30 #include "nav_msgs/GetPlan.h" 31 #include "geometry_msgs/PoseStamped.h" 32 #include "geometry_msgs/Point.h" 34 #include "urdf/model.h" 35 #include "urdf_model/joint.h" 39 #include <kdl_parser/kdl_parser.hpp> 40 #include <kdl/chain.hpp> 41 #include <kdl/chainfksolver.hpp> 42 #include <kdl/chainfksolverpos_recursive.hpp> 50 double speedFactorPTU_,speedFactorBaseMove_,speedFactorBaseRot_;
51 n.
getParam(
"speedFactorPTU", speedFactorPTU_);
52 n.
getParam(
"speedFactorBaseMove", speedFactorBaseMove_);
53 n.
getParam(
"speedFactorBaseRot", speedFactorBaseRot_);
75 while (sphereCoords[2] < 0) { sphereCoords[2] += 2 * M_PI; }
76 while (sphereCoords[2] > 2 * M_PI) { sphereCoords[2] -= 2 * M_PI; }
80 double currentPhi = sourceMILDRobotState->pan;
81 double currentRho = sourceMILDRobotState->rotation;
83 mDebugHelperPtr->write(std::stringstream() <<
"Source robot state: (Pan: " << sourceMILDRobotState->pan
84 <<
", Tilt: " << sourceMILDRobotState->tilt
85 <<
", Rotation " << sourceMILDRobotState->rotation
86 <<
", X:" << sourceMILDRobotState->x
87 <<
", Y:" << sourceMILDRobotState->y <<
")",
89 mDebugHelperPtr->write(std::stringstream() <<
"Target View Position: " << position[0] <<
", " << position[1] <<
", " << position[2],
91 mDebugHelperPtr->write(std::stringstream() <<
"Target View Orientation: " << orientation.w() <<
", " << orientation.x() <<
", " << orientation.y()<<
", " << orientation.z(),
94 double alpha = sphereCoords[2] - currentPhi - currentRho;
95 alpha = alpha > M_PI ? alpha - 2 * M_PI : alpha;
96 alpha = alpha < -M_PI ? alpha + 2 * M_PI : alpha;
99 if (currentPhi < phiMin) {
100 if (currentPhi < phiMin - 10.0) {
101 ROS_WARN_STREAM(
"Initial Pan-Angle (" << currentPhi * (180/M_PI) <<
") was too small.");
107 if (currentPhi > phiMax) {
108 if (currentPhi > phiMax + 10.0) {
109 ROS_WARN_STREAM(
"Initial Pan-Angle (" << currentPhi * (180/M_PI) <<
") was too large.");
120 int glIdx[1+cols*rows];
121 int glColIdx[1+cols*rows];
122 double glCoef[1+cols*rows];
124 lp = glp_create_prob();
125 glp_set_prob_name(lp,
"angle_prob");
126 glp_set_obj_dir(lp, GLP_MIN);
128 glp_add_cols(lp, cols);
131 glp_set_col_name(lp, colIdx,
"x_pan+");
132 double maxPanPlus = fabs(phiMax - currentPhi);
133 glp_set_col_bnds(lp, colIdx, (maxPanPlus == 0.0 ? GLP_FX : GLP_DB), 0.0, maxPanPlus);
137 glp_set_col_name(lp, colIdx,
"x_pan-");
138 double maxPanMinus = fabs(currentPhi - phiMin);
139 glp_set_col_bnds(lp, colIdx, (maxPanMinus == 0.0 ? GLP_FX : GLP_DB), 0.0, maxPanMinus);
143 glp_set_col_name(lp, colIdx,
"x_rot+");
144 glp_set_col_bnds(lp, colIdx, GLP_DB, 0, M_PI);
148 glp_set_col_name(lp, colIdx,
"x_rot-");
149 glp_set_col_bnds(lp, colIdx, GLP_DB, 0.0, M_PI);
154 glp_add_rows(lp, rowIdx);
155 glp_set_row_name(lp, rowIdx,
"alpha");
156 glp_set_row_bnds(lp, rowIdx, GLP_FX, alpha, alpha);
159 glIdx[1] = 1; glColIdx[1] = 1; glCoef[1] = 1.0;
160 glIdx[2] = 1; glColIdx[2] = 2; glCoef[2] = -1.0;
161 glIdx[3] = 1; glColIdx[3] = 3; glCoef[3] = 1.0;
162 glIdx[4] = 1; glColIdx[4] = 4; glCoef[4] = -1.0;
165 glp_load_matrix(lp, 4, glIdx, glColIdx, glCoef);
167 glp_smcp *
param =
new glp_smcp();
168 glp_init_smcp(param);
169 param->msg_lev = GLP_MSG_OFF;
170 glp_simplex(lp, param);
172 int statusCode = glp_get_status(lp);
173 if (statusCode != GLP_OPT) {
174 ROS_ERROR(
"No optimal solution found - inverse kinematics");
177 double x_pan_plus = glp_get_col_prim(lp, 1);
178 double x_pan_minus = glp_get_col_prim(lp, 2);
179 double x_rot_plus = glp_get_col_prim(lp, 3);
180 double x_rot_minus = glp_get_col_prim(lp, 4);
186 targetMILDRobotState->pan = sourceMILDRobotState->pan + x_pan_plus - x_pan_minus;
189 if (targetMILDRobotState->pan < phiMin) {
190 if (targetMILDRobotState->pan < phiMin - 10.0) {
191 ROS_WARN_STREAM(
"Calculated Pan-Angle (" << targetMILDRobotState->pan * (180/M_PI) <<
") was too small.");
195 targetMILDRobotState->pan = phiMin;
197 if (targetMILDRobotState->pan > phiMax) {
198 if (targetMILDRobotState->pan > phiMax + 10.0) {
199 ROS_WARN_STREAM(
"Calculated Pan-Angle (" << targetMILDRobotState->pan * (180/M_PI) <<
") was too large.");
203 targetMILDRobotState->pan = phiMax;
207 targetMILDRobotState->rotation = sourceMILDRobotState->rotation + x_rot_plus - x_rot_minus;
208 while (targetMILDRobotState->rotation < 0) { targetMILDRobotState->rotation += 2 * M_PI; };
209 while (targetMILDRobotState->rotation > 2 * M_PI) { targetMILDRobotState->rotation -= 2 * M_PI; };
212 targetMILDRobotState->tilt = sphereCoords[1];
215 targetMILDRobotState->x = position[0];
216 targetMILDRobotState->y = position[1];
217 mDebugHelperPtr->write(std::stringstream() <<
"Target state: (Pan: " << targetMILDRobotState->pan
218 <<
", Tilt: " << targetMILDRobotState->tilt
219 <<
", Rotation " << targetMILDRobotState->rotation
220 <<
", X:" << targetMILDRobotState->x
221 <<
", Y:" << targetMILDRobotState->y <<
")",
224 return targetMILDRobotState;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
float speedFactorBaseMove
ros::ServiceClient navigationCostClient
MILDRobotModel implements a model of pan tilt unit robot.
static boost::shared_ptr< DebugHelper > getInstance()
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
DebugHelperPtr mDebugHelperPtr
static SimpleVector3 getVisualAxis(const SimpleQuaternion &orientation)
SimpleVector3 SimpleSphereCoordinates
MILDRobotModelWithApproximatedIK()
constructor of the MILDRobotModelWithApproximatedIK
RobotStatePtr calculateRobotState(const RobotStatePtr &sourceRobotState, const SimpleVector3 &position, const SimpleQuaternion &orientation)
calculates the target robot state
boost::tuple< float, float > mPanLimits
this namespace contains all generally usable classes.
#define ROS_WARN_STREAM(args)
static SimpleSphereCoordinates convertC2S(const SimpleVector3 &cartesian)
converts cartesian coordinates to sphere coordinates
virtual ~MILDRobotModelWithApproximatedIK()
destructor of the MILDRobotModelWithApproximatedIK
bool getParam(const std::string &key, std::string &s) const
Eigen::Quaternion< Precision > SimpleQuaternion