File: gz_log.hh

package info (click to toggle)
gazebo 9.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 115,400 kB
  • sloc: cpp: 356,787; xml: 20,974; ansic: 9,594; python: 2,417; sh: 395; ruby: 375; makefile: 62
file content (276 lines) | stat: -rw-r--r-- 10,141 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
 * Copyright (C) 2012 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
#ifndef GAZEBO_TOOLS_GZLOG_HH_
#define GAZEBO_TOOLS_GZLOG_HH_

#include <string>
#include <list>

#include <gazebo/physics/WorldState.hh>
#include "gz.hh"

namespace gazebo
{
  /// \brief Base class for all filters.
  class FilterBase
  {
    /// \brief Constructor
    /// \param[in] _xmlOutput True if the output should be in XML format.
    /// \param[in[ _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    public: FilterBase(bool _xmlOutput, const std::string &_stamp);

    /// \brief Output a line of data.
    /// \param[in] _stream The output stream.
    /// \param[in] _state Current state.
    /// \return Reference to the output stream.
    public: std::ostringstream &Out(std::ostringstream &_stream,
                const gazebo::physics::State &_state);

    /// \brief Filter a pose.
    /// \param[in] _pose The pose to filter.
    /// \param[in] _xmlName Name of the xml tag.
    /// \param[in] _filter The filter string [x,y,z,r,p,a].
    /// \param[in] _state Current state.
    /// \return Filtered pose string.
    public: std::string FilterPose(const ignition::math::Pose3d &_pose,
                const std::string &_xmlName,
                std::string _filter,
                const gazebo::physics::State &_state);

    /// \brief True if XML output is requested.
    protected: bool xmlOutput;

    /// \brief Time stamp type
    protected: std::string stamp;
  };

  /// \brief Filter for joint state.
  class JointFilter : public FilterBase
  {
    /// \brief Constructor.
    /// \param[in] _xmlOutput True if the output should be in XML format.
    /// \param[in] _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    public: JointFilter(bool _xmlOutput, const std::string &_stamp);

    /// \brief Initialize the filter.
    /// \param[in] _filter The command line filter string.
    public: void Init(const std::string &_filter);

    /// \brief Filter joint parts (angle)
    /// \param[in] _state Link state to filter.
    /// \param[in] _partIter Iterator to the filtered string parts.
    /// \return Filtered joint string.
    public: std::string FilterParts(gazebo::physics::JointState &_state,
                std::list<std::string>::iterator _partIter);

    /// \brief Filter the joints in a Model state, and output the result
    /// as a string.
    /// \param[in] _state The model state to filter.
    /// \return Filtered string.
    public: std::string Filter(gazebo::physics::ModelState &_state);

    /// \brief The list of filter strings.
    public: std::list<std::string> parts;
  };

  /// \brief Filter for link state.
  class LinkFilter : public FilterBase
  {
    /// \brief Constructor.
    /// \param[in] _xmlOutput True if the output should be in XML format.
    /// \param[in] _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    public: LinkFilter(bool _xmlOutput, const std::string &_stamp);

    /// \brief Initialize the filter.
    /// \param[in] _filter The command line filter string.
    public: void Init(const std::string &_filter);

    /// \brief Filter link parts (pose, velocity, acceleration, wrench)
    /// \param[in] _state Link state to filter.
    /// \param[in] _partIter Iterator to the filtered string parts.
    /// \return Filtered string
    public: std::string FilterParts(gazebo::physics::LinkState &_state,
                std::list<std::string>::iterator _partIter);

    /// \brief Filter the links in a Model state, and output the result
    /// as a string.
    /// \param[in] _state The model state to filter.
    /// \return Filtered string.
    public: std::string Filter(gazebo::physics::ModelState &_state);

    /// \brief The list of filter strings.
    public: std::list<std::string> parts;
  };

  /// \brief Filter for model state.
  class ModelFilter : public FilterBase
  {
    /// \brief Constructor.
    /// \param[in] _xmlOutput True if the output should be in XML format.
    /// \param[in] _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    public: ModelFilter(bool _xmlOutput, const std::string &_stamp);

    /// \brief Destructor.
    public: virtual ~ModelFilter();

    /// \brief Initialize the filter.
    /// \param[in] _filter The command line filter string.
    public: void Init(const std::string &_filter);

