23 :
DirectSearchHandler(), gridFilePath(gridFilePath), ptuTuplePtrVecPtr(), clearVision(0.0) {
30 double panMin, panMax;
31 double tiltMin, tiltMax;
33 nh.
getParam(
"pan_min_angle", panMin);
34 nh.
getParam(
"pan_max_angle", panMax);
35 nh.
getParam(
"tilt_min_angle", tiltMin);
36 nh.
getParam(
"tilt_max_angle", tiltMax);
40 ROS_DEBUG_STREAM(
"We got params panMin:" << panMin <<
", panMax: " << panMax <<
", tiltMin: " << tiltMin <<
", tiltMax: " << tiltMax <<
", fovH: " << fovH <<
", fovV :" <<fovV );
41 double rangeV = tiltMax - tiltMin;
48 double rangeH = panMax - panMin;
49 int countH = ceil(rangeH/fovH);
50 int countV = ceil(rangeV/fovV);
51 double stepH = rangeH/countH;
52 double stepV = rangeV/countV;
53 ROS_DEBUG_STREAM(
"We calculted stepH: " << stepH <<
", stepV: " << stepV <<
", rangeV: "<< rangeV <<
", rangeH: " << rangeH <<
", countV: " << countV <<
", countH: "<< countH);
56 for (
int i=1;i<=countH;i++) {
57 for (
int j=1;j<=countV;j++) {
59 ROS_DEBUG_STREAM(
"PTU tuple created : "<< panMin+i*stepH <<
" , " <<tiltMin+j*stepV);
76 std::ifstream ConfigFile(
gridFilePath.c_str(),std::ifstream::in);
81 std::vector<char> buffer((std::istreambuf_iterator<char>(ConfigFile)), std::istreambuf_iterator<char>());
82 buffer.push_back(
'\0');
84 rapidxml::xml_document<> doc;
85 doc.parse<0>(&buffer[0]);
87 std::vector<geometry_msgs::Pose> orderedGrid;
89 rapidxml::xml_node<> * root_node = doc.first_node(
"Posen");
90 for (rapidxml::xml_node<> * pose_node = root_node->first_node(
"Pose"); pose_node; pose_node = pose_node->next_sibling()) {
91 double X = boost::lexical_cast<
double>((pose_node->first_attribute(
"X")->value()));
92 double Y = boost::lexical_cast<
double>((pose_node->first_attribute(
"Y")->value()));
93 double Z = boost::lexical_cast<
double>((pose_node->first_attribute(
"Z")->value()));
94 geometry_msgs::Pose pose;
98 orderedGrid.push_back(pose);
99 ROS_DEBUG_STREAM(
"Got Pose from XML X : " << X <<
", Y : " << Y <<
", Z : " << Z);
106 geometry_msgs::Pose robotPose =
poseHelperPtr->getCurrentRobotPose();
107 double dist = DBL_MAX;
108 auto iter = orderedGrid.begin();
109 for (
auto it = orderedGrid.begin(); it != orderedGrid.end(); ++it) {
110 double currentDist =
poseHelperPtr->calculateDistance(*it, robotPose);
111 if (currentDist < dist) {
116 std::vector<geometry_msgs::Pose> temp;
117 if (iter != orderedGrid.begin()) {
118 for (
auto it = iter; it != orderedGrid.end(); ++it) {
121 for (
auto it = orderedGrid.begin(); it != iter; ++it) {
130 std::vector<geometry_msgs::Pose> returnPath = orderedGrid;
131 std::reverse(returnPath.begin(), returnPath.end());
133 std::vector<double> yawArray;
137 for (
auto it = orderedGrid.begin(); it != orderedGrid.end(); ++it) {
138 if (it != orderedGrid.end()-1) {
139 yaw =
getYaw(it->position,(it+1)->position);
140 ROS_DEBUG_STREAM(
"got yaw : " << yaw*57);
142 yaw =
getYaw(it->position,(orderedGrid.front()).position);
143 ROS_DEBUG_STREAM(
"got yaw : " << yaw*57);
145 yawArray.push_back(yaw);
146 for (
int i=0;i<rotationPerPose;i++) {
147 geometry_msgs::Pose robotPose;
149 robotPose.orientation = quat;
150 robotPose.position = it->position;
151 temp.push_back(robotPose);
154 ROS_DEBUG_STREAM(
"Begin calculation for return grid");
155 for (
auto it = returnPath.begin(); it != returnPath.end(); ++it) {
156 if (yawArray.back() > M_PI) {
157 yaw = yawArray.back() - M_PI;
158 ROS_DEBUG_STREAM(
"got yaw : " << yaw*57);
160 yaw = yawArray.back() + M_PI;
161 ROS_DEBUG_STREAM(
"got yaw : " << yaw*57);
164 for (
int i=0;i<rotationPerPose;i++) {
165 geometry_msgs::Pose robotPose;
167 robotPose.orientation = quat;
168 robotPose.position = it->position;
169 temp.push_back(robotPose);
174 for (
auto it = orderedGrid.begin()+1; it != orderedGrid.end(); ++it) {
179 for (
const geometry_msgs::Pose &pose : orderedGrid) {
182 ptuList->push_back(tuple);
185 PosePtr posePtr = boost::make_shared<geometry_msgs::Pose>(pose);
195 double yaw = atan2((pointB.y-pointA.y),(pointB.x-pointA.x));
197 yaw += 2.0f * M_PI - (90+this->
clearVision)*M_PI/180;
GridInitialisation(std::string gridFilePath)
boost::shared_ptr< RobotStatePtrVec > RobotStatePtrVecPtr
PoseHelperPtr poseHelperPtr
ROSCPP_DECL const std::string & getName()
boost::shared_ptr< PtuTuple > PtuTuplePtr
double getYaw(const geometry_msgs::Point &pointA, const geometry_msgs::Point &pointB) const
std::vector< PtuTuplePtr > PtuTuplePtrVec
virtual ~GridInitialisation()
double remainingPosesDistances
RobotStatePtrVecPtr posesToExplorePtr
std::vector< RobotStatePtr > RobotStatePtrVec
#define ROS_DEBUG_STREAM(args)
virtual bool resetHandler()
boost::shared_ptr< PtuTuplePtrVec > PtuTuplePtrVecPtr
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
bool getParam(const std::string &key, std::string &s) const
boost::shared_ptr< RobotState > RobotStatePtr
PtuTuplePtrVecPtr ptuTuplePtrVecPtr
#define ROS_ERROR_STREAM(args)