checkpoint_nav_goals_file.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <iri_checkpoint_nav/Checkpoint.h>
00003 #include <iri_checkpoint_nav/ActionCheckpointNav.h>
00004 
00005 #include <vector>
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 int main(int argc, char **argv)
00010 {
00011     ros::init(argc, argv, "checkpoint_marker_example");
00012     ros::NodeHandle n;
00013     ros::NodeHandle pn("~");
00014     int count = 0;
00015     std::string ref_frame;
00016     std::string input_file_path;
00017     bool invert_x, invert_y, first_value_is_y;
00018     char option;
00019 
00020     ROS_INFO("Starting importer");
00021 
00022     // wait a couple of seconds to give time to manager to be available
00023     // when using together
00024     sleep(2);
00025 
00026     // Get the file path from the param server
00027     if (! pn.getParam("checkpoints_file_path", input_file_path)){
00028         ROS_ERROR("Node need a param called checkpoints_file_path");
00029         return 1;
00030     }
00031 
00032     // Change first value by y instead of x
00033     pn.param<bool>("first_value_is_y", first_value_is_y, false);
00034 
00035     // Sometimes is needed to invert X and Y values
00036     pn.param<bool>("invert_x", invert_x, false);
00037     pn.param<bool>("invert_y", invert_y, false);
00038 
00039     // Ref frame can be readed from param server
00040     pn.param<std::string>("ref_frame", ref_frame, "/map");
00041 
00042     std::ifstream input_file;
00043     input_file.open(input_file_path.c_str());
00044 
00045     if (! input_file.good()) {
00046         ROS_ERROR("Input file not found: %s", input_file_path.c_str());
00047         return 1;
00048     }
00049 
00050     iri_checkpoint_nav::ActionCheckpointNav reset_msg, start_msg;
00051 
00052     reset_msg.request.action = iri_checkpoint_nav::ActionCheckpointNav::Request::RESET_CHECKPOINTS;
00053     start_msg.request.action = iri_checkpoint_nav::ActionCheckpointNav::Request::START_NAV;
00054 
00055     ros::ServiceClient add_client    = n.serviceClient<iri_checkpoint_nav::Checkpoint>
00056                                                                        ("add_nav_checkpoint");
00057 
00058     ros::ServiceClient action_client = n.serviceClient<iri_checkpoint_nav::ActionCheckpointNav>
00059                                                                     ("action_checkpoint_nav");
00060 
00061     action_client.call(reset_msg);
00062 
00063     while (input_file.good()) {
00064         iri_checkpoint_nav::Checkpoint checkpoint;
00065         double x,y;
00066         count++;
00067 
00068         // Check which value is the first
00069         if (first_value_is_y) {
00070             input_file >> y;
00071             input_file >> x;
00072         } else {
00073             input_file >> x;
00074             input_file >> y;
00075         }
00076 
00077         if (invert_x)
00078             x = -x;
00079 
00080         if (invert_y)
00081             y = -y;
00082 
00083         if (! input_file.good())
00084             break;
00085 
00086         std::cout << "Add checkpoint x: " << x << " y: " << y << std::endl;
00087 
00088         checkpoint.request.id         = count;
00089         checkpoint.request.ref_frame  = ref_frame;
00090         checkpoint.request.position.x = x;
00091         checkpoint.request.position.y = y;
00092         checkpoint.request.position.z = 0;
00093 
00094         add_client.call(checkpoint);
00095     }
00096 
00097     input_file.close();
00098     std::cout << "Any key to start navigation (c to cancel)? ";
00099     std::cin >> option;
00100 
00101     if (option == 'c')
00102         return 0;
00103 
00104     action_client.call(start_msg);
00105 
00106     return 0;
00107 }


iri_checkpoint_nav
Author(s): Jose Luis Rivero
autogenerated on Fri Dec 6 2013 22:56:28