27 #include "cartographer_ros_msgs/StartTrajectory.h" 28 #include "cartographer_ros_msgs/StatusCode.h" 29 #include "cartographer_ros_msgs/TrajectoryOptions.h" 30 #include "gflags/gflags.h" 34 "First directory in which configuration files are searched, " 35 "second is always the Cartographer installation to allow " 36 "including files from there.");
38 "Basename, i.e. not containing any directory prefix, of the " 39 "configuration file.");
41 DEFINE_string(initial_pose,
"",
"Starting pose of a new trajectory");
49 std::vector<std::string>{FLAGS_configuration_directory});
50 const std::string code =
52 auto lua_parameter_dictionary =
54 code, std::move(file_resolver));
55 if (!FLAGS_initial_pose.empty()) {
56 auto initial_trajectory_pose_file_resolver =
59 std::vector<std::string>{FLAGS_configuration_directory});
60 auto initial_trajectory_pose =
62 "return " + FLAGS_initial_pose,
63 std::move(initial_trajectory_pose_file_resolver));
65 initial_trajectory_pose.get());
74 node_handle.
serviceClient<cartographer_ros_msgs::StartTrajectory>(
76 cartographer_ros_msgs::StartTrajectory srv;
78 srv.request.topics.laser_scan_topic = node_handle.
resolveName(
80 srv.request.topics.multi_echo_laser_scan_topic =
82 srv.request.topics.point_cloud2_topic =
85 srv.request.topics.odometry_topic =
88 if (!client.
call(srv)) {
92 if (srv.response.status.code != cartographer_ros_msgs::StatusCode::OK) {
93 LOG(ERROR) <<
"Error starting trajectory - message: '" 94 << srv.response.status.message
95 <<
"' (status code: " << std::to_string(srv.response.status.code)
99 LOG(INFO) <<
"Started trajectory " << srv.response.trajectory_id;
106 int main(
int argc,
char** argv) {
107 google::InitGoogleLogging(argv[0]);
108 google::SetUsageMessage(
110 "Convenience tool around the start_trajectory service. This takes a Lua " 111 "file that is accepted by the node as well and starts a new trajectory " 112 "using its settings.\n");
113 google::ParseCommandLineFlags(&argc, &argv,
true);
115 CHECK(!FLAGS_configuration_directory.empty())
116 <<
"-configuration_directory is missing.";
117 CHECK(!FLAGS_configuration_basename.empty())
118 <<
"-configuration_basename is missing.";
120 ::ros::init(argc, argv,
"cartographer_start_trajectory");
124 int exit_code = cartographer_ros::Run() ? 0 : 1;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
_Unique_if< T >::_Single_object make_unique(Args &&... args)
bool call(MReq &req, MRes &res)
constexpr char kImuTopic[]
constexpr char kLaserScanTopic[]
std::tuple< NodeOptions, TrajectoryOptions > LoadOptions(const std::string &configuration_directory, const std::string &configuration_basename)
std::string resolveName(const std::string &name, bool remap=true) const
static std::unique_ptr< LuaParameterDictionary > NonReferenceCounted(const std::string &code, std::unique_ptr< FileResolver > file_resolver)
std::string GetFileContentOrDie(const std::string &basename) override
constexpr char kStartTrajectoryServiceName[]
constexpr char kOdometryTopic[]
TrajectoryOptions CreateTrajectoryOptions(::cartographer::common::LuaParameterDictionary *const lua_parameter_dictionary)
constexpr char kMultiEchoLaserScanTopic[]
void Run(const std::string &configuration_directory, const std::string &configuration_basename)
constexpr char kPointCloud2Topic[]
int main(int argc, char **argv)
DEFINE_string(configuration_directory, "", "First directory in which configuration files are searched, " "second is always the Cartographer installation to allow " "including files from there.")
cartographer_ros_msgs::TrajectoryOptions ToRosMessage(const TrajectoryOptions &options)