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

Jett Onboarding #96

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
72 changes: 72 additions & 0 deletions 10_Examples/jett-onboarding/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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(<dependency> 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()
21 changes: 21 additions & 0 deletions 10_Examples/jett-onboarding/package.xml
Original file line number Diff line number Diff line change
@@ -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>jett-onboarding</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">jettvanbrocklin</maintainer>
<license>TODO: License declaration</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>
14 changes: 14 additions & 0 deletions 10_Examples/jett-onboarding/src/hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "talking.h"
#include <iostream>
#include "string.h"

using namespace std;

int test();

int main(int argc, char ** argv)
{
talking t1;
t1.talk("Hello World");
return 0;
}
56 changes: 56 additions & 0 deletions 10_Examples/jett-onboarding/src/publisher_member_function.cpp
Original file line number Diff line number Diff line change
@@ -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 <chrono>
#include <memory>

#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<std_msgs::msg::String>("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<std_msgs::msg::String>::SharedPtr publisher_;
size_t count_;
};

int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<MinimalPublisher>());
rclcpp::shutdown();
return 0;
}
45 changes: 45 additions & 0 deletions 10_Examples/jett-onboarding/src/subscriber_member_function.cpp
Original file line number Diff line number Diff line change
@@ -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 <memory>

#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>
using std::placeholders::_1;

class MinimalSubscriber : public rclcpp::Node
{
public:
MinimalSubscriber()
: Node("minimal_subscriber")
{
subscription_ = this->create_subscription<std_msgs::msg::String>(
"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<std_msgs::msg::String>::SharedPtr subscription_;
};

int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<MinimalSubscriber>());
rclcpp::shutdown();
return 0;
}
36 changes: 36 additions & 0 deletions 10_Examples/jett-onboarding/src/talking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "talking.h"
#include <iostream>
#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;
}
23 changes: 23 additions & 0 deletions 10_Examples/jett-onboarding/src/talking.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef TALKING_H_
#define TALKING_H_

#include <iostream>
#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
43 changes: 43 additions & 0 deletions 10_Examples/jett-onboarding/src/testFile.cpp
Original file line number Diff line number Diff line change
@@ -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<talking>();
}

void SetUp() override
{
}

void TearDown() override
{
}

std::shared_ptr<talking> 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();
// }
Loading