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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Release Versions:

- fix(modulo-controllers): improve log message (#110)
- fix(modulo-components): add missing space in log message (#113)
- feat(modulo-controller): add missing docs (#112)
- feat(modulo-controllers): add missing docs (#112)
- fix(modulo-controllers): correctly handle nullptr in read_input (#118)

## 4.2.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,12 @@ inline std::optional<T> ControllerInterface::read_input(const std::string& name)
return {};
}
auto message =
*std::get<realtime_tools::RealtimeBuffer<std::shared_ptr<modulo_core::EncodedState>>>(inputs_.at(name).buffer)
.readFromNonRT();
**std::get<realtime_tools::RealtimeBuffer<std::shared_ptr<modulo_core::EncodedState>>>(inputs_.at(name).buffer)
.readFromNonRT();
std::shared_ptr<state_representation::State> state;
try {
auto message_pair = input_message_pairs_.at(name);
message_pair->read<modulo_core::EncodedState, state_representation::State>(*message);
message_pair->read<modulo_core::EncodedState, state_representation::State>(message);
state = message_pair->get_message_pair<modulo_core::EncodedState, state_representation::State>()->get_data();
} catch (const std::exception& ex) {
RCLCPP_WARN_THROTTLE(
Expand All @@ -761,12 +761,14 @@ inline std::optional<T> ControllerInterface::read_input(const std::string& name)
if (state->is_empty()) {
return {};
}
try {
return *std::dynamic_pointer_cast<T>(state);
} catch (const std::exception& ex) {
auto cast_ptr = std::dynamic_pointer_cast<T>(state);
if (cast_ptr != nullptr) {
return *cast_ptr;
} else {
RCLCPP_WARN_THROTTLE(
get_node()->get_logger(), *get_node()->get_clock(), 1000, "Could not cast input '%s' to desired state type: %s",
name.c_str(), ex.what());
get_node()->get_logger(), *get_node()->get_clock(), 1000,
"Dynamic cast of message on input '%s' from type '%s' to type '%s' failed.", name.c_str(),
get_state_type_name(state->get_type()), get_state_type_name(T().get_type()));
}
return {};
}
Expand Down