29 #include "nav_msgs/GetPlan.h" 30 #include "geometry_msgs/PoseStamped.h" 31 #include "geometry_msgs/Point.h" 33 #include "urdf/model.h" 34 #include "urdf_model/joint.h" 38 #include <kdl_parser/kdl_parser.hpp> 39 #include <kdl/chain.hpp> 40 #include <kdl/chainfksolver.hpp> 41 #include <kdl/chainfksolverpos_recursive.hpp> 49 double mOmegaPan_, mOmegaTilt_, mOmegaRot_, tolerance_, speedFactorPTU_,speedFactorBaseMove_,speedFactorBaseRot_, mSigma_;
50 bool useGlobalPlanner_;
54 n.
getParam(
"speedFactorPTU", speedFactorPTU_);
55 n.
getParam(
"speedFactorBaseMove", speedFactorBaseMove_);
56 n.
getParam(
"speedFactorBaseRot", speedFactorBaseRot_);
58 n.
getParam(
"useGlobalPlanner", useGlobalPlanner_);
62 if (useGlobalPlanner_)
88 std::string strMap_, strMild_base_, strMild_ptu_base_link_, strMild_ptu_pan_link_, strMild_ptu_pan_link_rotated_, strMild_ptu_tilt_link_,
89 strMild_ptu_tilt_link_rotated_, strMild_camera_mount_link_, strMild_camera_left_, strMild_camera_right;
92 n.
getParam(
"ptu_base_frame", strMild_ptu_base_link_);
93 n.
getParam(
"ptu_pan_frame", strMild_ptu_pan_link_);
94 n.
getParam(
"ptu_pan_frame_rotated", strMild_ptu_pan_link_rotated_);
95 n.
getParam(
"ptu_tilt_frame", strMild_ptu_tilt_link_);
96 n.
getParam(
"ptu_tilt_frame_rotated", strMild_ptu_tilt_link_rotated_);
97 n.
getParam(
"camera_mount_frame", strMild_camera_mount_link_);
98 n.
getParam(
"camera_left_frame", strMild_camera_left_);
99 n.
getParam(
"camera_right_frame", strMild_camera_right);
131 geometry_msgs::Pose robotPose;
134 robotPose.position.x = transform.
getOrigin()[0];
135 robotPose.position.
y = transform.
getOrigin()[1];
136 robotPose.position.
z = transform.
getOrigin()[2];
143 geometry_msgs::Pose cameraPose;
146 cameraPose.position.x = transform.
getOrigin()[0];
147 cameraPose.position.
y = transform.
getOrigin()[1];
148 cameraPose.position.
z = transform.
getOrigin()[2];
176 int8_t occupancyValue =
mMapHelperPtr->getRaytracingMapOccupancyValue(pos);
178 return mMapHelperPtr->isOccupancyValueAcceptable(occupancyValue);
188 n.
param(
"colThresh", colThresh, 40.0);
209 if (path.poses.empty())
215 int lastPose = path.poses.size()-1;
216 float distanceToLastPoint = sqrt(pow(targetPosition.x - path.poses[lastPose].pose.position.x, 2) + pow(targetPosition.y - path.poses[lastPose].pose.position.y, 2));
218 mDebugHelperPtr->write(std::stringstream() <<
"Actual position: " << path.poses[lastPose].pose.position.x <<
", " << path.poses[lastPose].pose.position.y,
221 return distanceToLastPoint < 0.01f;
230 geometry_msgs::Point sourcePoint, targetPoint;
231 sourcePoint.x = sourceMILDRobotState->x;
232 sourcePoint.y = sourceMILDRobotState->y;
234 targetPoint.x = targetMILDRobotState->x;
235 targetPoint.y = targetMILDRobotState->y;
240 float movementCosts = std::exp(-pow((distance-0.0), 2.0)/(2.0*pow(
mSigma, 2.0)));
241 return movementCosts;
249 float panDiff = targetMILDRobotState->
pan - sourceMILDRobotState->pan;
256 float ptuPanCosts = fabs(panDiff)/ panSpan;
258 return 1.0 - ptuPanCosts;
265 float tiltDiff = targetMILDRobotState->
tilt - sourceMILDRobotState->tilt;
272 float ptuTiltCosts = fabs(tiltDiff)/ tiltSpan;
274 return 1.0 - ptuTiltCosts;
284 if (fabs(targetMILDRobotState->y - sourceMILDRobotState->y) < 0.00001 && fabs(targetMILDRobotState->x - sourceMILDRobotState->x) < 0.00001) {
285 float rotDiff = targetMILDRobotState->
rotation - sourceMILDRobotState->rotation;
287 rotationCosts = std::min((
float)fabs(rotDiff), (
float)(2.0
f*M_PI-fabs(rotDiff)))/ (2.0 * M_PI);
291 float angleBetweenPoints = std::atan2(targetMILDRobotState->y - sourceMILDRobotState->y, targetMILDRobotState->x - sourceMILDRobotState->x);
292 if(angleBetweenPoints < 0.0) angleBetweenPoints += 2.0 * M_PI;
294 float sourceRotDiff = sourceMILDRobotState->rotation - angleBetweenPoints;
295 float targetRotDiff = targetMILDRobotState->rotation - angleBetweenPoints;
297 rotationCosts = std::min((
float)fabs(sourceRotDiff), (
float)(2.0
f*M_PI-fabs(sourceRotDiff)))
298 + std::min((
float)fabs(targetRotDiff), (
float)(2.0
f*M_PI-fabs(targetRotDiff)));
299 rotationCosts /= 2.0 * M_PI;
302 return 1.0 - rotationCosts;
312 mDebugHelperPtr->write(std::stringstream() <<
"Calculate path from (" << sourcePosition.x <<
", " 313 << sourcePosition.y <<
") to (" << targetPosition.x <<
", "<< targetPosition.y <<
")",
318 if (!path.poses.empty())
320 unsigned int size = path.poses.size();
322 for (
unsigned int i = 0; i < size ; i++)
324 mDebugHelperPtr->write(std::stringstream() <<
"Path (" << path.poses[i].pose.position.x <<
", " << path.poses[i].pose.position.y <<
")",
328 distance += sqrt(pow(sourcePosition.x - path.poses[0].pose.position.x, 2) + pow(sourcePosition.y - path.poses[0].pose.position.y, 2));
330 for (
unsigned int i = 0; i < size - 1 ; i++)
332 distance += sqrt(pow(path.poses[i].pose.position.x - path.poses[i+1].pose.position.x, 2) + pow(path.poses[i].pose.position.y - path.poses[i+1].pose.position.y, 2));
338 ROS_ERROR(
"Could not get navigation path..");
343 distance = sqrt(pow(sourcePosition.x -targetPosition.x, 2) + pow(sourcePosition.y - targetPosition.y, 2));
347 << sqrt(pow(sourcePosition.x -targetPosition.x, 2) + pow(sourcePosition.y - targetPosition.y, 2)),
358 nav_msgs::Path
MILDRobotModel::getNavigationPath(
const geometry_msgs::Point &sourcePosition,
const geometry_msgs::Point &targetPosition,
double sourceRotationBase,
double targetRotationBase)
362 nav_msgs::GetPlan srv;
365 srv.request.start.pose.position = sourcePosition;
366 srv.request.goal.pose.position = targetPosition;
367 Eigen::Quaterniond sourceRotationEigen(Eigen::AngleAxisd(sourceRotationBase,Eigen::Vector3d::UnitZ()));
368 Eigen::Quaterniond targetRotationEigen(Eigen::AngleAxisd(targetRotationBase,Eigen::Vector3d::UnitZ()));
369 geometry_msgs::Quaternion sourceRotation;
370 sourceRotation.w = sourceRotationEigen.w();
371 sourceRotation.x = sourceRotationEigen.x();
372 sourceRotation.y = sourceRotationEigen.y();
373 sourceRotation.z = sourceRotationEigen.z();
374 geometry_msgs::Quaternion targetRotation;
375 targetRotation.w = targetRotationEigen.w();
376 targetRotation.x = targetRotationEigen.x();
377 targetRotation.y = targetRotationEigen.y();
378 targetRotation.z = targetRotationEigen.z();
379 srv.request.start.pose.orientation = sourceRotation;
380 srv.request.goal.pose.orientation = targetRotation;
386 path = srv.response.plan;
391 ROS_ERROR(
"Failed to call the global planner.");
460 geometry_msgs::Pose myPose;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool isPositionReachable(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition)
float speedFactorBaseMove
std::string mFrameName_mild_ptu_tilt_link_rotated
std::string mFrameName_map
boost::tuple< float, float > mRotationLimits
static double degToRad(double input)
float getBase_TranslationalMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
Calculates the movement costs from sourceRobotState to targetRobotState. Returns -1 if pose is not re...
ros::ServiceClient navigationCostClient
std::string mFrameName_mild_base
static boost::shared_ptr< DebugHelper > getInstance()
float getBase_RotationalMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
bool call(MReq &req, MRes &res)
ROSCPP_DECL const std::string & getName()
void setRotationAngleLimits(float minAngleDegrees, float maxAngleDegrees)
sets the angle limits of the rotation angle.
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
geometry_msgs::Pose calculateCameraPose(const RobotStatePtr &sourceRobotState)
Uses a given RobotState to calculate the camera frame.
void setPanAngleLimits(float minAngleDegrees, float maxAngleDegrees)
sets the angle limits of the pan angle.
DebugHelperPtr mDebugHelperPtr
static SimpleVector3 getVisualAxis(const SimpleQuaternion &orientation)
SimpleVector3 SimpleSphereCoordinates
boost::shared_ptr< MapHelper > MapHelperPtr
bool isPoseReachable(const SimpleVector3 &position, const SimpleQuaternion &orientation)
geometry_msgs::Pose getRobotPose()
double distance(double x0, double y0, double x1, double y1)
nav_msgs::Path getNavigationPath(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition, double sourceRotationBase, double targetRotationBase)
TFSIMD_FORCE_INLINE const tfScalar & z() const
boost::tuple< float, float > mPanLimits
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
static void quaternionTFToMsg(const Quaternion &bt, geometry_msgs::Quaternion &msg)
this namespace contains all generally usable classes.
void setTiltAngleLimits(float minAngleDegrees, float maxAngleDegrees)
sets the angle limits of the tilt angle.
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::string mFrameName_mild_ptu_pan_link_rotated
tf::TransformListener listener
float getPTU_TiltMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
float getDistance(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition)
static SimpleSphereCoordinates convertC2S(const SimpleVector3 &cartesian)
converts cartesian coordinates to sphere coordinates
std::string mFrameName_mild_ptu_pan_link
std::string mFrameName_mild_ptu_base_link
boost::tuple< float, float > mTiltLimits
void initMapHelper()
Init MapHelper if it is not initialized yet.
std::string mFrameName_mild_camera_left
std::string mFrameName_mild_ptu_tilt_link
bool getParam(const std::string &key, std::string &s) const
geometry_msgs::Pose getCameraPose()
MILDRobotModel()
constructor of the MILDRobotModel
bool isPositionAllowed(const geometry_msgs::Point &position)
virtual ~MILDRobotModel()
destructor of the MILDRobotModel
std::string mFrameName_mild_camera_right
float getPTU_PanMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
MapHelperPtr mMapHelperPtr
Eigen::Quaternion< Precision > SimpleQuaternion
std::string mFrameName_mild_camera_mount_link
RobotModel generalizes a robot model.