Skip to content
Snippets Groups Projects
Commit fa8892ce authored by Matthew Hansen's avatar Matthew Hansen Committed by Matt Hansen
Browse files

Remove navigate_to_pose from updown test

parent 29f97126
No related branches found
No related tags found
No related merge requests found
......@@ -22,72 +22,6 @@
using namespace std::chrono_literals;
struct xytheta
{
double x;
double y;
double theta;
};
void nav_to_poses(const char * nav_type_arg,
nav2_lifecycle_manager::LifecycleManagerClient & client)
{
if (nav_type_arg != nullptr) {
std::string nav_type(nav_type_arg);
// Create a set of target poses across the map
std::vector<xytheta> target_poses;
target_poses.push_back({-2.0, -0.5, 0});
target_poses.push_back({0.94, -0.55, 0});
target_poses.push_back({1.7, 0.5, 1.4});
target_poses.push_back({0.97, 1.68, 2.94});
target_poses.push_back({0.02, 1.74, -2.9});
xytheta & initial_pose = target_poses[0];
// Set the robot's starting pose (approximately where it comes up in gazebo)
client.set_initial_pose(initial_pose.x, initial_pose.y, initial_pose.theta);
if (nav_type == "iterative") {
// In the iterative case, navigate through all of the poses (but skip the
// first one, which is the initial pose)
for (std::vector<xytheta>::size_type i = 1; i < target_poses.size(); i++) {
auto pose = target_poses[i];
if (!client.navigate_to_pose(pose.x, pose.y, pose.theta)) {
RCLCPP_ERROR(rclcpp::get_logger("test_updown"), "Navigation failed!");
break;
}
}
} else if (nav_type == "random") {
// In the random case, navigate to randomly-selected poses from the target_poses
// collection
// Get set up to generate random indices
std::random_device r;
std::default_random_engine e1(r());
std::uniform_int_distribution<int> uniform_dist(0, target_poses.size() - 1);
for (int i = 0, cur_index = 0; i < 10; i++) {
// Get a random index that is not the current one (so we can navigate
// to a pose different than our current location)
int next_index = 0;
do {
next_index = uniform_dist(r);
} while (next_index == cur_index);
// Grab the pose for that index and start the navigation
auto pose = target_poses[next_index];
if (!client.navigate_to_pose(pose.x, pose.y, pose.theta)) {
RCLCPP_ERROR(rclcpp::get_logger("test_updown"), "Navigation failed!");
break;
}
}
} else {
RCLCPP_ERROR(rclcpp::get_logger("test_updown"),
"Unrecognized navigation type: %s, no navigation performed", nav_type);
}
}
}
int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);
......@@ -120,20 +54,17 @@ int main(int argc, char ** argv)
RCLCPP_ERROR(rclcpp::get_logger("test_updown"), "System startup failed");
test_passed = false;
}
else {
// Parse the command line options
char * nav_type_arg = rcutils_cli_get_option(argv, argv + argc, "-t");
nav_to_poses(nav_type_arg, client);
}
// Shut down the nav2 system, bringing it to the FINALIZED state
client.shutdown();
if (test_passed)
{
RCLCPP_INFO(rclcpp::get_logger("test_updown"), "TEST PASSED!");
RCLCPP_INFO(rclcpp::get_logger("test_updown"),
"**************************************************** TEST PASSED!");
} else {
RCLCPP_INFO(rclcpp::get_logger("test_updown"), "TEST FAILED!");
RCLCPP_INFO(rclcpp::get_logger("test_updown"),
"**************************************************** TEST FAILED!");
}
rclcpp::shutdown();
return 0;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment