Skip to content
Open
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
188 changes: 188 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
cmake_minimum_required(VERSION 3.5)
project(ros_tut)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

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(turtlesim REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rcutils REQUIRED)
find_package(rcl REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
include_directories(include)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Num.msg"
"srv/AddThreeInts.srv"
"srv/Success.srv"
"msg/Distance.msg"
"action/Software.action"
DEPENDENCIES std_msgs geometry_msgs builtin_interfaces
)

# add_executable(talker src/my_publisher.cpp)
# ament_target_dependencies(talker rclcpp std_msgs)
# add_executable(my_node src/my_node.cpp)
# add_executable(listener src/my_subscriber.cpp)
# ament_target_dependencies(listener rclcpp std_msgs)


# add_executable(server src/add_two_ints_server.cpp)
# ament_target_dependencies(server
# rclcpp example_interfaces)
# add_executable(client src/add_two_ints_client.cpp)
# ament_target_dependencies(client
# rclcpp example_interfaces)

# add_executable(clear src/clear_turtles.cpp)
# ament_target_dependencies(clear
# rclcpp )

# target_include_directories(my_node PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# $<INSTALL_INTERFACE:include>)

#add kill_turtles as a plugin
add_library(kill_turtles SHARED
src/clear_turtles.cpp)
target_compile_definitions(kill_turtles
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(kill_turtles
"rclcpp"
"rclcpp_components"
"turtlesim"
"std_msgs")
rclcpp_components_register_nodes(kill_turtles "composition::kill_turtles")
# this way we can execute the component with - ros2 component standalone software_training composition::turtle_service_request_node
set(node_plugins "${node_plugins}compositon::kill_turtles;$<TARGET_FILE:kill_turtles>\n")

add_library(circle SHARED
src/circle.cpp)
target_compile_definitions(circle
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(circle
"rclcpp"
"rclcpp_components"
"turtlesim"
"geometry_msgs")
rclcpp_components_register_nodes(circle "composition::circle")
# this way we can execute the component with - ros2 component standalone software_training composition::turtle_service_request_node
set(node_plugins "${node_plugins}compositon::circle;$<TARGET_FILE:circle>\n")

add_library(spawn SHARED
src/spawn.cpp)
target_compile_definitions(spawn
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(spawn
"rclcpp"
"rclcpp_components"
"turtlesim"
"std_msgs")
rclcpp_components_register_nodes(spawn "composition::spawn")
# this way we can execute the component with - ros2 component standalone software_training composition::turtle_service_request_node
set(node_plugins "${node_plugins}compositon::spawn;$<TARGET_FILE:spawn>\n")

add_library(reset SHARED
src/reset.cpp)
target_compile_definitions(reset
PRIVATE "COMPOSITION_BUILDING_DLL"
)
ament_target_dependencies(reset
"rclcpp"
"rclcpp_components"
"turtlesim"
"turtlesim"
"std_msgs")
rosidl_target_interfaces(reset ${PROJECT_NAME} "rosidl_typesupport_cpp") # need for custom srv
rclcpp_components_register_nodes(reset "composition::reset")
set(node_plugins "${node_plugins}composition::reset;$<TARGET_FILE:reset\n">)

add_library(publisher SHARED
src/publisher.cpp)
target_compile_definitions(publisher
PRIVATE "COMPOSITION_BUILDING_DLL"
)
ament_target_dependencies(publisher
"rclcpp"
"rclcpp_components"
"turtlesim"
"std_msgs")
rosidl_target_interfaces(publisher ${PROJECT_NAME} "rosidl_typesupport_cpp") # need this for custom messages - idk why tho
rclcpp_components_register_nodes(publisher "composition::publisher")
set(node_plugins "${node_plugins}composition::publisher;$<TARGET_FILE:turtle_pub\n>")

# add_library(action SHARED
# src/action.cpp)
# target_compile_definitions(action
# PRIVATE "COMPOSITION_BUILDING_DLL")
# ament_target_dependencies(action
# "rclcpp"
# "rclcpp_components"
# "turtlesim"
# "rclcpp_action"
# "std_msgs"
# "geometry_msgs")
# rosidl_target_interfaces(action ${PROJECT_NAME} "rosidl_typesupport_cpp") # needed for custom action
# # with this we can exexute the component as a node - ros2 run software_training moving_action_server
# rclcpp_components_register_node(action PLUGIN "composition::action" EXECUTABLE action)
add_library(turtle_action_server SHARED
src/action.cpp)
target_compile_definitions(turtle_action_server
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(turtle_action_server
"rclcpp"
"rclcpp_components"
"turtlesim"
"rclcpp_action"
"std_msgs"
"geometry_msgs")
rosidl_target_interfaces(turtle_action_server ${PROJECT_NAME} "rosidl_typesupport_cpp") # needed for custom action
# with this we can exexute the component as a node - ros2 run software_training moving_action_server
# rclcpp_components_register_node(turtle_action_server PLUGIN "composition::action" EXECUTABLE action)
# rclcpp_components_register_nodes(turtle_action_server "composition::action")
rclcpp_components_register_nodes(turtle_action_server "composition::action")
# this way we can execute the component with - ros2 component standalone software_training composition::turtle_service_request_node
set(turtle_action_server "${node_plugins}compositon::action;$<TARGET_FILE:action>\n")



install(TARGETS
# my_node
# talker
# listener
kill_turtles
circle
spawn
reset
turtle_action_server
publisher
# server
# client
RUNTIME DESTINATION lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION bin)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
8 changes: 8 additions & 0 deletions action/Software.action
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
geometry_msgs/Vector3 linear_pos
geometry_msgs/Vector3 angular_pos
---
uint64 duration
---
float32 x_pos
float32 y_pos
float32 theta_pos
57 changes: 57 additions & 0 deletions include/ros-tut/action.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef ACTION_HPP_
#define ACTION_HPP_

// #include <ros_tut/visibility.h>

#include <chrono>
#include <functional>
#include <geometry_msgs/msg/twist.hpp> // cmd_vel publisher message
#include <memory>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp/time.hpp> // ros2 time header
#include <rclcpp_action/rclcpp_action.hpp> // ros2 action header
#include <ros_tut/action/software.hpp>
#include <thread>
#include <turtlesim/msg/pose.hpp> // header for message to get moving turt position

namespace composition {

class action : public rclcpp::Node {
public:
explicit action(const rclcpp::NodeOptions &options);

// nice to have to prevent lengthy repitive code
using GoalHandleActionServer = rclcpp_action::ServerGoalHandle<ros_tut::action::Software>;

private:
// action server
rclcpp_action::Server<ros_tut::action::Software>::SharedPtr action_server;

rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher;

rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr subscriber;

rclcpp_action::GoalResponse handle_goal(const rclcpp_action::GoalUUID &uuid,
std::shared_ptr<const ros_tut::action::Software::Goal> goal);

rclcpp_action::CancelResponse handle_cancel(const std::shared_ptr<GoalHandleActionServer> goal_handle);

// handle accepetd callback function
void handle_accepted(const std::shared_ptr<GoalHandleActionServer> goal_handle);

// executioner callback function
void execute(const std::shared_ptr<GoalHandleActionServer> goal_handle);

// for subscriber
static float x;
static float y;
static float theta;
static float linear_velocity;
static float angular_velocity;

static constexpr unsigned int QUEUE{10};
};

} // namespace composition

#endif // MOVING_TURTLE_ACTION_SERVER_HPP_
35 changes: 35 additions & 0 deletions include/ros-tut/circle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// #ifndef TURTLE_SERVICE_REQUEST_NODE_HPP_
// #define TURTLE_SERVICE_REQUEST_NODE_HPP_
#ifndef TURTLE_SERVICE_REQUEST_NODE_HPP_
#define TURTLE_SERVICE_REQUEST_NODE_HPP_



#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <vector>

#include <rclcpp/rclcpp.hpp>

// #include <software_training/visibility.h>
#include <turtlesim/msg/pose.hpp>
#include "geometry_msgs/msg/twist.hpp"
namespace composition{

class circle : public rclcpp::Node {

public:
explicit circle(const rclcpp::NodeOptions &options);

private:
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher;
rclcpp::TimerBase::SharedPtr timer;

void circleBoi();

};
}

#endif
34 changes: 34 additions & 0 deletions include/ros-tut/publisher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// #include <ros-tut/visibility.h>

#include <memory>
#include <rclcpp/rclcpp.hpp>
#include <ros_tut/msg/distance.hpp>
#include <turtlesim/msg/pose.hpp>

namespace composition {

class publisher : public rclcpp::Node {
public:
explicit publisher(const rclcpp::NodeOptions &options);

private:
rclcpp::Publisher<ros_tut::msg::Distance>::SharedPtr publisher_val;

rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr sitting_turtle;
rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr moving_turtle;

rclcpp::TimerBase::SharedPtr timer;

rclcpp::CallbackGroup::SharedPtr callbacks;
void publish();
float x_sitting_turtle;
float y_sitting_turtle;

float x_moving_turtle;
float y_moving_turtle;

float distance;

static const unsigned int QUEUE{10};
};
} // namespace composition
37 changes: 37 additions & 0 deletions include/ros-tut/reset.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef TURTLE_SERVICE_REQUEST_NODE_HPP_
#define TURTLE_SERVICE_REQUEST_NODE_HPP_

#include <cstdlib>
#include <memory>
#include <rclcpp/rclcpp.hpp>
#include <ros_tut/srv/success.hpp>
#include <string>
#include <turtlesim/srv/teleport_absolute.hpp>
#include <vector>

using namespace std::placeholders;
using namespace std::chrono_literals;

// #include "rclcpp/rclcpp.hpp"
// #include "std_msgs/msg/string.hpp"
// #include "ros_tut/srv/add_three_ints.hpp"

namespace composition {

class reset : public rclcpp::Node {
public:
// SOFTWARE_TRAINING_PUBLIC //what is this?
explicit reset(const rclcpp::NodeOptions &options);

private:
rclcpp::Service<ros_tut::srv::Success>::SharedPtr service;
rclcpp::TimerBase::SharedPtr timer;

// all the turtles
rclcpp::Client<turtlesim::srv::TeleportAbsolute>::SharedPtr client;
// SOFTWARE_TRAINING_LOCAL //what is this?
void reset_service(const std::shared_ptr<ros_tut::srv::Success::Request> request,
std::shared_ptr<ros_tut::srv::Success::Response> response);
};
} // namespace composition
#endif
Loading