diff --git a/10_Examples/jett-onboarding/CMakeLists.txt b/10_Examples/jett-onboarding/CMakeLists.txt new file mode 100644 index 00000000..91be2267 --- /dev/null +++ b/10_Examples/jett-onboarding/CMakeLists.txt @@ -0,0 +1,72 @@ +cmake_minimum_required(VERSION 3.8) +project(jett-onboarding) + +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) + +find_package(ament_cmake_gtest REQUIRED) + +# uncomment the following section in order to fill in +# further dependencies manually. +# find_package( REQUIRED) +add_executable(listener src/subscriber_member_function.cpp) +ament_target_dependencies(listener rclcpp std_msgs) + +add_executable(talker src/publisher_member_function.cpp) +ament_target_dependencies(talker rclcpp std_msgs) +install(TARGETS + talker + listener + DESTINATION lib/${PROJECT_NAME}) + +add_executable(hello_world src/hello_world.cpp) +install(TARGETS + hello_world + DESTINATION lib/${PROJECT_NAME}) +target_link_libraries(hello_world +talking +) + +# Add Class as Library to allow it to share across files easier probably +add_library(talking SHARED src/talking.cpp) +ament_target_dependencies(talking + ${DEPENDENCIES} +) +ament_export_targets(talking HAS_LIBRARY_TARGET) +install( + TARGETS talking + EXPORT talking + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include + ) + + +ament_add_gtest(testFile src/testFile.cpp) +target_link_libraries(testFile + talking + gtest_main +) + +# 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() diff --git a/10_Examples/jett-onboarding/package.xml b/10_Examples/jett-onboarding/package.xml new file mode 100644 index 00000000..3af362a4 --- /dev/null +++ b/10_Examples/jett-onboarding/package.xml @@ -0,0 +1,21 @@ + + + + jett-onboarding + 0.0.0 + TODO: Package description + jettvanbrocklin + TODO: License declaration + + ament_cmake + + rclcpp + std_msgs + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/10_Examples/jett-onboarding/src/hello_world.cpp b/10_Examples/jett-onboarding/src/hello_world.cpp new file mode 100644 index 00000000..8482cc12 --- /dev/null +++ b/10_Examples/jett-onboarding/src/hello_world.cpp @@ -0,0 +1,14 @@ +#include "talking.h" +#include +#include "string.h" + +using namespace std; + +int test(); + +int main(int argc, char ** argv) +{ + talking t1; + t1.talk("Hello World"); + return 0; +} diff --git a/10_Examples/jett-onboarding/src/publisher_member_function.cpp b/10_Examples/jett-onboarding/src/publisher_member_function.cpp new file mode 100644 index 00000000..5b4a81bb --- /dev/null +++ b/10_Examples/jett-onboarding/src/publisher_member_function.cpp @@ -0,0 +1,56 @@ +// Copyright 2016 Open Source Robotics Foundation, Inc. +// +// 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 +#include + +#include "rclcpp/rclcpp.hpp" +#include "std_msgs/msg/string.hpp" + +using namespace std::chrono_literals; + +/* This example creates a subclass of Node and uses std::bind() to register a + * member function as a callback from the timer. */ + +class MinimalPublisher : public rclcpp::Node +{ +public: + MinimalPublisher() + : Node("minimal_publisher"), count_(0) + { + publisher_ = this->create_publisher("topic", 10); + timer_ = this->create_wall_timer( + 500ms, std::bind(&MinimalPublisher::timer_callback, this)); + } + +private: + void timer_callback() + { + auto message = std_msgs::msg::String(); + message.data = "Hello, world! " + std::to_string(count_++); + RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str()); + publisher_->publish(message); + } + rclcpp::TimerBase::SharedPtr timer_; + rclcpp::Publisher::SharedPtr publisher_; + size_t count_; +}; + +int main(int argc, char *argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} diff --git a/10_Examples/jett-onboarding/src/subscriber_member_function.cpp b/10_Examples/jett-onboarding/src/subscriber_member_function.cpp new file mode 100644 index 00000000..39d29f78 --- /dev/null +++ b/10_Examples/jett-onboarding/src/subscriber_member_function.cpp @@ -0,0 +1,45 @@ +// Copyright 2016 Open Source Robotics Foundation, Inc. +// +// 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 + +#include +#include +using std::placeholders::_1; + +class MinimalSubscriber : public rclcpp::Node +{ +public: + MinimalSubscriber() + : Node("minimal_subscriber") + { + subscription_ = this->create_subscription( + "topic", 10, std::bind(&MinimalSubscriber::topic_callback, this, _1)); + } + +private: + void topic_callback(const std_msgs::msg::String::SharedPtr msg) const + { + RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str()); + } + rclcpp::Subscription::SharedPtr subscription_; +}; + +int main(int argc, char *argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} diff --git a/10_Examples/jett-onboarding/src/talking.cpp b/10_Examples/jett-onboarding/src/talking.cpp new file mode 100644 index 00000000..91a2900a --- /dev/null +++ b/10_Examples/jett-onboarding/src/talking.cpp @@ -0,0 +1,36 @@ +#include "talking.h" +#include +#include "string.h" + +using namespace std; + +talking::talking() +{ + this->num1 = 10; +} + +talking::~talking() +{ +} + +string talking::talk(string words) +{ + cout << words << endl; + return words; +} + +int talking::numberPrint() +{ + cout << num1 << endl; + return num1; +} + +int talking::twoToPower(int i) +{ + int value = 1; + while (i > 0) { + value *= 2; + i--; + } + return value; +} diff --git a/10_Examples/jett-onboarding/src/talking.h b/10_Examples/jett-onboarding/src/talking.h new file mode 100644 index 00000000..a4b00f2b --- /dev/null +++ b/10_Examples/jett-onboarding/src/talking.h @@ -0,0 +1,23 @@ +#ifndef TALKING_H_ +#define TALKING_H_ + +#include +#include "string.h" + +using namespace std; + +class talking +{ +public: + int num1; + + talking(); // constructor + ~talking(); // destructor + + string talk(string words); + int numberPrint(); + + int twoToPower(int i); +}; + +#endif diff --git a/10_Examples/jett-onboarding/src/testFile.cpp b/10_Examples/jett-onboarding/src/testFile.cpp new file mode 100644 index 00000000..eb8a9cae --- /dev/null +++ b/10_Examples/jett-onboarding/src/testFile.cpp @@ -0,0 +1,43 @@ +#include "gtest/gtest.h" +#include "talking.h" +#include "string.h" + +class TestExample : public ::testing::Test +{ +protected: + TestExample() + { + talking_ = std::make_shared(); + } + + void SetUp() override + { + } + + void TearDown() override + { + } + + std::shared_ptr talking_; + +}; + +TEST_F(TestExample, testTalk) { + //testing the talk function + EXPECT_EQ("Test", talking_->talk("Test")); +} + +TEST_F(TestExample, testNumberPrint) { + EXPECT_TRUE(talking_->numberPrint() == talking_->num1); +} + +TEST_F(TestExample, testTwoToPower) { + EXPECT_EQ(talking_->twoToPower(5) == (2 ^ 5)); +} + + +// int main(int argc, char ** argv) +// { +// ::testing::InitGoogleTest(&argc, argv); +// return RUN_ALL_TESTS(); +// }