sm-cli-export-rawlog.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2023 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mrpt/core/exceptions.h>
11 #include <mrpt/maps/CSimpleMap.h>
12 #include <mrpt/obs/CObservationComment.h>
13 #include <mrpt/obs/CObservationRobotPose.h>
14 #include <mrpt/obs/CRawlog.h>
15 #include <mrpt/poses/CPose3DInterpolator.h>
16 
17 #include <sstream>
18 
19 #include "sm-cli.h"
20 
21 static int printCommandsExportRawlog(bool showErrorMsg);
22 
24 {
25  const auto& lstCmds = cli->argCmd.getValue();
26  if (cli->argHelp.isSet()) return printCommandsExportRawlog(false);
27  if (lstCmds.size() != 2 || !cli->arg_output.isSet())
28  return printCommandsExportRawlog(true);
29 
30  // Take second unlabeled argument:
31  const std::string file = lstCmds.at(1);
32 
33  const mrpt::maps::CSimpleMap sm = read_input_sm_from_cli(file);
34 
35  const auto outFil = cli->arg_output.getValue();
36 
37  mrpt::obs::CRawlog rawlog;
38 
39  for (const auto& [kf, sf, twist] : sm)
40  {
41  ASSERT_(kf);
42  ASSERT_(sf);
43 
44  std::optional<mrpt::Clock::time_point> timestamp;
45 
46  mrpt::obs::CSensoryFrame outSF;
47  // regular observations:
48  outSF += *sf;
49 
50  for (const auto& o : *sf)
51  {
52  if (o->timestamp == mrpt::system::InvalidTimeStamp()) continue;
53  if (!timestamp)
54  {
55  timestamp = o->timestamp;
56  break;
57  }
58  }
59 
60  // plus:
61  // 1) Robot pose:
62  // 2) Twist:
63  {
64  auto obsPose = mrpt::obs::CObservationRobotPose::Create();
65  if (timestamp) obsPose->timestamp = *timestamp;
66  obsPose->sensorLabel = "pose";
67  obsPose->pose.copyFrom(*kf);
68  outSF.insert(obsPose);
69  }
70  if (twist.has_value())
71  {
72  auto obsTwist = mrpt::obs::CObservationComment::Create();
73  if (timestamp) obsTwist->timestamp = *timestamp;
74  obsTwist->sensorLabel = "twist";
75  std::stringstream ss;
76  ss << "Twist stored in the simplemap keyframe:\n"
77  << twist->asString();
78 
79  obsTwist->text = ss.str();
80  outSF.insert(obsTwist);
81  }
82 
83  rawlog.insert(outSF);
84  }
85 
86  std::cout << "Saving rawlog with " << rawlog.size() << " entries to: '"
87  << outFil << "'" << std::endl;
88 
89  rawlog.saveToRawLogFile(outFil);
90 
91  return 0;
92 }
93 
94 int printCommandsExportRawlog(bool showErrorMsg)
95 {
96  if (showErrorMsg)
97  {
99  std::cerr << "Error: missing or unknown subcommand.\n";
101  }
102 
103  fprintf(
104  stderr,
105  R"XXX(Usage:
106 
107  sm-cli export-rawlog <filename.simplemap> --output <OUTPUT.rawlog>
108 
109 )XXX");
110 
111  return showErrorMsg ? 1 : 0;
112 }
commandExportRawlog
int commandExportRawlog()
Definition: sm-cli-export-rawlog.cpp:23
cli
std::unique_ptr< cli_flags > cli
Definition: sm-cli-main.cpp:29
printCommandsExportRawlog
static int printCommandsExportRawlog(bool showErrorMsg)
Definition: sm-cli-export-rawlog.cpp:94
testing::internal::string
::std::string string
Definition: gtest.h:1979
read_input_sm_from_cli
mrpt::maps::CSimpleMap read_input_sm_from_cli(const std::string &inFile)
Definition: sm-cli-main.cpp:119
sm-cli.h
setConsoleNormalColor
void setConsoleNormalColor()
Definition: sm-cli-main.cpp:49
setConsoleErrorColor
void setConsoleErrorColor()
Definition: sm-cli-main.cpp:43


mp2p_icp
Author(s):
autogenerated on Wed Oct 23 2024 02:45:41