First commit of a simple package that can be used for demonstration.

This commit is contained in:
James Pace 2023-02-07 00:45:20 +00:00
commit ae2875d7cf
5 changed files with 118 additions and 0 deletions

27
CMakeLists.txt Normal file
View File

@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.8)
project(j7s-simple)
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)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
add_executable(j7s-publisher src/j7s-publisher.cpp)
target_include_directories(j7s-publisher PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(j7s-publisher PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
ament_target_dependencies(j7s-publisher rclcpp std_msgs)
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)
install(TARGETS j7s-publisher
DESTINATION lib/${PROJECT_NAME})
ament_package()

View File

@ -0,0 +1,26 @@
// Copyright 2023 James Pace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
class J7sPublisher: public rclcpp::Node
{
public:
J7sPublisher();
private:
rclcpp::TimerBase::SharedPtr m_timer;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr m_publisher;
};

View File

@ -0,0 +1,10 @@
import launch
import launch_ros.actions
def generate_launch_description():
return launch.LaunchDescription([
launch_ros.actions.Node(
package='j7s-simple',
executable='j7s-publisher',
name='j7s_publisher')
])

17
package.xml Normal file
View File

@ -0,0 +1,17 @@
<?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>j7s-simple</name>
<version>0.0.0</version>
<description>A set of simple nodes for testing things which package ros2.</description>
<maintainer email="jpace121@gmail.com">James Pace</maintainer>
<license>Apache-2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>std_msgs</depend>
<depend>rclcpp</depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>

38
src/j7s-publisher.cpp Normal file
View File

@ -0,0 +1,38 @@
// Copyright 2023 James Pace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <j7s-simple/j7s-publisher.hpp>
#include <chrono>
using namespace std::chrono_literals;
J7sPublisher::J7sPublisher():
Node("j7s_publisher")
{
m_publisher = this->create_publisher<std_msgs::msg::String>("j7s_hello", 1);
const auto callback = [this]() {
std_msgs::msg::String msg;
msg.data = "Hello from j7s!";
m_publisher->publish(msg);
};
m_timer = this->create_wall_timer(500ms, callback);
}
int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<J7sPublisher>());
rclcpp::shutdown();
return 0;
}