apps
sm-cli
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
23
int
commandExportRawlog
()
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())
return
printCommandsExportRawlog
(
true
);
28
29
// Take second unlabeled argument:
30
const
std::string
file = lstCmds.at(1);
31
32
const
mrpt::maps::CSimpleMap sm =
read_input_sm_from_cli
(file);
33
34
const
auto
outFil =
cli
->arg_output.getValue();
35
36
mrpt::obs::CRawlog rawlog;
37
38
for
(
const
auto
& [kf, sf, twist] : sm)
39
{
40
ASSERT_(kf);
41
ASSERT_(sf);
42
43
std::optional<mrpt::Clock::time_point> timestamp;
44
45
mrpt::obs::CSensoryFrame outSF;
46
// regular observations:
47
outSF += *sf;
48
49
for
(
const
auto
& o : *sf)
50
{
51
if
(o->timestamp == mrpt::system::InvalidTimeStamp())
continue
;
52
if
(!timestamp)
53
{
54
timestamp = o->timestamp;
55
break
;
56
}
57
}
58
59
// plus:
60
// 1) Robot pose:
61
// 2) Twist:
62
{
63
auto
obsPose = mrpt::obs::CObservationRobotPose::Create();
64
if
(timestamp) obsPose->timestamp = *timestamp;
65
obsPose->sensorLabel =
"pose"
;
66
obsPose->pose.copyFrom(*kf);
67
outSF.insert(obsPose);
68
}
69
if
(twist.has_value())
70
{
71
auto
obsTwist = mrpt::obs::CObservationComment::Create();
72
if
(timestamp) obsTwist->timestamp = *timestamp;
73
obsTwist->sensorLabel =
"twist"
;
74
std::stringstream ss;
75
ss <<
"Twist stored in the simplemap keyframe:\n"
<< twist->asString();
76
77
obsTwist->text = ss.str();
78
outSF.insert(obsTwist);
79
}
80
81
rawlog.insert(outSF);
82
}
83
84
std::cout <<
"Saving rawlog with "
<< rawlog.size() <<
" entries to: '"
<< outFil <<
"'"
85
<< std::endl;
86
87
rawlog.saveToRawLogFile(outFil);
88
89
return
0;
90
}
91
92
int
printCommandsExportRawlog
(
bool
showErrorMsg)
93
{
94
if
(showErrorMsg)
95
{
96
setConsoleErrorColor
();
97
std::cerr <<
"Error: missing or unknown subcommand.\n"
;
98
setConsoleNormalColor
();
99
}
100
101
fprintf(
102
stderr,
103
R
"XXX(Usage:
104
105
sm-cli export-rawlog <filename.simplemap> --output <OUTPUT.rawlog>
106
107
)XXX");
108
109
return
showErrorMsg ? 1 : 0;
110
}
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:92
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:113
sm-cli.h
setConsoleNormalColor
void setConsoleNormalColor()
Definition:
sm-cli-main.cpp:48
setConsoleErrorColor
void setConsoleErrorColor()
Definition:
sm-cli-main.cpp:43
mp2p_icp
Author(s):
autogenerated on Mon May 26 2025 02:45:50