Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ src/oliver_pkg @GoldenGuy1000
src/james_pkg @jhaddixcodes
src/ben_pkg @benvrao
src/cole_pkg @cole-wilson
src/estefania_pkg @EstefaniaC-M
src/ziang_pkg @zichen04

.clang-format @ryden-handsaker
Expand Down
44 changes: 44 additions & 0 deletions src/estefania_pkg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.8)
project(estefania_pkg)

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(onboarding_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

add_executable(estefania_publisher src/estefania_publisher.cpp)
add_executable(estefania_subscriber src/estefania_subscriber.cpp)

ament_target_dependencies(estefania_publisher rclcpp std_msgs)
ament_target_dependencies(estefania_subscriber rclcpp onboarding_msgs std_msgs)
install(TARGETS
estefania_publisher
estefania_subscriber
DESTINATION lib/${PROJECT_NAME})

install(DIRECTORY
launch
DESTINATION share/${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()
9 changes: 9 additions & 0 deletions src/estefania_pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# estefania_pkg

This package contains a publisher and subscriber.

The publisher publishes random `std_msgs/msg/Float32` values to the
`estefania_topic` topic at 0.5 Hz.

The subscriber listens to `estefania_topic`, summarizes the received
value, and sends the summary to the `echo_string` service.
5 changes: 5 additions & 0 deletions src/estefania_pkg/launch/all.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<node pkg="estefania_pkg" exec="estefania_publisher"/>
<node pkg="estefania_pkg" exec="estefania_subscriber"/>
</launch>
21 changes: 21 additions & 0 deletions src/estefania_pkg/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>estefania_pkg</name>
<version>0.0.0</version>
<description>Publisher and subscriber for the Estefania onboarding task.</description>
<maintainer email="e.correa-mendez@wsu.edu">Estefania Correa-Mendez</maintainer>
<license>MIT</license>

<depend>onboarding_msgs</depend>
<depend>rclcpp</depend>
<depend>std_msgs</depend>

<buildtool_depend>ament_cmake</buildtool_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
45 changes: 45 additions & 0 deletions src/estefania_pkg/src/estefania_publisher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <chrono>
#include <memory>
#include <random>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/float32.hpp"

using namespace std::chrono_literals;

class EstefaniaPublisher : public rclcpp::Node {
public:
EstefaniaPublisher() :
Node("estefania_publisher"), generator_(std::random_device{}()),
distribution_(0.0f, 100.0f) {
publisher_ = this->create_publisher<std_msgs::msg::Float32>(
"estefania_topic", 10
);

timer_ = this->create_wall_timer(
2s, std::bind(&EstefaniaPublisher::publish_message, this)
);
}

private:
void publish_message() {
std_msgs::msg::Float32 message;
message.data = distribution_(generator_);

publisher_->publish(message);
}

rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr publisher_;
rclcpp::TimerBase::SharedPtr timer_;

std::mt19937 generator_;
std::uniform_real_distribution<float> distribution_;
};

int main(int argc, char* argv[]) {
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<EstefaniaPublisher>());
rclcpp::shutdown();

return 0;
}
56 changes: 56 additions & 0 deletions src/estefania_pkg/src/estefania_subscriber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <functional>
#include <memory>
#include <string>

#include "onboarding_msgs/srv/echo_string.hpp"
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/float32.hpp"

class EstefaniaSubscriber : public rclcpp::Node {
public:
EstefaniaSubscriber() : Node("estefania_subscriber") {
subscription_ = this->create_subscription<std_msgs::msg::Float32>(
"estefania_topic", 10,
std::bind(
&EstefaniaSubscriber::topic_callback, this,
std::placeholders::_1
)
);

client_ = this->create_client<onboarding_msgs::srv::EchoString>(
"echo_string"
);
}

private:
void topic_callback(const std_msgs::msg::Float32::SharedPtr message) {
std::string summary =
"Estefania received the value: " + std::to_string(message->data);

if (!client_->wait_for_service(std::chrono::seconds(1))) {
RCLCPP_WARN(this->get_logger(), "Echo service is not available.");
return;
}

auto request =
std::make_shared<onboarding_msgs::srv::EchoString::Request>();

request->data = summary;

client_->async_send_request(request);
}

rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr subscription_;

rclcpp::Client<onboarding_msgs::srv::EchoString>::SharedPtr client_;
};

int main(int argc, char* argv[]) {
rclcpp::init(argc, argv);

rclcpp::spin(std::make_shared<EstefaniaSubscriber>());

rclcpp::shutdown();

return 0;
}
1 change: 1 addition & 0 deletions src/onboarding/launch/all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<include file="$(find-pkg-share james_pkg)/launch/all.xml" />
<include file="$(find-pkg-share ben_pkg)/launch/all.xml" />
<include file="$(find-pkg-share cole_pkg)/launch/all.xml" />
<include file="$(find-pkg-share estefania_pkg)/launch/all.xml" />
<include file="$(find-pkg-share ziang_pkg)/launch/all.xml" />

</launch>
Loading