Package-Identification-using-Turtlebot
Robots have been used to improve efficiency in a various tasks in warehouses such as package handling, identification and organization. This project aims to simulate the use of Turtlebot in identifying packages with QR codes, in a warehouse setting.
Public Member Functions | List of all members
PathPlanner Class Reference

Class PathPlanner has methods send goal points and initial pose of the turtlebot to move_base package. Once the packages are identified, this class prints the package IDs and locations. More...

#include <PathPlanner.hpp>

Public Member Functions

 PathPlanner (std::vector< std::vector< double >>)
 Constructor of the PathPlanner class. More...
 
 ~PathPlanner ()
 Destructor of the PathPlanner class. More...
 
ros::Publisher returnPublisher ()
 Method that returns publisher object. More...
 
std::vector< double > callPublisher (double, double, double)
 Method to call publishInitPose. More...
 
std::vector< std::string > callVision (std::vector< std::string >)
 Method to call callback function from QReader class. More...
 
std::vector< std::string > sendGoals ()
 Method to send goals to move_base action server. More...
 
int findPackage (std::vector< std::string >)
 Method to print the packIDs and their location where to find them. More...
 
std::string waitPackageDetection (std::string)
 Method to try again if the package detection is faulty. More...
 

Detailed Description

Class PathPlanner has methods send goal points and initial pose of the turtlebot to move_base package. Once the packages are identified, this class prints the package IDs and locations.

Constructor & Destructor Documentation

PathPlanner::PathPlanner ( std::vector< std::vector< double >>  )
explicit

Constructor of the PathPlanner class.

Parameters
pointsof type std::vector<std::vector<double>>
Returns
none
49  {
50  initPosePub = nh.advertise<geometry_msgs::PoseWithCovarianceStamped>(
51  "/initialpose", 1000);
52  move_base_msgs::MoveBaseGoal targetPose;
53  // Initialize the intial pose
54  initialPose.header.frame_id = "map";
55  initialPose.pose.pose.position.x = 0.0;
56  initialPose.pose.pose.position.y = 0.0;
57  initialPose.pose.pose.orientation.w = 1.0;
58  counter = 0;
59 
60  // Add the points to the goal vector
61  targetPose.target_pose.header.frame_id = "map";
62  targetPose.target_pose.header.stamp = ros::Time::now();
63  for (auto i = points.begin(); i != points.end() && counter < points.size();
64  i++) {
65  targetPose.target_pose.pose.position.x = (*i).at(0);
66  targetPose.target_pose.pose.position.y = (*i).at(1);
67  targetPose.target_pose.pose.orientation.z = (*i).at(2);
68  targetPose.target_pose.pose.orientation.w = (*i).at(3);
69  goal.push_back(targetPose);
70  }
71 }
PathPlanner::~PathPlanner ( )

Destructor of the PathPlanner class.

Parameters
none
Returns
none
73 {}

Member Function Documentation

std::vector< double > PathPlanner::callPublisher ( double  x,
double  y,
double  w 
)

Method to call publishInitPose.

Parameters
xof type double
yof type double
wof type double
Returns
initPose of type std::vector<double>
93  {
94  // Calls the private class (For rostest)
95  return publishInitPose(x, y, w);
96 }
std::vector< std::string > PathPlanner::callVision ( std::vector< std::string >  packID)

Method to call callback function from QReader class.

Parameters
objectof QReader class
packIDof type std::vector<std::string>
Returns
packID of type std::vector<std::string>
115  {
116  // Call image callback
117  ros::spinOnce();
118  // Get the updated result
119  std::vector<uint8_t> result = reader.returnBytes();
120  std::string str;
121  str.assign(result.begin(), result.end());
122  ROS_INFO("Package ID is: %s \n", str.c_str());
123 
124  packID.push_back(waitPackageDetection(str));
125 
126  return packID;
127 }
std::string waitPackageDetection(std::string)
Method to try again if the package detection is faulty.
Definition: PathPlanner.cpp:98
std::vector< uint8_t > returnBytes()
Function to get the extracted data array.
Definition: QReader.cpp:65
int PathPlanner::findPackage ( std::vector< std::string >  packID)

Method to print the packIDs and their location where to find them.

Parameters
packIDof type std::vector<std::string>
Returns
exit status of type int
162  {
163  auto j = goal.begin();
164  std::string result =
165  "\n*****************************\n******Package "
166  "Locations******\n*****************************\n";
167  for (auto i = packID.begin(); i != packID.end() && j != goal.end();
168  i++, j++) {
169  result += (*i) + " is in position x=" +
170  std::to_string((*j).target_pose.pose.position.x) +
171  " y = " + std::to_string((*j).target_pose.pose.position.y) + "\n";
172  }
173  ROS_INFO_STREAM(result);
174  ros::Duration(10).sleep();
175  return 0;
176 }
ros::Publisher PathPlanner::returnPublisher ( )

Method that returns publisher object.

Parameters
none
Returns
initPosePub of type ros::Publisher
75 { return initPosePub; }
std::vector< std::string > PathPlanner::sendGoals ( )

Method to send goals to move_base action server.

Parameters
none
Returns
packID of type std::vector<std::string>
129  {
130  actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> ac("move_base",
131  true);
132 
133  std::vector<std::string> packID;
134  // Wait for the action server to come up
135  while (!ac.waitForServer(ros::Duration(5.0))) {
136  ROS_INFO("Waiting for the move_base action server to come up");
137  }
138  // Publish initial position (x, y) and orientation quaternion of the
139  // Turtlebot. In this case (x, y) = (-3.0, -3.0) and w of quaternion = 1.0 (0
140  // degrees) All other parameters are 0.0 by default
141  publishInitPose(-3.0, -3.0, 1.0);
142  for (auto i = goal.begin(); i != goal.end() && counter < goal.size(); i++) {
143  ROS_INFO("Moving to goal %d \n", counter + 1);
144  // Send goal to move base
145  ac.sendGoal(*i);
146  ac.waitForResult();
147  if (ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) {
148  counter = counter + 1;
149  ROS_INFO_STREAM("Reached goal %d \n" << counter);
150  if (counter == goal.size()) {
151  break;
152  } else {
153  packID = callVision(packID);
154  }
155  } else {
156  ROS_WARN_STREAM("Failed to reach goal");
157  }
158  }
159  return packID;
160 }
std::vector< std::string > callVision(std::vector< std::string >)
Method to call callback function from QReader class.
Definition: PathPlanner.cpp:114
std::string PathPlanner::waitPackageDetection ( std::string  str)

Method to try again if the package detection is faulty.

Parameters
QReaderobject of QReader class
strof type string
Returns
none
98  {
99  // wait until package is detected
100  while (str.substr(0, 4) != "pack") {
101  ros::spinOnce();
102  std::vector<uint8_t> result = reader.returnBytes();
103  str.assign(result.begin(), result.end());
104  // Check if QR code is detected properly
105  if (str.substr(0, 4) == "pack") {
106  ROS_INFO("QR code detected! \n");
107  ROS_INFO("Package ID is: %s \n", str.c_str());
108  break;
109  }
110  }
111  return str;
112 }
std::vector< uint8_t > returnBytes()
Function to get the extracted data array.
Definition: QReader.cpp:65

The documentation for this class was generated from the following files: