Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parameters_logging_visualization): log and visualize test iteration parameters #1360

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <rclcpp_lifecycle/lifecycle_node.hpp>
#include <scenario_simulator_exception/exception.hpp>
#include <simple_junit/junit5.hpp>
#include <std_msgs/msg/string.hpp>
#include <utility>

#define INTERPRETER_INFO_STREAM(...) \
Expand All @@ -51,6 +52,7 @@ class Interpreter : public rclcpp_lifecycle::LifecycleNode,
using Context = openscenario_interpreter_msgs::msg::Context;

const rclcpp_lifecycle::LifecyclePublisher<Context>::SharedPtr publisher_of_context;
const rclcpp_lifecycle::LifecyclePublisher<std_msgs::msg::String>::SharedPtr publisher_of_params;

double local_frame_rate;

Expand Down Expand Up @@ -80,6 +82,8 @@ class Interpreter : public rclcpp_lifecycle::LifecycleNode,

bool waiting_for_engagement_to_be_completed = false; // NOTE: DIRTY HACK!!!

std_msgs::msg::String test_iteration_params_str = std_msgs::msg::String();

public:
OPENSCENARIO_INTERPRETER_PUBLIC
explicit Interpreter(const rclcpp::NodeOptions &);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace openscenario_interpreter
Interpreter::Interpreter(const rclcpp::NodeOptions & options)
: rclcpp_lifecycle::LifecycleNode("openscenario_interpreter", options),
publisher_of_context(create_publisher<Context>("context", rclcpp::QoS(1).transient_local())),
publisher_of_params(create_publisher<std_msgs::msg::String>(
"test_iteration_parameters", rclcpp::QoS(1).transient_local())),
local_frame_rate(30),
local_real_time_factor(1.0),
osc_path(""),
Expand Down Expand Up @@ -122,6 +124,14 @@ auto Interpreter::on_configure(const rclcpp_lifecycle::State &) -> Result

if (script->category.is<ScenarioDefinition>()) {
scenarios = {std::dynamic_pointer_cast<ScenarioDefinition>(script->category)};
// get and log parameters used in this test iteration
test_iteration_params_str.data.clear();
test_iteration_params_str.data = "Parameter declarations for this scenario iteration:\n";
for (const auto & pd : currentScenarioDefinition()->parameter_declarations) {
test_iteration_params_str.data.append(pd.name + " = " + pd.value + "\n");
}
RCLCPP_INFO_STREAM(get_logger(), test_iteration_params_str.data);

} else if (script->category.is<ParameterValueDistribution>()) {
throw Error(
"ParameterValueDistribution cannot be processed by openscenario_interpreter alone. "
Expand Down Expand Up @@ -179,6 +189,7 @@ auto Interpreter::on_activate(const rclcpp_lifecycle::State &) -> Result
withExceptionHandler(
[this](auto &&...) {
publishCurrentContext();
publisher_of_params->publish(test_iteration_params_str);
deactivate();
},
[this]() {
Expand All @@ -200,6 +211,7 @@ auto Interpreter::on_activate(const rclcpp_lifecycle::State &) -> Result
SimulatorCore::update();

publishCurrentContext();
publisher_of_params->publish(test_iteration_params_str);
});
});
};
Expand Down Expand Up @@ -237,8 +249,10 @@ auto Interpreter::on_activate(const rclcpp_lifecycle::State &) -> Result
execution_timer.clear();

publisher_of_context->on_activate();
publisher_of_params->on_activate();

assert(publisher_of_context->is_activated());
assert(publisher_of_params->is_activated());

if (currentScenarioDefinition()) {
currentScenarioDefinition()->storyboard.init.evaluateInstantaneousActions();
Expand Down Expand Up @@ -308,6 +322,10 @@ auto Interpreter::reset() -> void
publisher_of_context->on_deactivate();
}

if (publisher_of_params->is_activated()) {
publisher_of_params->on_deactivate();
}