    /// \brief Filter model parts (pose)
    /// \param[in] _state Model state to filter.
    /// \param[in] _partIter Iterator to the filtered string parts.
    /// \return Filtered string
    public: std::string FilterParts(gazebo::physics::ModelState &_state,
                std::list<std::string>::iterator _partIter);

    /// \brief Filter the models in a World state, and output the result
    /// as a string.
    /// \param[in] _state The World state to filter.
    /// \return Filtered string.
    public: std::string Filter(gazebo::physics::WorldState &_state);

    /// \brief The list of model parts to filter.
    public: std::list<std::string> parts;

    /// \brief Pointer to the link filter.
    public: LinkFilter *linkFilter;

    /// \brief Pointer to the joint filter.
    public: JointFilter *jointFilter;
  };

  /// \brief Filter interface for an entire state.
  class StateFilter : public FilterBase
  {
    /// \brief Constructor
    /// \param[in] _xmlOutput True to format output as XML
    /// \param[in] _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    public: StateFilter(bool _xmlOutput, const std::string &_stamp,
                double _hz = 0);

    /// \brief Initialize the filter with a set of parameters.
    /// \param[_in] _filter The filter parameters
    public: void Init(const std::string &_filter);

    /// \brief Perform filtering
    /// \param[in] _stateString The string to filter.
    /// \return Filtered string
    public: std::string Filter(const std::string &_stateString);

    /// \brief Filter for a model.
    private: ModelFilter filter;

    /// \brief Rate at which to output states.
    private: double hz;

    /// \brief Previous time a state was output.
    private: gazebo::common::Time prevTime;
  };

  /// \brief Log command
  class LogCommand : public Command
  {
    /// \brief Constructor
    public: LogCommand();

    // Documentation inherited
    public: virtual void HelpDetailed();

    // Documentation inherited
    protected: virtual bool RunImpl();

    // Documentation inherited
    protected: virtual bool TransportRequired();

    /// \brief Output information about a log file.
    /// \param[in] _filename Name of the file to parse.
    private: void Info(const std::string &_filename);

    /// \brief Output log data to a file. This is usually used with the
    /// filter command.
    /// \param[in] _outFilename Output filename
    /// \param[in] _filter Filter string
    /// \param[in] _raw True to output data without xml formatting.
    /// \param[in] _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    /// \param[in] _hz Hertz rate.
    /// \param[in] _encoding Specify output log file encoding. If empty, the
    /// encoding from the source log file is used.
    /// Valid values include (txt, zlib, bz2)
    private: void Output(const std::string &_outFilename,
                 const std::string &_filter, const bool _raw,
                 const std::string &_stamp, const double _hz,
                 const std::string &_encoding = "");

    /// \brief Dump the contents of a log file to screen
    /// \param[in] _filter Filter string
    /// \param[in] _raw True to output data without xml formatting.
    /// \param[in] _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    /// \param[in] _hz Hertz rate.
    private: void Echo(const std::string &_filter,
                 bool _raw, const std::string &_stamp, double _hz);

    /// \brief Step through a log file.
    /// \param[in] _filter Filter string
    /// \param[in] _raw True to output data without xml formatting.
    /// \param[in] _stamp Type of stamp to apply.
    /// Valid values are (sim,real,wall)
    /// \param[in] _hz Hertz rate.
    private: void Step(const std::string &_filter, bool _raw,
                 const std::string &_stamp, double _hz);

    /// \brief Start or stop logging
    /// \param[in] _start True to start logging
    private: void Record(bool _start);

    /// \brief Get a character from the terminal.
    /// This bypasses the need to wait for the 'enter' key.
    /// \return The characater read from the terminal.
    private: int GetChar();

    /// \brief Get the size of file.
    /// \param[in] _filename Name of the file to get the size of.
    /// \return The size of the file in human readable format.
    private: std::string GetFileSizeStr(const std::string &_filename);

    /// \brief Load a log file from a filename.
    /// \param[in] _filename Filename to open
    /// \return True on success.
    private: bool LoadLogFromFile(const std::string &_filename);


    /// \brief Write data to a file.
    /// \param[in] _outFile Output file stream reference.
    /// \param[in] _stateString SDF state string to write
    /// \param[in] _raw True to output data without xml formatting.
    /// \param[in] _encoding Encoding type: txt, zlib, bz2
    private: void OutputWriter(std::ofstream &_outFile,
                 const std::string &_stateString,
                 const bool _raw, const std::string &_encoding);

    /// \brief Node pointer.
    private: gazebo::transport::NodePtr node;
  };
}
#endif