Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pacledt-compose'Node' #9

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packet/packet_composed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.8)
project(packet_composed)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
find_package(rclcpp REQUIRED)
find_package(packet_interfaces REQUIRED)

add_executable(Composed
src/composed_main.cpp
src/composed.cpp
)

ament_target_dependencies(Composed
rclcpp
packet_interfaces
)

target_include_directories(Composed
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
install(TARGETS
Composed
DESTINATION lib/${PROJECT_NAME}
)

ament_package()

20 changes: 20 additions & 0 deletions packet/packet_composed/include/packet_composed/sensorspacket.hpp
H1rono marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef PACKET_COMPOSED_SENSORPACKET_HPP
#define PACKET_COMPOSED_SENSORPACKET_HPP

#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

class Composed : public rclcpp::Node {
private:

std::shared_ptr<rclcpp::Publisher<std_msgs::msg::String>> _publisher;
std::shared_ptr<rclcpp::TimerBase> _timer;
unsigned int _count;
void _loop();

public:
Composed();
};

#endif // PACKET_COMPOSED_SENSORPACKET_HPP
15 changes: 15 additions & 0 deletions packet/packet_composed/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>packet_composed</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">norikonakano</maintainer>
<license>MIT</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>rclcpp</depend>
<depend>packet_interfaces</depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
28 changes: 28 additions & 0 deletions packet/packet_composed/src/composed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <chrono>
#include <functional>
#include <string>

#include "packet_composed/sensorspacket.hpp"

void Composed::_loop() {
std::stringstream ss;
ss << "Hello, world! " << _count;
std_msgs::msg::String msg{};
msg.data = ss.str();
RCLCPP_INFO(this->get_logger(), "say %s", ss.str().c_str());
_publisher->publish(msg);
_count++;
}


Composed::Composed() :
rclcpp::Node("composed"),
_publisher(),
_timer(),
_count(0)
{
using namespace std::chrono_literals;
_publisher = this->create_publisher<std_msgs::msg::String>("/sensorspacket", 10);
H1rono marked this conversation as resolved.
Show resolved Hide resolved
auto loop = std::bind(&Composed::_loop, this);
_timer = this->create_wall_timer(500ms, loop);
Copy link
Member

@H1rono H1rono Jun 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もうちょい周波数高くていいかも

Suggested change
_timer = this->create_wall_timer(500ms, loop);
_timer = this->create_wall_timer(10ms, loop);

}
11 changes: 11 additions & 0 deletions packet/packet_composed/src/composed_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <memory>
#include <rclcpp/rclcpp.hpp>
#include "packet_composed/sensorspacket.hpp"

int main(int argc, char * argv[]) {
rclcpp::init(argc, argv);
auto node = std::make_shared<Composed>();
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}