Skip to content

Commit

Permalink
[drake_ros] Use modern drake::systems::Event API (#292)
Browse files Browse the repository at this point in the history
As of Drake v1.20, the old API is deprecated.
  • Loading branch information
jwnimmer-tri authored Aug 15, 2023
1 parent 656bbc7 commit 381424a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
6 changes: 1 addition & 5 deletions drake_ros/core/ros_publisher_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ 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,
const drake::systems::PublishEvent<double>&) {
PublishInput(context);
}));
this->DeclarePerStepPublishEvent(&RosPublisherSystem::PublishInput);
}
// ^^^ 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 381424a

Please sign in to comment.