initial commit
This commit is contained in:
37
drone_sensors/CMakeLists.txt
Normal file
37
drone_sensors/CMakeLists.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(drone_sensors)
|
||||
|
||||
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(std_msgs REQUIRED)
|
||||
|
||||
# add executable so that the node can be run with ros2 run
|
||||
add_executable(height_sensor src/height_sensor.cpp)
|
||||
ament_target_dependencies(height_sensor rclcpp std_msgs)
|
||||
|
||||
# add install targets section so ros2 run can find the executable
|
||||
install(TARGETS
|
||||
height_sensor
|
||||
DESTINATION lib/${PROJECT_NAME})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
find_package(ament_lint_auto REQUIRED)
|
||||
# the following line skips the linter which checks for copyrights
|
||||
# comment the line when a copyright and license is added to all source files
|
||||
set(ament_cmake_copyright_FOUND TRUE)
|
||||
# the following line skips cpplint (only works in a git repo)
|
||||
# comment the line when this package is in a git repo and when
|
||||
# a copyright and license is added to all source files
|
||||
set(ament_cmake_cpplint_FOUND TRUE)
|
||||
ament_lint_auto_find_test_dependencies()
|
||||
endif()
|
||||
|
||||
ament_package()
|
||||
21
drone_sensors/package.xml
Normal file
21
drone_sensors/package.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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>drone_sensors</name>
|
||||
<version>0.0.0</version>
|
||||
<description>package for the environment sensors of the 5G drone (height meter, object detection)</description>
|
||||
<maintainer email="sem.hoeven@gmail.com">Sem van der Hoeven</maintainer>
|
||||
<license>Apache License 2.0</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<depend>rclcpp</depend>
|
||||
<depend>std_msgs</depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
39
drone_sensors/src/height_sensor.cpp
Normal file
39
drone_sensors/src/height_sensor.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <chrono> //time measurement
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "std_msgs/msg/string.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class HeightSensorPublisher : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
HeightSensorPublisher() : Node("height_sensor_publisher")
|
||||
{
|
||||
publisher_ = this->create_publisher<std_msgs::msg::String>("height_sensor", 10);
|
||||
timer_ = this->create_wall_timer(
|
||||
500ms, std::bind(&HeightSensorPublisher::timer_callback, this));
|
||||
|
||||
}
|
||||
private:
|
||||
void timer_callback()
|
||||
{
|
||||
auto message = std_msgs::msg::String();
|
||||
message.data = "Hello heigth sensor!";
|
||||
RCLCPP_INFO(this->get_logger(), "Publishing: %s", message.data.c_str());
|
||||
publisher_->publish(message);
|
||||
}
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
rclcpp::init(argc,argv);
|
||||
rclcpp::spin(std::make_shared<HeightSensorPublisher>());
|
||||
rclcpp::shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user