Skip to content

Commit

Permalink
Update from template
Browse files Browse the repository at this point in the history
  • Loading branch information
andyblarblar committed Oct 4, 2023
1 parent 306b136 commit 5292b34
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(TODO_PACKAGE_NAME)
project(obj_tracker)
include(FetchContent)

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -18,11 +18,11 @@ find_package(cv_bridge REQUIRED)
find_package(OpenCV 4.2.0 REQUIRED)

# Add source for node executable (link non-ros dependencies here)
add_executable(TODO_PACKAGE_NAME src/TODO_NODE_NAME.cpp src/TODO_NODE_NAME_node.cpp)
target_include_directories(TODO_PACKAGE_NAME PUBLIC
add_executable(obj_tracker src/ObjTrackerNode.cpp src/ObjTrackerNode_node.cpp)
target_include_directories(obj_tracker PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(TODO_PACKAGE_NAME PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
target_compile_features(obj_tracker PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17

# Make ros deps a variable so they get linked to tests as well
set(dependencies
Expand All @@ -38,11 +38,11 @@ set(dependencies

# Link ros dependencies
ament_target_dependencies(
TODO_PACKAGE_NAME
obj_tracker
${dependencies}
)

install(TARGETS TODO_PACKAGE_NAME
install(TARGETS obj_tracker
DESTINATION lib/${PROJECT_NAME})

# Uncomment below to make launch files available if created
Expand All @@ -62,7 +62,7 @@ if (BUILD_TESTING)
ament_add_gtest(${PROJECT_NAME}-test
tests/unit.cpp
# Remember to add node source files
src/TODO_NODE_NAME_node.cpp
src/ObjTrackerNode_node.cpp
)
ament_target_dependencies(${PROJECT_NAME}-test ${dependencies})
target_include_directories(${PROJECT_NAME}-test PUBLIC
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ An opinionated ROS2 C++ node template, optimised for ISC.
2. `rosdep install --from-paths . --ignore-src -r -y` to install deps
3. `colcon build` to make sure the repo builds before you mess with it
4. Replace the following in both file names and code exactly and consistently.
1. TODO_PACKAGE_NAME: Replace with the package name. Use snake case. Ex. `data_logger`
2. TODO_NODE_NAME: Replace with the node name. Use Pascal case. Ex. `DataLogger`
1. obj_tracker: Replace with the package name. Use snake case. Ex. `data_logger`
2. ObjTrackerNode: Replace with the node name. Use Pascal case. Ex. `DataLogger`
5. `colcon build` again. If it builds, you are done
6. Rename outer folder
7. Review the optional dependencies, and remove what you do not need
Expand All @@ -29,19 +29,19 @@ These are marked with TODO_EXTRA.
```
.
├── include
│   └── TODO_PACKAGE_NAME
│   └── TODO_NODE_NAME_node.hpp
│   └── obj_tracker
│   └── ObjTrackerNode_node.hpp
├── package.xml
├── README.md
├── src
│   ├── TODO_NODE_NAME.cpp
│   └── TODO_NODE_NAME_node.cpp
│   ├── ObjTrackerNode.cpp
│   └── ObjTrackerNode_node.cpp
└── tests
└── unit.cpp
```

TODO_NODE_NAME_node: Source files for the ROS2 node object itself, and only itself
ObjTrackerNode_node: Source files for the ROS2 node object itself, and only itself

TODO_NODE_NAME.cpp: Source for the main function of the node, and only the main function
ObjTrackerNode.cpp: Source for the main function of the node, and only the main function

tests/unit.cpp: Example file for unit tests. This is linked to the node and ros, so both can be used
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

class TODO_NODE_NAME : public rclcpp::Node {
class ObjTrackerNode : public rclcpp::Node {
private:
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub;

rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub;

public:
TODO_NODE_NAME(const rclcpp::NodeOptions& options);
ObjTrackerNode(const rclcpp::NodeOptions& options);

/// subscriber callback
void sub_cb(std_msgs::msg::String::SharedPtr msg);
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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>TODO_PACKAGE_NAME</name>
<name>obj_tracker</name>
<version>0.1.0</version>
<description>A node template</description>
<maintainer email="[email protected]">Andrew Ealovega</maintainer>
Expand Down
4 changes: 2 additions & 2 deletions src/TODO_NODE_NAME.cpp → src/ObjTrackerNode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "TODO_PACKAGE_NAME/TODO_NODE_NAME_node.hpp"
#include "obj_tracker/ObjTrackerNode_node.hpp"

int main(int argc, char** argv) {
// Setup runtime
Expand All @@ -7,7 +7,7 @@ int main(int argc, char** argv) {
rclcpp::NodeOptions options;

// Add nodes to executor
auto node = std::make_shared<TODO_NODE_NAME>(options);
auto node = std::make_shared<ObjTrackerNode>(options);
exec.add_node(node);

// Run
Expand Down
8 changes: 4 additions & 4 deletions src/TODO_NODE_NAME_node.cpp → src/ObjTrackerNode_node.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "TODO_PACKAGE_NAME/TODO_NODE_NAME_node.hpp"
#include "obj_tracker/ObjTrackerNode_node.hpp"

// For _1
using namespace std::placeholders;

TODO_NODE_NAME::TODO_NODE_NAME(const rclcpp::NodeOptions& options) : Node("TODO_NODE_NAME", options) {
ObjTrackerNode::ObjTrackerNode(const rclcpp::NodeOptions& options) : Node("ObjTrackerNode", options) {
// Parameters
float x = this->declare_parameter<float>("foo", -10.0);

// Pub Sub
this->sub =
this->create_subscription<std_msgs::msg::String>("/str", 1, std::bind(&TODO_NODE_NAME::sub_cb, this, _1));
this->create_subscription<std_msgs::msg::String>("/str", 1, std::bind(&ObjTrackerNode::sub_cb, this, _1));
this->pub = this->create_publisher<std_msgs::msg::String>("/run_folder", 1);

// Log a sample log
Expand All @@ -21,7 +21,7 @@ TODO_NODE_NAME::TODO_NODE_NAME(const rclcpp::NodeOptions& options) : Node("TODO_
pub->publish(msg);
}

void TODO_NODE_NAME::sub_cb(const std_msgs::msg::String::SharedPtr msg) {
void ObjTrackerNode::sub_cb(const std_msgs::msg::String::SharedPtr msg) {
// Echo message
this->pub->publish(*msg);
}
4 changes: 2 additions & 2 deletions tests/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <rclcpp/rclcpp.hpp>

#include "TODO_PACKAGE_NAME/TODO_NODE_NAME_node.hpp"
#include "obj_tracker/ObjTrackerNode_node.hpp"

TEST(TODO_NODE_NAME, Test1) {}
TEST(ObjTrackerNode, Test1) {}

int main(int argc, char** argv) {
rclcpp::init(0, nullptr);
Expand Down

0 comments on commit 5292b34

Please sign in to comment.