Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dc_core/include/dc_core/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Measurement
* from if_all/if_any/if_none, which are re-evaluated on every collection
* @param run_id Unique ID of the current run
* @param run_id Whether Run Id is enabled
* @param custom_params Vector of JSON with custom parameters
* @param custom_keys Vector of JSON with custom keys
*/
virtual void configure(const rclcpp_lifecycle::LifecycleNode::WeakPtr& parent, const std::string& name,
const std::map<std::string, std::shared_ptr<dc_core::Condition>>& conditions,
Expand All @@ -68,7 +68,7 @@ class Measurement
const bool& nest, const bool& flatten, const std::string& save_local_base_path,
const std::string& all_base_path, const std::string& all_base_path_expanded,
const std::string& save_local_base_path_expanded, const std::string& run_id,
const bool& run_id_enabled, const std::vector<json>& custom_params) = 0;
const bool& run_id_enabled, const std::vector<json>& custom_keys) = 0;

/**
* @brief Method to cleanup resources used on shutdown.
Expand Down
4 changes: 2 additions & 2 deletions dc_demos/params/elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ dc_bridge:
measurement_server:
ros__parameters:
measurement_plugins: ["cpu", "memory", "os", "uptime"]
custom_str_params_list: ["robot_name"]
custom_str_params:
custom_key_str_list: ["robot_name"]
custom_keys_str:
robot_name:
name: robot_name
value: "C3PO"
Expand Down
4 changes: 2 additions & 2 deletions dc_demos/params/qrcodes_minio_pgsql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ measurement_server:
robot_name: "C3PO"
measurement_plugins:
["cmd_vel", "position", "speed", "map", "right_camera", "left_camera"]
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "C3PO"
Expand Down
4 changes: 2 additions & 2 deletions dc_demos/params/qrcodes_stdout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ measurement_server:
save_local_base_path: "$HOME/dc_data/"
all_base_path: "=robot_name/%Y/%m/%d/%H"
condition_plugins: ["moving"]
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "r2d2"
Expand Down
4 changes: 2 additions & 2 deletions dc_demos/params/tb3_simulation_influxdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ measurement_server:
# Infrastructure
"influxdb_health",
]
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "Turtlebot"
Expand Down
4 changes: 2 additions & 2 deletions dc_demos/params/tb3_simulation_pgsql_minio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ measurement_server:
"rustfs_health",
"pgsql_health",
]
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "Turtlebot"
Expand Down
4 changes: 2 additions & 2 deletions dc_demos/params/tb3_simulation_stdout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ measurement_server:
ros__parameters:
robot_name: "C3PO"
measurement_plugins: ["cmd_vel", "map", "position", "speed"]
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "C3PO"
Expand Down
4 changes: 2 additions & 2 deletions dc_demos/params/uptime_stdout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ measurement_server:
counter: true
counter_path: "$HOME/run_id"
uuid: false
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
force_override: false
robot_name:
name: robot_name
Expand Down
18 changes: 9 additions & 9 deletions dc_measurements/include/dc_measurements/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class Measurement : public dc_core::Measurement
addTags(msg);
addMeasurementName(msg);
addMeasurementPluginName(msg);
addCustomParameters(msg);
addCustomKeys(msg);
}
if (!msg.data.empty() && msg.data != "null")
{
Expand Down Expand Up @@ -482,9 +482,9 @@ class Measurement : public dc_core::Measurement
}
}

void addCustomParameters(dc_interfaces::msg::StringStamped& msg)
void addCustomKeys(dc_interfaces::msg::StringStamped& msg)
{
if (!custom_params_.empty() && (!msg.data.empty() && msg.data != "null"))
if (!custom_keys_.empty() && (!msg.data.empty() && msg.data != "null"))
{
json data;
try
Expand All @@ -493,9 +493,9 @@ class Measurement : public dc_core::Measurement
}
catch (json::parse_error& e)
{
RCLCPP_ERROR_STREAM(logger_, "Error parsing JSON when adding custom parameters: " << data.dump());
RCLCPP_ERROR_STREAM(logger_, "Error parsing JSON when adding custom keys: " << data.dump());
}
for (auto& param : custom_params_)
for (auto& param : custom_keys_)
{
auto key = param["key"].get<std::string>();
auto value = param["value"].get<std::string>();
Expand Down Expand Up @@ -535,7 +535,7 @@ class Measurement : public dc_core::Measurement
const std::vector<std::string>& remote_prefixes, const bool& nested, const bool& flatten,
const std::string& save_local_base_path, const std::string& all_base_path,
const std::string& all_base_path_expanded, const std::string& save_local_base_path_expanded,
const std::string& run_id, const bool& run_id_enabled, const std::vector<json>& custom_params) override
const std::string& run_id, const bool& run_id_enabled, const std::vector<json>& custom_keys) override
{
node_ = parent;
auto node = node_.lock();
Expand Down Expand Up @@ -569,7 +569,7 @@ class Measurement : public dc_core::Measurement
save_local_base_path_expanded_ = save_local_base_path_expanded;
run_id_ = run_id;
run_id_enabled_ = run_id_enabled;
custom_params_ = custom_params;
custom_keys_ = custom_keys;

condition_max_measurements_ = condition_max_measurements;
if_all_conditions_ = if_all_conditions;
Expand Down Expand Up @@ -665,8 +665,8 @@ class Measurement : public dc_core::Measurement
bool run_id_enabled_;
std::string run_id_;

// Custom params
std::vector<json> custom_params_;
// Custom keys
std::vector<json> custom_keys_;

// Parameters
bool init_collect_;
Expand Down
14 changes: 7 additions & 7 deletions dc_measurements/include/dc_measurements/measurement_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MeasurementServer : public nav2_util::LifecycleNode
nav2_util::CallbackReturn on_shutdown(const rclcpp_lifecycle::State& state) override;

void setRunId();
void setCustomParameters();
void setCustomKeys();
void setBaseSavePath();

std::shared_ptr<tf2_ros::Buffer> tf_;
Expand All @@ -99,9 +99,9 @@ class MeasurementServer : public nav2_util::LifecycleNode
bool run_id_counter_;
bool run_id_uuid_;

// Custom parameters
std::vector<std::string> custom_str_params_list_;
std::vector<json> custom_params_;
// Custom keys
std::vector<std::string> custom_key_str_list_;
std::vector<json> custom_keys_;

// std::vector<std::string> measurement_plugins_;
std::vector<std::string> measurement_group_key_;
Expand Down Expand Up @@ -129,9 +129,9 @@ class MeasurementServer : public nav2_util::LifecycleNode
std::string save_local_base_path_expanded_;
std::string all_base_path_;
std::string all_base_path_expanded_;
std::vector<std::string> measurement_custom_str_params_;
std::map<std::string, std::string> custom_str_params_map_;
bool custom_str_params_force_override_;
std::vector<std::string> measurement_custom_keys_str_;
std::map<std::string, std::string> custom_keys_str_map_;
bool custom_keys_str_force_override_;

// Conditions
std::map<std::string, std::shared_ptr<dc_core::Condition>> conditions_;
Expand Down
47 changes: 23 additions & 24 deletions dc_measurements/src/measurement_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,42 @@ void MeasurementServer::setBaseSavePath()
save_local_base_path_expanded_ = dc_util::expand_values(save_local_base_path_expanded_, this);
RCLCPP_INFO(get_logger(), "Base save path expanded to %s", save_local_base_path_expanded_.c_str());
all_base_path_expanded_ = dc_util::expand_env(all_base_path_);
all_base_path_expanded_ = dc_util::expand_values(all_base_path_expanded_, this, "custom_str_params.", ".value");
all_base_path_expanded_ = dc_util::expand_values(all_base_path_expanded_, this, "custom_keys_str.", ".value");
RCLCPP_INFO(get_logger(), "All Base path expanded to %s", all_base_path_expanded_.c_str());
}

void MeasurementServer::setCustomParameters()
void MeasurementServer::setCustomKeys()
{
// Declared for override parity with the per-parameter custom_str_params.<name>.force_override
// below; not consumed here (each custom param's own force_override is what's actually read).
dc_util::get_bool_type_param(this, "custom_str_params", "force_override", false);
custom_str_params_list_ = dc_util::get_str_array_param(this, "custom_str_params_list", std::vector<std::string>());
// Declared for override parity with the per-parameter custom_keys_str.<name>.force_override
// below; not consumed here (each custom key's own force_override is what's actually read).
dc_util::get_bool_type_param(this, "custom_keys_str", "force_override", false);
custom_key_str_list_ = dc_util::get_str_array_param(this, "custom_key_str_list", std::vector<std::string>());

for (auto param = std::begin(measurement_custom_str_params_); param != std::end(measurement_custom_str_params_);
++param)
for (auto param = std::begin(measurement_custom_keys_str_); param != std::end(measurement_custom_keys_str_); ++param)
{
custom_str_params_map_[*param] = dc_util::get_str_param(this, *param, "");
custom_keys_str_map_[*param] = dc_util::get_str_param(this, *param, "");
}

custom_params_.resize(custom_str_params_list_.size());
custom_keys_.resize(custom_key_str_list_.size());

for (size_t i = 0; i < custom_str_params_list_.size(); i++)
for (size_t i = 0; i < custom_key_str_list_.size(); i++)
{
auto custom_param = custom_str_params_list_[i];
std::string custom_param_ns = "custom_str_params." + custom_param;
std::string key = dc_util::get_str_type_param(this, custom_param_ns, "name", "");
std::string value = dc_util::get_str_type_param(this, custom_param_ns, "value", "");
std::string value_from_file = dc_util::get_str_type_param(this, custom_param_ns, "value_from_file", "");
bool force_override = dc_util::get_bool_type_param(this, custom_param_ns, "force_override", false);

custom_params_[i]["key"] = key;
custom_params_[i]["override"] = force_override;
auto custom_key = custom_key_str_list_[i];
std::string custom_key_ns = "custom_keys_str." + custom_key;
std::string key = dc_util::get_str_type_param(this, custom_key_ns, "name", "");
std::string value = dc_util::get_str_type_param(this, custom_key_ns, "value", "");
std::string value_from_file = dc_util::get_str_type_param(this, custom_key_ns, "value_from_file", "");
bool force_override = dc_util::get_bool_type_param(this, custom_key_ns, "force_override", false);

custom_keys_[i]["key"] = key;
custom_keys_[i]["override"] = force_override;
if (!value.empty())
{
custom_params_[i]["value"] = value;
custom_keys_[i]["value"] = value;
}
else if (!value_from_file.empty())
{
custom_params_[i]["value"] = dc_util::get_file_content(value_from_file);
custom_keys_[i]["value"] = dc_util::get_file_content(value_from_file);
}
}
}
Expand Down Expand Up @@ -129,7 +128,7 @@ nav2_util::CallbackReturn MeasurementServer::on_configure(const rclcpp_lifecycle
RCLCPP_INFO(get_logger(), "Configuring");
auto node = shared_from_this();
setRunId();
setCustomParameters();
setCustomKeys();
setBaseSavePath();

tf_ = std::make_shared<tf2_ros::Buffer>(get_clock());
Expand Down Expand Up @@ -281,7 +280,7 @@ bool MeasurementServer::loadMeasurementPlugins()
measurement_if_all_conditions_[i], measurement_if_any_conditions_[i], measurement_if_none_conditions_[i],
measurement_gate_condition_[i], measurement_remote_keys_[i], measurement_remote_prefixes_[i],
measurement_nested_[i], measurement_flatten_[i], save_local_base_path_, all_base_path_,
all_base_path_expanded_, save_local_base_path_expanded_, run_id_, run_id_enabled_, custom_params_);
all_base_path_expanded_, save_local_base_path_expanded_, run_id_, run_id_enabled_, custom_keys_);
}
catch (const pluginlib::PluginlibException& ex)
{
Expand Down
10 changes: 5 additions & 5 deletions doc/src/dc/demos/qrcodes_minio_pgsql.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ group_server:

measurement_server:
ros__parameters:
custom_str_params: ["robot_name"]
custom_keys_str: ["robot_name"]
robot_name: "C3PO"
measurement_plugins: ["cmd_vel", "position", "speed"]
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "C3PO"
Expand Down Expand Up @@ -289,8 +289,8 @@ measurement_server:
...
measurement_plugins: ["cmd_vel", "position", "speed", "map", "right_camera", "left_camera"]
condition_plugins: ["moving", "inspected_exists"]
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "C3PO"
Expand Down
8 changes: 4 additions & 4 deletions doc/src/dc/demos/tb3_stdout.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ This record contains the map data from the measurement.
```yaml
measurement_server:
ros__parameters:
custom_str_params: ["robot_name"]
custom_keys_str: ["robot_name"]
robot_name: "C3PO"
measurement_plugins: ["cmd_vel", "map", "position", "speed"]
run_id:
Expand Down Expand Up @@ -178,7 +178,7 @@ measurement_server:

**save_local_base_path (Optional)**: Used as a common base for all saved files from measurement plugins. *all_base_path* is concatenated to it afterwards for defining the path where files are saved.

**all_base_path (Optional)**: Used as a common base for some measurements to save files. Is concatenated to *save_local_base_path*. Note the =robot_name, which is later replaced by C3PO (the variable defined in custom_str_params)
**all_base_path (Optional)**: Used as a common base for some measurements to save files. Is concatenated to *save_local_base_path*. Note the =robot_name, which is later replaced by C3PO (the variable defined in custom_keys_str)

**map.remote_keys**: creates a dictionary inside **remote_paths** which is named by the strings in this field — each name must match a `receives: files` Destination in the `dc_bridge` block below, so the Bridge's Uploader knows where to send the file.

Expand Down Expand Up @@ -225,8 +225,8 @@ dc_bridge:

measurement_server:
ros__parameters:
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: "C3PO"
Expand Down
16 changes: 8 additions & 8 deletions doc/src/dc/demos/uptime_stdout.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ measurement_server:
enable_validator: true
debug: true
init_collect: true
custom_str_params_list: ["robot_name", "id"]
custom_str_params:
custom_key_str_list: ["robot_name", "id"]
custom_keys_str:
robot_name:
name: robot_name
value: C3PO
Expand Down Expand Up @@ -74,17 +74,17 @@ This will collect the uptime every 5 seconds (including when the node starts), w

Here, we want to append some content in every record: the robot name and its ID. While the robot name comes from a fixed variable in the parameter file, the id comes from the machine-id file.

**custom_str_params_list (Optional)**: Look for those keys in this configuration to add them as keys and values in each record.
**custom_key_str_list (Optional)**: Look for those keys in this configuration to add them as keys and values in each record.

**custom_str_params.robot_name (Optional)**: This parameter is loaded since it is mentioned in custom_str_params_list
**custom_keys_str.robot_name (Optional)**: This parameter is loaded since it is mentioned in custom_key_str_list

**custom_str_params.robot_name.name (Optional)**: Key in the dictionary to add
**custom_keys_str.robot_name.name (Optional)**: Key in the dictionary to add

**custom_str_params.robot_name.value (Optional)**: Value associated to the key in the dictionary to add
**custom_keys_str.robot_name.value (Optional)**: Value associated to the key in the dictionary to add

**custom_str_params.id.name (Optional)**: Key in the dictionary to add
**custom_keys_str.id.name (Optional)**: Key in the dictionary to add

**custom_str_params.id.value_from_file (Optional)**: Value associated to the key in the dictionary to add taken from the content of a file
**custom_keys_str.id.value_from_file (Optional)**: Value associated to the key in the dictionary to add taken from the content of a file


```admonish info
Expand Down
Loading
Loading