Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>
  • Loading branch information
Prajakta Gokhale committed Apr 2, 2020
1 parent a3b4d9d commit 58faa95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions system_metrics_collector/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<depend>rclcpp_lifecycle</depend>
<depend>rcpputils</depend>
<depend>rcutils</depend>
<depend>sensor_msgs</depend>

<build_depend>rosidl_default_generators</build_depend>
<build_depend>std_msgs</build_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
// limitations under the License.

#include <memory>
#include <mutex>
#include <utility>

#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/imu.hpp"

using namespace std::chrono_literals;

/**
* A class that publishes IMU messages every second with the Header set to current time.
*/
Expand All @@ -29,32 +28,34 @@ class ImuTalker : public rclcpp::Node
ImuTalker()
: Node("imu_talker")
{
using namespace std::chrono_literals;
auto publish_lambda =
[this]() -> void
{
std::unique_lock<std::mutex> ulock{mutex_};

msg_ = std::make_unique<sensor_msgs::msg::Imu>();
msg_->header = std_msgs::msg::Header{};
msg_->header.stamp = this->now();
RCLCPP_INFO(
this->get_logger(),
"%lu Publishing header: %lu",
++count_,
"Publishing header: %lu",
msg_->header.stamp.nanosec);

publisher_->publish(std::move(msg_));
};

publisher_ = this->create_publisher<sensor_msgs::msg::Imu>(
"imu_data",
10);
10 /* QoS history_depth */);
timer_ = this->create_wall_timer(1s, publish_lambda);
}

private:
uint64_t count_ = 1;
std::unique_ptr<sensor_msgs::msg::Imu> msg_;
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr publisher_;
rclcpp::TimerBase::SharedPtr timer_;
mutable std::mutex mutex_;
};

int main(int argc, char ** argv)
Expand Down

0 comments on commit 58faa95

Please sign in to comment.