Skip to content

Commit

Permalink
[drake_ros] Use new Drake v1.20 systems::Event API
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri committed Aug 14, 2023
1 parent 76e1f1e commit 89eb745
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion drake_ros/core/ros_publisher_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ RosPublisherSystem::RosPublisherSystem(
if (publish_triggers.find(drake::systems::TriggerType::kPerStep) !=
publish_triggers.end()) {
DeclarePerStepEvent(drake::systems::PublishEvent<double>(
[this](const drake::systems::Context<double>& context,
[this](const drake::systems::System<double>&,
const drake::systems::Context<double>& context,
const drake::systems::PublishEvent<double>&) {
PublishInput(context);
return drake::systems::EventStatus::Succeeded();
}));
}
// ^^^ Mostly copied from LcmPublisherSystem ^^^
Expand Down
28 changes: 14 additions & 14 deletions drake_ros/core/ros_subscriber_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ void RosSubscriberSystem::DoCalcNextUpdateTime(

// Create a unrestricted event and tie the handler to the corresponding
// function.
drake::systems::UnrestrictedUpdateEvent<double>::UnrestrictedUpdateCallback
callback = [this, serialized_message{std::move(message)}](
const drake::systems::Context<double>&,
const drake::systems::UnrestrictedUpdateEvent<double>&,
drake::systems::State<double>* state) {
// Deserialize the message and store it in the abstract state on the
// context
drake::systems::AbstractValues& abstract_state =
state->get_mutable_abstract_state();
auto& abstract_value =
abstract_state.get_mutable_value(impl_->message_state_index);
impl_->serializer->Deserialize(*serialized_message, &abstract_value);
return drake::systems::EventStatus::Succeeded();
};
auto callback = [this, serialized_message{std::move(message)}](
const drake::systems::System<double>&,
const drake::systems::Context<double>&,
const drake::systems::UnrestrictedUpdateEvent<double>&,
drake::systems::State<double>* state) {
// Deserialize the message and store it in the abstract state on the
// context
drake::systems::AbstractValues& abstract_state =
state->get_mutable_abstract_state();
auto& abstract_value =
abstract_state.get_mutable_value(impl_->message_state_index);
impl_->serializer->Deserialize(*serialized_message, &abstract_value);
return drake::systems::EventStatus::Succeeded();
};

// Schedule an update event at the current time.
*time = context.get_time();
Expand Down

0 comments on commit 89eb745

Please sign in to comment.