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

swtraining #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
swtraining/install/
swtraining/log/
swtraining/build/
134 changes: 134 additions & 0 deletions swtraining/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
cmake_minimum_required(VERSION 3.5)
project(swtraining)

# 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(geometry_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(turtlesim REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(rcutils REQUIRED)

#include the "include" directory
include_directories(include)

rosidl_generate_interfaces(${PROJECT_NAME}
"action/Waypt.action"
"srv/Status.srv"
"msg/Distance.msg"
)

ament_export_dependencies(rosidl_default_runtime)
set(node_plugins "")

add_library(clearturtles SHARED src/clearturtles.cpp)
target_compile_definitions(clearturtles PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(clearturtles
"rclcpp"
"rclcpp_components"
"turtlesim"
)
rosidl_target_interfaces(clearturtles ${PROJECT_NAME} "rosidl_typesupport_cpp")
rclcpp_components_register_nodes(clearturtles "composition::clearturtles")
set(node_plugins "${node_plugins}compose::clearturtles;$<TARGET_FILE:clearturtles\n>")

add_library(drawCircle SHARED src/drawCircle.cpp)
target_compile_definitions(drawCircle PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(drawCircle
"rclcpp"
"rclcpp_components"
"turtlesim"
"geometry_msgs"
)
rosidl_target_interfaces(drawCircle ${PROJECT_NAME} "rosidl_typesupport_cpp")
rclcpp_components_register_nodes(drawCircle "composition::drawCircle")
set(node_plugins "${node_plugins}composition::drawCircle;$<TARGET_FILE:drawCircle\n>")

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

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

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


add_library(waypoint SHARED src/waypoint.cpp)
target_compile_definitions(waypoint PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(waypoint
"rclcpp"
"rclcpp_components"
"turtlesim"
"rclcpp_action"
"geometry_msgs"
)
rosidl_target_interfaces(waypoint ${PROJECT_NAME} "rosidl_typesupport_cpp")
rclcpp_components_register_nodes(waypoint "composition::waypoint")
set(node_plugins "${node_plugins}composition::waypoint;$<TARGET_FILE:waypoint\n>")



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

install(TARGETS
clearturtles
drawCircle
resetturtle
spawnturtles
turtledistance
waypoint
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME})

ament_package()
6 changes: 6 additions & 0 deletions swtraining/action/Waypt.action
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
float64 x
float64 y
---
uint64 wtime
---
float64 dist
27 changes: 27 additions & 0 deletions swtraining/include/swtraining/clearturtles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <rclcpp/rclcpp.hpp>
#include <turtlesim/srv/kill.hpp>
#include <swtraining/software_training_visibility.h>
#include <swtraining/srv/status.hpp>

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

namespace composition{
class clearturtles : public rclcpp::Node{
public:
SOFTWARE_TRAINING_PUBLIC
clearturtles(const rclcpp::NodeOptions & options);
private:
rclcpp::Client<turtlesim::srv::Kill>::SharedPtr clearClient;
rclcpp::Service<swtraining::srv::Status>::SharedPtr clearService;
std::vector<std::string> myTurtles;
SOFTWARE_TRAINING_LOCAL
void clearCB(const std::shared_ptr<swtraining::srv::Status::Request> request,std::shared_ptr<swtraining::srv::Status::Response> response);
};
}

25 changes: 25 additions & 0 deletions swtraining/include/swtraining/drawCircle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <rclcpp/rclcpp.hpp>
#include <geometry_msgs/msg/twist.hpp>
#include <swtraining/software_training_visibility.h>

#include <chrono>
#include <cstdlib>
#include <memory>


namespace composition {

class drawCircle : public rclcpp::Node
{
public:
SOFTWARE_TRAINING_PUBLIC
drawCircle(const rclcpp::NodeOptions &options);
private:
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr circlePub;
rclcpp::TimerBase::SharedPtr circleTimer;
SOFTWARE_TRAINING_LOCAL
void timerCB();
};
}
23 changes: 23 additions & 0 deletions swtraining/include/swtraining/resetturtle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <rclcpp/rclcpp.hpp>
#include <swtraining/srv/status.hpp>
#include <turtlesim/srv/teleport_absolute.hpp>
#include <swtraining/software_training_visibility.h>

#include <chrono>
#include <cstdlib>
#include <memory>

namespace composition {
class resetturtle:public rclcpp::Node{
public:
SOFTWARE_TRAINING_PUBLIC
resetturtle(const rclcpp::NodeOptions &options);
private:
rclcpp::Client<turtlesim::srv::TeleportAbsolute>::SharedPtr resetClient;
rclcpp::Service<swtraining::srv::Status>::SharedPtr resetService;
SOFTWARE_TRAINING_LOCAL
void resetCB(const std::shared_ptr<swtraining::srv::Status::Request> request, std::shared_ptr<swtraining::srv::Status::Response> response);
};
}
63 changes: 63 additions & 0 deletions swtraining/include/swtraining/software_training_visibility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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.

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__

#ifdef __GNUC__
#define SOFTWARE_TRAINING_EXPORT __attribute__((dllexport))
#define SOFTWARE_TRAINING_IMPORT __attribute__((dllimport))
#else
#define SOFTWARE_TRAINING_EXPORT __declspec(dllexport)
#define SOFTWARE_TRAINING_IMPORT __declspec(dllimport)
#endif

#ifdef SOFTWARE_TRAINING_DLL
#define SOFTWARE_TRAINING_PUBLIC SOFTWARE_TRAINING_EXPORT
#else
#define SOFTWARE_TRAINING_PUBLIC SOFTWARE_TRAINING_IMPORT
#endif

#define SOFTWARE_TRAINING_PUBLIC_TYPE SOFTWARE_TRAINING_PUBLIC

#define SOFTWARE_TRAINING_LOCAL

#else

#define SOFTWARE_TRAINING_EXPORT __attribute__((visibility("default")))
#define SOFTWARE_TRAINING_IMPORT

#if __GNUC__ >= 4
#define SOFTWARE_TRAINING_PUBLIC __attribute__((visibility("default")))
#define SOFTWARE_TRAINING_LOCAL __attribute__((visibility("hidden")))
#else
#define SOFTWARE_TRAINING_PUBLIC
#define SOFTWARE_TRAINING_LOCAL
#endif

#define SOFTWARE_TRAINING_PUBLIC_TYPE
#endif

#ifdef __cplusplus
}
#endif

36 changes: 36 additions & 0 deletions swtraining/include/swtraining/spawnturtles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include <rclcpp/rclcpp.hpp>
#include <turtlesim/srv/spawn.hpp>
#include <swtraining/srv/status.hpp>
#include <swtraining/software_training_visibility.h>

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

namespace composition{

class spawnturtles : public rclcpp::Node {

public:
SOFTWARE_TRAINING_PUBLIC
spawnturtles(const rclcpp::NodeOptions &options);

private:
rclcpp::Client<turtlesim::srv::Spawn>::SharedPtr spawnClient;
rclcpp::Service<swtraining::srv::Status>::SharedPtr spawnService;

typedef struct params{
float x;
float y;
float theta;
std::string name;
}params;

std::vector<params> myTurtles;
SOFTWARE_TRAINING_LOCAL
void spawnCB(const std::shared_ptr<swtraining::srv::Status::Request> request,std::shared_ptr<swtraining::srv::Status::Response> response);
};
}
34 changes: 34 additions & 0 deletions swtraining/include/swtraining/turtledistance.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <rclcpp/rclcpp.hpp>
#include <turtlesim/msg/pose.hpp>
#include <swtraining/msg/distance.hpp>
#include <swtraining/software_training_visibility.h>

#include <chrono>
#include <cstdlib>
#include <memory>


namespace composition{
class turtledistance : public rclcpp::Node{
public:
SOFTWARE_TRAINING_PUBLIC
turtledistance(const rclcpp::NodeOptions &options);
private:
rclcpp::TimerBase::SharedPtr distTimer;
rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr stSub;
rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr mtSub;
rclcpp::Publisher<swtraining::msg::Distance>::SharedPtr distPub;
double stx;
double sty;
double mtx;
double mty;
SOFTWARE_TRAINING_LOCAL
void timerCB();
SOFTWARE_TRAINING_LOCAL
void mtCB(const turtlesim::msg::Pose::SharedPtr res);
SOFTWARE_TRAINING_LOCAL
void stCB(const turtlesim::msg::Pose::SharedPtr res);
};
}
Loading