Skip to content

Commit 4c00dc5

Browse files
LCM buffer bug fix: The lcm buffer used to be a queue of depth 1 that stored the first message it received after being cleared and never replaced them with newer messages. This fix makes the buffer size bigger and ensures that the latest message is picked up before clearing the buffer. RobotLocomotion/drake#15234 details this issue and the PR on main #366
1 parent 6416507 commit 4c00dc5

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

examples/jacktoy/franka_c3_controller.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ DEFINE_string(lcm_channels,
7171

7272
int DoMain(int argc, char* argv[]) {
7373
gflags::ParseCommandLineFlags(&argc, &argv, true);
74-
drake::lcm::DrakeLcm lcm("udpm://239.255.76.67:7667?ttl=1");
74+
drake::lcm::DrakeLcm lcm("udpm://239.255.76.67:7667?ttl=0");
7575

7676
// load parameters
7777
drake::yaml::LoadYamlOptions yaml_options;
@@ -673,9 +673,10 @@ std::vector<SortedPair<GeometryId>> ground_object_contact_pairs;
673673
DrawAndSaveDiagramGraph(*plant_diagram, "examples/jacktoy/franka_c3_plant");
674674

675675
// Run lcm-driven simulation
676+
int lcm_buffer_size = 200;
676677
systems::LcmDrivenLoop<dairlib::lcmt_robot_output> loop(
677678
&lcm, std::move(owned_diagram), franka_state_receiver,
678-
lcm_channel_params.franka_state_channel, true);
679+
lcm_channel_params.franka_state_channel, true, lcm_buffer_size);
679680
DrawAndSaveDiagramGraph(*loop.get_diagram(), "examples/jacktoy/loop");
680681
// auto& controller_context = loop.get_diagram()->GetMutableSubsystemContext(
681682
// *controller, &loop.get_diagram_mutable_context());

systems/framework/lcm_driven_loop.h

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,9 @@ class LcmDrivenLoop {
136136
/// @param is_forced_publish A flag which enables publishing via diagram.
137137
LcmDrivenLoop(drake::lcm::DrakeLcm* drake_lcm,
138138
std::unique_ptr<drake::systems::Diagram<double>> diagram,
139-
<<<<<<< HEAD
140139
const drake::systems::LeafSystem<double>* lcm_parser,
141-
const std::string& input_channel, bool is_forced_publish)
142-
=======
143-
const drake::systems::System<double>* lcm_parser,
144140
const std::string& input_channel, bool is_forced_publish,
145141
int queue_capacity=1)
146-
>>>>>>> 0423e9d80 (update lcm driven loop to use most recent message)
147142
: LcmDrivenLoop(drake_lcm, std::move(diagram), lcm_parser,
148143
std::vector<std::string>(1, input_channel), input_channel,
149144
"", is_forced_publish, queue_capacity){};
@@ -321,19 +316,17 @@ class LcmDrivenLoop {
321316
time =
322317
name_to_input_sub_map_.at(active_channel_).message().utime * 1e-6;
323318
last_input_msg_time_ = time;
324-
// print current cpu time
325-
// get current time point
326-
auto now = std::chrono::high_resolution_clock::now();
327-
std::cout << "Time of receipt of robot state: "
328-
<< std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()<< std::endl;
319+
// print current cpu time for timing analysis
320+
// auto now = std::chrono::high_resolution_clock::now();
321+
// std::cout << "Time of receipt of robot state: "
322+
// << std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()<<" at utime: "<< time << std::endl;
329323
} else {
330324
// use the robot state to advance
331325
time = state_sub_->message().utime * 1e-6;
332-
// print current cpu time
333-
// get current time point
334-
auto now = std::chrono::high_resolution_clock::now();
335-
std::cout << "Time of receipt of robot state: "
336-
<< std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()<< std::endl;
326+
// print current cpu time for timing analysis
327+
// auto now = std::chrono::high_resolution_clock::now();
328+
// std::cout << "Time of receipt of robot state: "
329+
// << std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()<<" at utime: "<< time << std::endl;
337330
state_sub_->clear();
338331
}
339332

@@ -357,11 +350,10 @@ class LcmDrivenLoop {
357350
if (is_forced_publish_) {
358351
// Force-publish via the diagram
359352
diagram_ptr_->ForcedPublish(diagram_context);
360-
// print current cpu time
361-
// get current time point
362-
auto now = std::chrono::high_resolution_clock::now();
363-
std::cout << "Time of publish: "
364-
<< std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()<< std::endl;
353+
// print current cpu time for timing analysis
354+
// auto now = std::chrono::high_resolution_clock::now();
355+
// std::cout << "Time of publish: "
356+
// << std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()<< std::endl;
365357
}
366358

367359
// Clear messages in the current input channel

0 commit comments

Comments
 (0)