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

Commit

Permalink
Use dummy_message instead of imu
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 58faa95 commit 8239aaa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
11 changes: 6 additions & 5 deletions system_metrics_collector/CMakeLists.txt
Expand Up @@ -87,9 +87,9 @@ add_executable(linux_memory_collector src/system_metrics_collector/linux_memory_
target_link_libraries(linux_memory_collector ${PROJECT_NAME})
ament_target_dependencies(linux_memory_collector)

add_executable(imu_talker src/topic_statistics_collector/imu_talker.cpp)
target_link_libraries(imu_talker system_metrics_collector)
ament_target_dependencies(imu_talker sensor_msgs)
add_executable(dummy_talker src/topic_statistics_collector/dummy_talker.cpp)
target_link_libraries(dummy_talker system_metrics_collector)
ament_target_dependencies(dummy_talker)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand Down Expand Up @@ -144,8 +144,9 @@ if(BUILD_TESTING)
ament_target_dependencies(test_subscriber_topic_statistics rcl rclcpp)
endif()

# To enable use of dummy_message.hpp in test_subscriber_topic_statistics
# To enable use of dummy_message.hpp in executables
rosidl_target_interfaces(test_subscriber_topic_statistics system_metrics_collector_test_msgs "rosidl_typesupport_cpp")
rosidl_target_interfaces(dummy_talker system_metrics_collector_test_msgs "rosidl_typesupport_cpp")

# Install launch files
install(DIRECTORY
Expand Down Expand Up @@ -173,7 +174,7 @@ install(TARGETS
)

install(TARGETS
imu_talker
dummy_talker
DESTINATION
lib/${PROJECT_NAME}
)
Expand Down
1 change: 0 additions & 1 deletion system_metrics_collector/package.xml
Expand Up @@ -18,7 +18,6 @@
<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
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Launch file to launch an IMU data publisher node."""
"""Launch file to launch a DummyMessage publisher node."""

from launch import LaunchDescription
import launch_ros.actions
Expand All @@ -22,6 +22,6 @@ def generate_launch_description():
return LaunchDescription([
launch_ros.actions.Node(
package='system_metrics_collector',
node_executable='imu_talker',
node_executable='dummy_talker',
output='screen'),
])
Expand Up @@ -16,25 +16,26 @@
#include <mutex>
#include <utility>

#include "system_metrics_collector/msg/dummy_message.hpp"

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

/**
* A class that publishes IMU messages every second with the Header set to current time.
* A class that publishes DummyMessages every second with the Header set to current time.
*/
class ImuTalker : public rclcpp::Node
class DummyTalker : public rclcpp::Node
{
public:
ImuTalker()
: Node("imu_talker")
DummyTalker()
: Node("dummy_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_ = std::make_unique<system_metrics_collector::msg::DummyMessage>();
msg_->header = std_msgs::msg::Header{};
msg_->header.stamp = this->now();
RCLCPP_INFO(
Expand All @@ -45,15 +46,15 @@ class ImuTalker : public rclcpp::Node
publisher_->publish(std::move(msg_));
};

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

private:
std::unique_ptr<sensor_msgs::msg::Imu> msg_;
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr publisher_;
std::unique_ptr<system_metrics_collector::msg::DummyMessage> msg_;
rclcpp::Publisher<system_metrics_collector::msg::DummyMessage>::SharedPtr publisher_;
rclcpp::TimerBase::SharedPtr timer_;
mutable std::mutex mutex_;
};
Expand All @@ -62,11 +63,11 @@ int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);

const auto imu_talker_node =
std::make_shared<ImuTalker>();
const auto dummy_talker =
std::make_shared<DummyTalker>();

rclcpp::executors::SingleThreadedExecutor ex;
ex.add_node(imu_talker_node->get_node_base_interface());
ex.add_node(dummy_talker->get_node_base_interface());
ex.spin();

rclcpp::shutdown();
Expand Down

0 comments on commit 8239aaa

Please sign in to comment.