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
2 changes: 2 additions & 0 deletions software_training_assignment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/
software_training_assignment/launch/__pycache__/
164 changes: 164 additions & 0 deletions software_training_assignment/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
cmake_minimum_required(VERSION 3.5)
project(software_training_assignment)

# 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()

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(turtlesim REQUIRED)
find_package(geometry_msgs REQUIRED)

find_package(rclcpp_action REQUIRED)

find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)

include_directories(include)

set(node_plugins "")

# custom services and messages and actions
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/ExampleService.srv"
"msg/Position.msg"
"action/MoveTo.action"
DEPENDENCIES std_msgs geometry_msgs builtin_interfaces)
ament_export_dependencies(rosidl_default_runtime)

#spawn turtles
add_library(spawn_turtle SHARED
src/spawn_turtle.cpp)
target_include_directories(spawn_turtle PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(spawn_turtle
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(spawn_turtle
"turtlesim"
"rclcpp"
"rclcpp_components")
rclcpp_components_register_node(spawn_turtle PLUGIN "composition::SpawnTurtle" EXECUTABLE spawn)

#clear turtles
add_library(clear SHARED
src/clear_turtle.cpp)
target_include_directories(clear PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(clear
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(clear
"turtlesim"
"rclcpp"
"rclcpp_components")
rclcpp_components_register_node(clear PLUGIN "composition::ClearTurtle" EXECUTABLE clear_turtle)

#rotate turtle 1
add_library(rotate SHARED
src/rotate_turtle1.cpp)
target_include_directories(rotate PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(rotate
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(rotate
"turtlesim"
"rclcpp"
"rclcpp_components"
"geometry_msgs")
rclcpp_components_register_node(rotate PLUGIN "composition::RotateTurtle" EXECUTABLE rotate_turtle)

#reset turtle service
add_library(reset SHARED
src/reset_moving.cpp)
target_include_directories(reset PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(reset
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(reset
"turtlesim"
"rclcpp"
"rclcpp_components")
rosidl_target_interfaces(reset ${PROJECT_NAME} "rosidl_typesupport_cpp")
rclcpp_components_register_node(reset PLUGIN "composition::ResetMoving" EXECUTABLE reset_turtle)

#stationary position publisher
add_library(pos_pub SHARED
src/stationary_position_publisher.cpp)
target_include_directories(pos_pub PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(pos_pub
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(pos_pub
"turtlesim"
"rclcpp"
"rclcpp_components")
rosidl_target_interfaces(pos_pub ${PROJECT_NAME} "rosidl_typesupport_cpp")
rclcpp_components_register_node(pos_pub PLUGIN "composition::StationaryPosPublisher" EXECUTABLE stationary_publisher)

#move turtle server
add_library(move_server SHARED
src/move_turtle_server.cpp)
target_include_directories(move_server PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(move_server
PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(move_server
"turtlesim"
"rclcpp"
"rclcpp_components"
"rclcpp_action")
rosidl_target_interfaces(move_server ${PROJECT_NAME} "rosidl_typesupport_cpp")
rclcpp_components_register_node(move_server PLUGIN "composition::MoveTurtleServer" EXECUTABLE move_turtle)


install(TARGETS
spawn_turtle
clear
rotate
reset
pos_pub
move_server
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

# Install launch files.
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)


ament_package()




5 changes: 5 additions & 0 deletions software_training_assignment/action/MoveTo.action
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
float32[] position
---
int32 seconds
---
float32 distance
28 changes: 28 additions & 0 deletions software_training_assignment/include/clear_turtle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef CLEAR_H
#define CLEAR_H

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include <turtlesim/srv/kill.hpp>
#include <visibility.h>

namespace composition
{
class ClearTurtle : public rclcpp::Node
{
public:
SOFTWARE_TRAINING_PUBLIC
explicit ClearTurtle(const rclcpp::NodeOptions & options);

private:
SOFTWARE_TRAINING_LOCAL
rclcpp::Client<turtlesim::srv::Kill>::SharedPtr client;
rclcpp::TimerBase::SharedPtr timer;

void kill_turtles();

};
}

#endif
42 changes: 42 additions & 0 deletions software_training_assignment/include/move_turtle_server.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef MOVE_H
#define MOVE_H

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"
#include "rclcpp_action/rclcpp_action.hpp"

#include <turtlesim/msg/pose.hpp>
#include <geometry_msgs/msg/twist.hpp>

#include <software_training_assignment/action/move_to.hpp>

namespace composition
{
class MoveTurtleServer : public rclcpp::Node
{
public:
using MoveTo = software_training_assignment::action::MoveTo;
using GoalHandleMoveTo = rclcpp_action::ServerGoalHandle<MoveTo>;

MoveTurtleServer(const rclcpp::NodeOptions & options);

private:
rclcpp_action::Server<MoveTo>::SharedPtr action_server;
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher;
rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr pose_sub;

float curr_x;
float curr_y;
std::vector<float> target;

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

rclcpp_action::CancelResponse handle_cancel(const std::shared_ptr<GoalHandleMoveTo> goal_handle);
void handle_accepted(const std::shared_ptr<GoalHandleMoveTo> goal_handle);
void execute(const std::shared_ptr<GoalHandleMoveTo> goal_handle);
void get_pose(const turtlesim::msg::Pose::SharedPtr currentPose);
};
}

#endif
31 changes: 31 additions & 0 deletions software_training_assignment/include/reset_moving.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef RESET_H
#define RESET_H

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include <visibility.h>
#include <software_training_assignment/srv/example_service.hpp>
#include <turtlesim/srv/teleport_absolute.hpp>

#include <turtle_info.hpp>
#include <string>

namespace composition
{
class ResetMoving : public rclcpp::Node
{
public:
explicit ResetMoving(const rclcpp::NodeOptions & options);

private:
rclcpp::Client<turtlesim::srv::TeleportAbsolute>::SharedPtr teleport_cli;
rclcpp::Service<software_training_assignment::srv::ExampleService>::SharedPtr teleport_srv;

void reset_moving_turtle(
const std::shared_ptr<software_training_assignment::srv::ExampleService::Request> request,
std::shared_ptr<software_training_assignment::srv::ExampleService::Response> response);
};
}

#endif
22 changes: 22 additions & 0 deletions software_training_assignment/include/rotate_turtle1.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef ROTATE_H
#define ROTATE_H

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include <geometry_msgs/msg/twist.hpp>

namespace composition
{
class RotateTurtle : public rclcpp::Node
{
public:
explicit RotateTurtle(const rclcpp::NodeOptions & options);

private:
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher;
void callback();
};
}

#endif
30 changes: 30 additions & 0 deletions software_training_assignment/include/spawn_turtle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef SPAWN_H
#define SPAWN_H

#include <rclcpp/rclcpp.hpp>
#include <rclcpp_components/register_node_macro.hpp>

#include "turtlesim/srv/spawn.hpp"

#include <turtle_info.hpp>
#include <visibility.h>
#include <thread>

namespace composition
{
class SpawnTurtle : public rclcpp::Node
{
public:
SOFTWARE_TRAINING_PUBLIC
explicit SpawnTurtle(const rclcpp::NodeOptions &options);

private:
rclcpp::Client<turtlesim::srv::Spawn>::SharedPtr srv_client;
rclcpp::TimerBase::SharedPtr timer;

SOFTWARE_TRAINING_LOCAL
void spawn_turtles();
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef STAT_POS_H
#define STAT_POS_HS

#include <rclcpp/rclcpp.hpp>
#include <rclcpp_components/register_node_macro.hpp>

#include <software_training_assignment/msg/position.hpp>
#include <turtle_info.hpp>
#include <turtlesim/msg/pose.hpp>
#include <geometry_msgs/msg/pose.hpp>

#include <math.h>

namespace composition
{
class StationaryPosPublisher : public rclcpp::Node
{
public:
StationaryPosPublisher(const rclcpp::NodeOptions &options);

private:
rclcpp::Publisher<software_training_assignment::msg::Position>::SharedPtr publisher;
rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr pose_sub;

void get_pose(const turtlesim::msg::Pose::SharedPtr currentPose);
};
}

#endif
13 changes: 13 additions & 0 deletions software_training_assignment/include/turtle_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef TURTLE_INFO_H
#define TURTLE_INFO_H

#include <map>
#include <vector>


std::map<std::string, std::vector<int>> turtles {
{ "moving_turtle", { 10, 10} },
{ "stationary_turtle", { 5, 5 } }
};

#endif
Loading