if (not has_parameter("initialize_duration")) {
declare_parameter<int>("initialize_duration", 30);
}
Expand Down
10 changes: 6 additions & 4 deletions rviz_plugins/openscenario_visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ ament_auto_add_library(openscenario_visualization_rviz_plugin SHARED
include/openscenario_visualization/context_panel_plugin.hpp
src/context_panel_plugin.cpp
${UIC_FILES}
include/openscenario_visualization_condition_groups_plugin/jsk_overlay_utils.hpp
src/openscenario_visualization_condition_groups_plugin/jsk_overlay_utils.cpp
include/openscenario_visualization_condition_groups_plugin/openscenario_visualization_condition_groups_plugin.hpp
src/openscenario_visualization_condition_groups_plugin/openscenario_visualization_condition_groups_plugin.cpp
include/openscenario_visualization_plugins/jsk_overlay_utils.hpp
src/openscenario_visualization_plugins/jsk_overlay_utils.cpp
include/openscenario_visualization_plugins/openscenario_visualization_condition_groups_plugin.hpp
src/openscenario_visualization_plugins/openscenario_visualization_condition_groups_plugin.cpp
include/openscenario_visualization_plugins/openscenario_visualization_parameters_plugin.hpp
src/openscenario_visualization_plugins/openscenario_visualization_parameters_plugin.cpp
)

target_include_directories(openscenario_visualization_rviz_plugin PRIVATE "${OGRE_PREFIX_DIR}/include")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2015 TIER IV, Inc. All rights reserved.
//
// 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 OPENSCENARIO_VISUALIZATION_PARAMETERS_HPP_
#define OPENSCENARIO_VISUALIZATION_PARAMETERS_HPP_

#include <yaml-cpp/yaml.h>

#include <memory>
#include <nlohmann/json.hpp>

#ifndef Q_MOC_RUN
#include <OgreBillboardSet.h>
#include <OgreManualObject.h>
#include <OgreSceneManager.h>
#include <OgreSceneNode.h>

#include <openscenario_interpreter_msgs/msg/context.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rviz_common/display_context.hpp>
#include <rviz_common/frame_manager_iface.hpp>
#include <rviz_common/message_filter_display.hpp>
#include <rviz_common/properties/bool_property.hpp>
#include <rviz_common/properties/color_property.hpp>
#include <rviz_common/properties/enum_property.hpp>
#include <rviz_common/properties/float_property.hpp>
#include <rviz_common/properties/int_property.hpp>
#include <rviz_common/properties/string_property.hpp>
#include <rviz_common/tool.hpp>
#include <rviz_common/validate_floats.hpp>
#include <std_msgs/msg/string.hpp>

#include "jsk_overlay_utils.hpp"
#endif

namespace openscenario_visualization
{

class VisualizationParametersDisplay : public rviz_common::Display
{
Q_OBJECT

public:
VisualizationParametersDisplay();
virtual ~VisualizationParametersDisplay();

void onInitialize() override;
void onDisable() override;
void onEnable() override;
void subscribe();
void unsubscribe();

private Q_SLOTS:
void updateTopic();
void updateVisualization();

protected:
void processMessage(const std_msgs::msg::String::ConstSharedPtr msg_ptr);
jsk_rviz_plugins::OverlayObject::Ptr overlay_;
rviz_common::properties::ColorProperty * property_text_color_;
rviz_common::properties::IntProperty * property_left_;
rviz_common::properties::IntProperty * property_top_;
rviz_common::properties::IntProperty * property_length_;
rviz_common::properties::IntProperty * property_width_;
rviz_common::properties::StringProperty * property_topic_name_;
rviz_common::properties::FloatProperty * property_value_scale_;

private:
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr test_iteration_params_sub_;
std_msgs::msg::String::ConstSharedPtr last_msg_ptr_;
};

} // namespace openscenario_visualization

#endif // OPENSCENARIO_VISUALIZATION_PARAMETERS_HPP_
3 changes: 3 additions & 0 deletions rviz_plugins/openscenario_visualization/plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<class name="openscenario_visualization/VisualizationConditionGroups" type="openscenario_visualization::VisualizationConditionGroupsDisplay" base_class_type="rviz_common::Display">
<description>Display Condition Groups</description>
</class>
<class name="openscenario_visualization/VisualizationParameters" type="openscenario_visualization::VisualizationParametersDisplay" base_class_type="rviz_common::Display">
<description>Display Parameters</description>
</class>
</library>
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// POSSIBILITY OF SUCH DAMAGE.S SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include "openscenario_visualization_condition_groups_plugin/jsk_overlay_utils.hpp"
#include "openscenario_visualization_plugins/jsk_overlay_utils.hpp"

#include <string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "openscenario_visualization_condition_groups_plugin/openscenario_visualization_condition_groups_plugin.hpp"
#include "openscenario_visualization_plugins/openscenario_visualization_condition_groups_plugin.hpp"

#include <OgreHardwarePixelBuffer.h>
#include <X11/Xlib.h>
Expand Down
Loading
Loading