Skip to content

Commit 7f627f8

Browse files
committed
Add logging for string metrics in MachineViewer and update settings
1 parent e42cf9d commit 7f627f8

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"chat.tools.terminal.autoApprove": {
3+
"cmake": true
4+
}
5+
}

src/machine_viewer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ struct MachineViewer::Impl {
101101
_rec.log(_root_path + "/metrics/" + sanitize_metric_name(name), rerun::Scalars(value));
102102
}
103103

104+
void log_string(const std::string& name, const std::string& value) {
105+
if (name.empty()) {
106+
throw std::invalid_argument("MachineViewer string metric name cannot be empty.");
107+
}
108+
109+
++_tick;
110+
_rec.set_time_sequence("tick", _tick);
111+
_rec.log(_root_path + "/metrics/" + sanitize_metric_name(name), rerun::TextLog(value));
112+
}
113+
104114
void load_tool(double length, double diameter) {
105115
if (length == 0 || diameter == 0) {
106116
unload_tool();
@@ -341,6 +351,10 @@ void MachineViewer::log_scalar(const std::string& name, double value) {
341351
_impl->log_scalar(name, value);
342352
}
343353

354+
void MachineViewer::log_string(const std::string& name, const std::string& value) {
355+
_impl->log_string(name, value);
356+
}
357+
344358
double MachineViewer::tool_z_offset() const {
345359
return _impl->tool_z_offset();
346360
}

src/machine_viewer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MachineViewer {
2929
void load_tool(double length, double diameter);
3030
void unload_tool();
3131
void log_scalar(const std::string& name, double value);
32+
void log_string(const std::string& name, const std::string& value);
3233
double tool_z_offset() const;
3334
void set_tool_z_offset(double tool_z_offset);
3435

src/machinetool.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ class MachinetoolPlugin : public Sink<json> {
121121
}
122122

123123
for (const auto& [name, value] : input.at("metrics").items()) {
124-
if (!value.is_number()) {
125-
_error = "Metric '" + name + "' is not numeric.";
124+
if (value.is_number()) {
125+
_viewer->log_scalar(name, value.get<double>());
126+
} else if (value.is_string()) {
127+
_viewer->log_string(name, value.get<string>());
128+
} else {
129+
_error = "Metric '" + name + "' can't be logged.";
126130
return return_type::warning;
127131
}
128-
_viewer->log_scalar(name, value.get<double>());
129132
}
130133
}
131134
} catch (const exception& ex) {

0 commit comments

Comments
 (0)