From 6937f7dc3aa9942c539f95590752d6ec0f770b71 Mon Sep 17 00:00:00 2001 From: hr-ti Date: Mon, 11 Jan 2021 00:11:31 -0500 Subject: [PATCH 1/8] initial commit --- .gitignore | 0 software_training_assignment | 1 + 2 files changed, 1 insertion(+) create mode 100644 .gitignore create mode 160000 software_training_assignment diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/software_training_assignment b/software_training_assignment new file mode 160000 index 0000000..d051c23 --- /dev/null +++ b/software_training_assignment @@ -0,0 +1 @@ +Subproject commit d051c2343c14b7d60e63bb882539b5bbc7861445 From 163a3a376c4c2f9bbf70f197f349e250a56d64ab Mon Sep 17 00:00:00 2001 From: hr-ti Date: Mon, 11 Jan 2021 00:17:50 -0500 Subject: [PATCH 2/8] initial commit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e69de29..b4eedb1 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +beginner_tutorials/ +dbus-1/ \ No newline at end of file From 5b2ef7f2538051a7878c7453daadb3b63f66edf7 Mon Sep 17 00:00:00 2001 From: hr-ti Date: Mon, 11 Jan 2021 00:20:16 -0500 Subject: [PATCH 3/8] initial commit --- software_training_assignment | 1 - software_training_assignment/CMakeLists.txt | 214 ++++++++++++++++++ .../action/Goto.action | 6 + .../launch/turtlebackground.launch | 10 + software_training_assignment/msg/Position.msg | 3 + software_training_assignment/package.xml | 69 ++++++ .../src/goto_action.h | 99 ++++++++ .../src/killTurtles.cpp | 26 +++ .../src/killTurtles.h | 8 + software_training_assignment/src/publisher.h | 32 +++ software_training_assignment/src/resetPos.cpp | 31 +++ software_training_assignment/src/resetPos.h | 9 + .../src/spawnTurtles.cpp | 31 +++ .../src/spawnTurtles.h | 8 + .../src/spawnturtle.cpp | 49 ++++ software_training_assignment/src/testing.cpp | 57 +++++ 16 files changed, 652 insertions(+), 1 deletion(-) delete mode 160000 software_training_assignment create mode 100644 software_training_assignment/CMakeLists.txt create mode 100644 software_training_assignment/action/Goto.action create mode 100644 software_training_assignment/launch/turtlebackground.launch create mode 100644 software_training_assignment/msg/Position.msg create mode 100644 software_training_assignment/package.xml create mode 100644 software_training_assignment/src/goto_action.h create mode 100644 software_training_assignment/src/killTurtles.cpp create mode 100644 software_training_assignment/src/killTurtles.h create mode 100644 software_training_assignment/src/publisher.h create mode 100644 software_training_assignment/src/resetPos.cpp create mode 100644 software_training_assignment/src/resetPos.h create mode 100644 software_training_assignment/src/spawnTurtles.cpp create mode 100644 software_training_assignment/src/spawnTurtles.h create mode 100644 software_training_assignment/src/spawnturtle.cpp create mode 100644 software_training_assignment/src/testing.cpp diff --git a/software_training_assignment b/software_training_assignment deleted file mode 160000 index d051c23..0000000 --- a/software_training_assignment +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d051c2343c14b7d60e63bb882539b5bbc7861445 diff --git a/software_training_assignment/CMakeLists.txt b/software_training_assignment/CMakeLists.txt new file mode 100644 index 0000000..781fb58 --- /dev/null +++ b/software_training_assignment/CMakeLists.txt @@ -0,0 +1,214 @@ +cmake_minimum_required(VERSION 3.0.2) +project(software_training_assignment) + +## Compile as C++11, supported in ROS Kinetic and newer +# add_compile_options(-std=c++11) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + roscpp + std_msgs + message_generation + turtlesim + actionlib + actionlib_msgs +) + +## System dependencies are found with CMake's conventions +find_package(Boost REQUIRED COMPONENTS system) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a exec_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder + add_message_files( + FILES + Position.msg + ) + +## Generate services in the 'srv' folder + add_service_files( + FILES + ) + +## Generate actions in the 'action' folder + add_action_files( + FILES + Goto.action + ) + +## Generate added messages and services with any dependencies listed here + generate_messages( + DEPENDENCIES + std_msgs + actionlib_msgs + ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a exec_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if your package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( + CATKIN_DEPENDS message_runtime actionlib_msgs +# INCLUDE_DIRS include +# LIBRARIES software_training_assignment +# CATKIN_DEPENDS roscpp std_msgs +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +include_directories( +# include + ${catkin_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(${PROJECT_NAME} +# src/${PROJECT_NAME}/software_training_assignment.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +## With catkin_make all packages are built within a single CMake context +## The recommended prefix ensures that target names across packages don't collide +# add_executable(${PROJECT_NAME}_node src/software_training_assignment_node.cpp) + +## Rename C++ executable without prefix +## The above recommended prefix causes long target names, the following renames the +## target back to the shorter version for ease of user use +## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" +# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(${PROJECT_NAME}_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# catkin_install_python(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables for installation +## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html +# install(TARGETS ${PROJECT_NAME}_node +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark libraries for installation +## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html +# install(TARGETS ${PROJECT_NAME} +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation + install(DIRECTORY include/${PROJECT_NAME}/ + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} + FILES_MATCHING PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) + +add_executable(spawnturtle src/spawnturtle.cpp) +target_link_libraries(spawnturtle ${catkin_LIBRARIES}) +# add_dependencies(spawnturtle software_training_assignment_gencpp) + +add_executable(testing src/testing.cpp) +target_link_libraries(testing ${catkin_LIBRARIES}) diff --git a/software_training_assignment/action/Goto.action b/software_training_assignment/action/Goto.action new file mode 100644 index 0000000..1d6804f --- /dev/null +++ b/software_training_assignment/action/Goto.action @@ -0,0 +1,6 @@ +float32 x +float32 y +--- +duration time_elapsed +--- +float32 distance diff --git a/software_training_assignment/launch/turtlebackground.launch b/software_training_assignment/launch/turtlebackground.launch new file mode 100644 index 0000000..cd24631 --- /dev/null +++ b/software_training_assignment/launch/turtlebackground.launch @@ -0,0 +1,10 @@ + + + + 128 + 128 + 0 + + + + diff --git a/software_training_assignment/msg/Position.msg b/software_training_assignment/msg/Position.msg new file mode 100644 index 0000000..e5ddcc8 --- /dev/null +++ b/software_training_assignment/msg/Position.msg @@ -0,0 +1,3 @@ +float32 x +float32 y +float32 distance diff --git a/software_training_assignment/package.xml b/software_training_assignment/package.xml new file mode 100644 index 0000000..33dc040 --- /dev/null +++ b/software_training_assignment/package.xml @@ -0,0 +1,69 @@ + + + software_training_assignment + 0.0.0 + The software_training_assignment package + + + + + htieu + + + + + + MIT + + + + + + + + + + + + + + + + + + + + + + + + message_generation + + + + + + message_runtime + + gtest + + + catkin + roscpp + std_msgs + roscpp + std_msgs + roscpp + std_msgs + turtlesim + turtlesim + actionlib + actionlib + actionlib_msgs + actionlib_msgs + + + + + + diff --git a/software_training_assignment/src/goto_action.h b/software_training_assignment/src/goto_action.h new file mode 100644 index 0000000..678c4cd --- /dev/null +++ b/software_training_assignment/src/goto_action.h @@ -0,0 +1,99 @@ +#include +#include +#include +#include + +namespace A +{ + class GotoAction + { + public: + ros::NodeHandle node; + actionlib::SimpleActionServer as_; + GotoAction(std::string name) : as_(node, name, boost::bind(&GotoAction::executeCB, this, _1), false) + { + as_.start(); + ROS_INFO("Action server started"); + } + + ~GotoAction(void) + { + } + + ros::Publisher pub; + ros::Subscriber sub; + double x, y; + + void subCallback(const turtlesim::Pose::ConstPtr& msg) + { + x = msg->x; + y = msg->y; + // ROS_INFO_STREAM("x: " << x << " y: " << y); + } + + void executeCB(const software_training_assignment::GotoGoal::ConstPtr &goal) + { + + ROS_INFO("executeCB called"); + double relativeX = goal->x - x, + relativeY = goal->y - y, + relativeDist = sqrt(pow(relativeX, 2) + pow(relativeY, 2)), + theta = acos(relativeX / relativeDist), + angVel = theta; + + if (relativeY < 0) + angVel *= -1; + + bool success = true; + + geometry_msgs::Twist rotation; + + feedback_.distance = relativeDist; + as_.publishFeedback(feedback_); + + rotation.angular.z = angVel; + + pub.publish(rotation); + + ros::Duration(1).sleep(); + + double gotoCount = (int)relativeDist / 2, gotoRe = relativeDist - (gotoCount * 2); + ros::Duration gotoDuration(1); + + geometry_msgs::Twist forward; + + forward.linear.x = 2; + for (int count = 0; count < gotoCount; count++) + { + if(as_.isPreemptRequested() || !ros::ok()) + { + as_.setPreempted(); + success = false; + break; + } + pub.publish(forward); + ros::Duration(1).sleep(); + gotoDuration += ros::Duration(1); + + } + + forward.linear.x = gotoRe; + + gotoDuration += ros::Duration(2); + + pub.publish(forward); + ros::Duration(1).sleep(); + + if (success) + { + result_.time_elapsed = gotoDuration; + as_.setSucceeded(result_); + } + + } + + protected: + software_training_assignment::GotoFeedback feedback_; + software_training_assignment::GotoResult result_; + }; +} \ No newline at end of file diff --git a/software_training_assignment/src/killTurtles.cpp b/software_training_assignment/src/killTurtles.cpp new file mode 100644 index 0000000..6d96556 --- /dev/null +++ b/software_training_assignment/src/killTurtles.cpp @@ -0,0 +1,26 @@ +#include +#include "killTurtles.h" + +bool killTurtles(ros::NodeHandle n) +{ + ros::ServiceClient killClient = n.serviceClient("kill"); + + ros::service::waitForService("kill"); + + turtlesim::Kill killSrv; + + killSrv.request.name = "turtle1"; + + + if (killClient.call(killSrv)) + { + ROS_INFO_STREAM (killSrv.request.name << " killed"); + } + else + { + ROS_ERROR("Failed to call service kill"); + return false; + } + + return true; +} \ No newline at end of file diff --git a/software_training_assignment/src/killTurtles.h b/software_training_assignment/src/killTurtles.h new file mode 100644 index 0000000..60d5bc3 --- /dev/null +++ b/software_training_assignment/src/killTurtles.h @@ -0,0 +1,8 @@ +#ifndef KILLTURTLES_H +#define KILLTURTLES_H + +#include + +bool killTurtles(ros::NodeHandle n); + +#endif \ No newline at end of file diff --git a/software_training_assignment/src/publisher.h b/software_training_assignment/src/publisher.h new file mode 100644 index 0000000..3d3adcf --- /dev/null +++ b/software_training_assignment/src/publisher.h @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +namespace P +{ + class Publisher + { + public: + void publisher() + { + software_training_assignment::Position msg; + msg.x = x - 5; + msg.y = y - 5; + msg.distance = sqrt(pow(msg.x, 2) + pow(msg.y, 2)); + + // ROS_INFO_STREAM("x:" << msg.x << " y: " << msg.y); + + pub.publish(msg); + } + void subCallback(const turtlesim::Pose::ConstPtr& msg) + { + x = msg->x; + y = msg->y; + // ROS_INFO_STREAM("moving turtle x: " << x << " y: " << y); + } + double x = 0, y = 0; + ros::Publisher pub; + ros::Subscriber sub; + }; +} \ No newline at end of file diff --git a/software_training_assignment/src/resetPos.cpp b/software_training_assignment/src/resetPos.cpp new file mode 100644 index 0000000..9b94d5a --- /dev/null +++ b/software_training_assignment/src/resetPos.cpp @@ -0,0 +1,31 @@ +#include +#include "resetPos.h" +#include "killTurtles.h" +#include "spawnTurtles.h" + +bool resetPos(std_srvs::Empty::Request &req, + std_srvs::Empty::Response &res) +{ + ros::NodeHandle n; + + ros::ServiceClient resetClient = n.serviceClient("reset"); + + ros::service::waitForService("reset"); + + std_srvs::Empty resetSrv; + + if (resetClient.call(resetSrv)) + { + killTurtles(n); + spawnTurtles(n, "stationary_turtle", 5, 5); + spawnTurtles(n, "moving_turtle", 25, 10); + ROS_INFO_STREAM ("Resetted"); + } + else + { + ROS_ERROR("Failed to call service reset"); + return false; + } + + return true; +} \ No newline at end of file diff --git a/software_training_assignment/src/resetPos.h b/software_training_assignment/src/resetPos.h new file mode 100644 index 0000000..56f409a --- /dev/null +++ b/software_training_assignment/src/resetPos.h @@ -0,0 +1,9 @@ +#ifndef RESETPOS_H +#define RESETPOS_H + +#include + +bool resetPos(std_srvs::Empty::Request &req, + std_srvs::Empty::Response &res); + +#endif \ No newline at end of file diff --git a/software_training_assignment/src/spawnTurtles.cpp b/software_training_assignment/src/spawnTurtles.cpp new file mode 100644 index 0000000..c216c6c --- /dev/null +++ b/software_training_assignment/src/spawnTurtles.cpp @@ -0,0 +1,31 @@ +#include +#include "spawnTurtles.h" + + +bool spawnTurtles(ros::NodeHandle n, std::string name, int x, int y) +{ + ros::ServiceClient spawnClient = n.serviceClient("spawn"); + + + ros::service::waitForService("spawn"); + + turtlesim::Spawn spawnSrv; + + spawnSrv.request.x = x; + spawnSrv.request.y = y; + spawnSrv.request.theta = 0; + spawnSrv.request.name = name; + + + if (spawnClient.call(spawnSrv)) + { + ROS_INFO_STREAM ("Name: " << spawnSrv.response.name); + } + else + { + ROS_ERROR("Failed to call service spawn"); + return false; + } + + return true; +} \ No newline at end of file diff --git a/software_training_assignment/src/spawnTurtles.h b/software_training_assignment/src/spawnTurtles.h new file mode 100644 index 0000000..903253c --- /dev/null +++ b/software_training_assignment/src/spawnTurtles.h @@ -0,0 +1,8 @@ +#ifndef SPAWNTURTLES_H +#define SPAWNTURTLES_H + +#include + +bool spawnTurtles(ros::NodeHandle n, std::string name, int x, int y); + +#endif \ No newline at end of file diff --git a/software_training_assignment/src/spawnturtle.cpp b/software_training_assignment/src/spawnturtle.cpp new file mode 100644 index 0000000..b5556c0 --- /dev/null +++ b/software_training_assignment/src/spawnturtle.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include "killTurtles.cpp" +#include "publisher.h" +#include "resetPos.cpp" +#include "spawnTurtles.cpp" +#include "goto_action.h" + + +using namespace P; +using namespace A; + + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "spawnturtle"); + + ros::NodeHandle n; + + killTurtles(n); + spawnTurtles(n, "stationary_turtle", 5, 5); + spawnTurtles(n, "moving_turtle", 25, 10); + + ros::ServiceServer resetService = n.advertiseService("reset_pos", resetPos); + + Publisher posPublisher; + posPublisher.pub = n.advertise("position", 1000); + posPublisher.sub = n.subscribe("moving_turtle/pose", 1000, &Publisher::subCallback, &posPublisher); + + GotoAction goTo("goto"); + goTo.node = n; + goTo.pub = n.advertise("moving_turtle/cmd_vel", 1000); + goTo.sub = n.subscribe("moving_turtle/pose", 1000, &GotoAction::subCallback, &goTo); + + ros::Rate loop_rate(10); + + while(ros::ok()) + { + posPublisher.publisher(); + + ros::spinOnce(); + + loop_rate.sleep(); + } + + return 0; +} diff --git a/software_training_assignment/src/testing.cpp b/software_training_assignment/src/testing.cpp new file mode 100644 index 0000000..3150101 --- /dev/null +++ b/software_training_assignment/src/testing.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "test_node"); + + ros::NodeHandle n; + + actionlib::SimpleActionClient ac ("turtlesim1/goto", true); + + ROS_INFO("Waiting for action server to start."); + + ac.waitForServer(); + + ROS_INFO("Action server started, sending goal."); + + + software_training_assignment::GotoGoal goal; + + goal.x = 6; + goal.y = 6; + + ac.sendGoal(goal); + + bool finished_before_timeout = ac.waitForResult(ros::Duration(30.0)); + + if (finished_before_timeout) + { + actionlib::SimpleClientGoalState state = ac.getState(); + ROS_INFO("Action finished: %s",state.toString().c_str()); + } + else + ROS_INFO("Action did not finish before the time out."); + + + ros::ServiceClient client = n.serviceClient("turtlesim1/reset_pos"); + + ros::service::waitForService("turtlesim1/reset_pos"); + + std_srvs::Empty srv; + + if(client.call(srv)) + { + ROS_INFO("resetted"); + } + else + { + ROS_ERROR("Failed to call service reset_pos"); + return 1; + } + + return 0; +} \ No newline at end of file From c029bb874c3b314def8fd0e7ce942e46c94e5042 Mon Sep 17 00:00:00 2001 From: hr-ti Date: Mon, 11 Jan 2021 00:21:01 -0500 Subject: [PATCH 4/8] initial commit --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index b4eedb1..be3559b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -beginner_tutorials/ dbus-1/ \ No newline at end of file From 0ff4154e38c427fa704b6e95b15c43bcd61afd0f Mon Sep 17 00:00:00 2001 From: hr-ti Date: Mon, 11 Jan 2021 01:01:21 -0500 Subject: [PATCH 5/8] cleaning up --- software_training_assignment/src/goto_action.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/software_training_assignment/src/goto_action.h b/software_training_assignment/src/goto_action.h index 678c4cd..ea52bc3 100644 --- a/software_training_assignment/src/goto_action.h +++ b/software_training_assignment/src/goto_action.h @@ -9,7 +9,6 @@ namespace A { public: ros::NodeHandle node; - actionlib::SimpleActionServer as_; GotoAction(std::string name) : as_(node, name, boost::bind(&GotoAction::executeCB, this, _1), false) { as_.start(); @@ -94,6 +93,7 @@ namespace A protected: software_training_assignment::GotoFeedback feedback_; + actionlib::SimpleActionServer as_; software_training_assignment::GotoResult result_; }; } \ No newline at end of file From a37862ca418ea040f616989c22d9d7bb5afe7b15 Mon Sep 17 00:00:00 2001 From: hr-ti Date: Mon, 11 Jan 2021 01:31:19 -0500 Subject: [PATCH 6/8] cleaning up --- software_training_assignment/src/goto_action.h | 8 +++----- software_training_assignment/src/testing.cpp | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/software_training_assignment/src/goto_action.h b/software_training_assignment/src/goto_action.h index ea52bc3..d8768a0 100644 --- a/software_training_assignment/src/goto_action.h +++ b/software_training_assignment/src/goto_action.h @@ -27,7 +27,6 @@ namespace A { x = msg->x; y = msg->y; - // ROS_INFO_STREAM("x: " << x << " y: " << y); } void executeCB(const software_training_assignment::GotoGoal::ConstPtr &goal) @@ -37,11 +36,10 @@ namespace A double relativeX = goal->x - x, relativeY = goal->y - y, relativeDist = sqrt(pow(relativeX, 2) + pow(relativeY, 2)), - theta = acos(relativeX / relativeDist), - angVel = theta; + theta = acos(relativeX / relativeDist); if (relativeY < 0) - angVel *= -1; + theta *= -1; bool success = true; @@ -50,7 +48,7 @@ namespace A feedback_.distance = relativeDist; as_.publishFeedback(feedback_); - rotation.angular.z = angVel; + rotation.angular.z = theta; pub.publish(rotation); diff --git a/software_training_assignment/src/testing.cpp b/software_training_assignment/src/testing.cpp index 3150101..c85c8c1 100644 --- a/software_training_assignment/src/testing.cpp +++ b/software_training_assignment/src/testing.cpp @@ -45,7 +45,7 @@ int main(int argc, char **argv) if(client.call(srv)) { - ROS_INFO("resetted"); + ROS_INFO("Test resetted"); } else { From a2eeb5fc40e9bb591e603a202e222331632279b9 Mon Sep 17 00:00:00 2001 From: hr-ti Date: Mon, 11 Jan 2021 17:24:04 -0500 Subject: [PATCH 7/8] better testing --- software_training_assignment/src/testing.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/software_training_assignment/src/testing.cpp b/software_training_assignment/src/testing.cpp index c85c8c1..bda2165 100644 --- a/software_training_assignment/src/testing.cpp +++ b/software_training_assignment/src/testing.cpp @@ -8,6 +8,12 @@ int main(int argc, char **argv) { ros::init(argc, argv, "test_node"); + if (argc != 3) + { + ROS_INFO("rosrun software_training_assignment testing x y"); + return 0; + } + ros::NodeHandle n; actionlib::SimpleActionClient ac ("turtlesim1/goto", true); @@ -21,8 +27,8 @@ int main(int argc, char **argv) software_training_assignment::GotoGoal goal; - goal.x = 6; - goal.y = 6; + goal.x = atoll(argv[1]); + goal.y = atoll(argv[2]); ac.sendGoal(goal); From 26778671aba4ef2cbe02aebd2bf7b774f45b6db2 Mon Sep 17 00:00:00 2001 From: hr-ti Date: Thu, 14 Jan 2021 21:05:26 -0500 Subject: [PATCH 8/8] remove comments --- software_training_assignment/CMakeLists.txt | 155 ------------------- software_training_assignment/package.xml | 39 +---- software_training_assignment/src/publisher.h | 3 - 3 files changed, 1 insertion(+), 196 deletions(-) diff --git a/software_training_assignment/CMakeLists.txt b/software_training_assignment/CMakeLists.txt index 781fb58..3ec9442 100644 --- a/software_training_assignment/CMakeLists.txt +++ b/software_training_assignment/CMakeLists.txt @@ -1,12 +1,7 @@ cmake_minimum_required(VERSION 3.0.2) project(software_training_assignment) -## Compile as C++11, supported in ROS Kinetic and newer -# add_compile_options(-std=c++11) -## Find catkin macros and libraries -## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) -## is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS roscpp std_msgs @@ -16,50 +11,14 @@ find_package(catkin REQUIRED COMPONENTS actionlib_msgs ) -## System dependencies are found with CMake's conventions find_package(Boost REQUIRED COMPONENTS system) - -## Uncomment this if the package has a setup.py. This macro ensures -## modules and global scripts declared therein get installed -## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html -# catkin_python_setup() - -################################################ -## Declare ROS messages, services and actions ## -################################################ - -## To declare and build messages, services or actions from within this -## package, follow these steps: -## * Let MSG_DEP_SET be the set of packages whose message types you use in -## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). -## * In the file package.xml: -## * add a build_depend tag for "message_generation" -## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET -## * If MSG_DEP_SET isn't empty the following dependency has been pulled in -## but can be declared for certainty nonetheless: -## * add a exec_depend tag for "message_runtime" -## * In this file (CMakeLists.txt): -## * add "message_generation" and every package in MSG_DEP_SET to -## find_package(catkin REQUIRED COMPONENTS ...) -## * add "message_runtime" and every package in MSG_DEP_SET to -## catkin_package(CATKIN_DEPENDS ...) -## * uncomment the add_*_files sections below as needed -## and list every .msg/.srv/.action file to be processed -## * uncomment the generate_messages entry below -## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) - ## Generate messages in the 'msg' folder add_message_files( FILES Position.msg ) -## Generate services in the 'srv' folder - add_service_files( - FILES - ) - ## Generate actions in the 'action' folder add_action_files( FILES @@ -73,138 +32,24 @@ find_package(Boost REQUIRED COMPONENTS system) actionlib_msgs ) -################################################ -## Declare ROS dynamic reconfigure parameters ## -################################################ - -## To declare and build dynamic reconfigure parameters within this -## package, follow these steps: -## * In the file package.xml: -## * add a build_depend and a exec_depend tag for "dynamic_reconfigure" -## * In this file (CMakeLists.txt): -## * add "dynamic_reconfigure" to -## find_package(catkin REQUIRED COMPONENTS ...) -## * uncomment the "generate_dynamic_reconfigure_options" section below -## and list every .cfg file to be processed - -## Generate dynamic reconfigure parameters in the 'cfg' folder -# generate_dynamic_reconfigure_options( -# cfg/DynReconf1.cfg -# cfg/DynReconf2.cfg -# ) - -################################### -## catkin specific configuration ## -################################### -## The catkin_package macro generates cmake config files for your package -## Declare things to be passed to dependent projects -## INCLUDE_DIRS: uncomment this if your package contains header files -## LIBRARIES: libraries you create in this project that dependent projects also need -## CATKIN_DEPENDS: catkin_packages dependent projects also need -## DEPENDS: system dependencies of this project that dependent projects also need catkin_package( CATKIN_DEPENDS message_runtime actionlib_msgs -# INCLUDE_DIRS include -# LIBRARIES software_training_assignment -# CATKIN_DEPENDS roscpp std_msgs -# DEPENDS system_lib ) -########### -## Build ## -########### - -## Specify additional locations of header files -## Your package locations should be listed before other locations include_directories( # include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ) -## Declare a C++ library -# add_library(${PROJECT_NAME} -# src/${PROJECT_NAME}/software_training_assignment.cpp -# ) - -## Add cmake target dependencies of the library -## as an example, code may need to be generated before libraries -## either from message generation or dynamic reconfigure -# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) - -## Declare a C++ executable -## With catkin_make all packages are built within a single CMake context -## The recommended prefix ensures that target names across packages don't collide -# add_executable(${PROJECT_NAME}_node src/software_training_assignment_node.cpp) - -## Rename C++ executable without prefix -## The above recommended prefix causes long target names, the following renames the -## target back to the shorter version for ease of user use -## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" -# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") - -## Add cmake target dependencies of the executable -## same as for the library above -# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) - -## Specify libraries to link a library or executable target against -# target_link_libraries(${PROJECT_NAME}_node -# ${catkin_LIBRARIES} -# ) - -############# -## Install ## -############# - -# all install targets should use catkin DESTINATION variables -# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html - -## Mark executable scripts (Python etc.) for installation -## in contrast to setup.py, you can choose the destination -# catkin_install_python(PROGRAMS -# scripts/my_python_script -# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -# ) - -## Mark executables for installation -## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html -# install(TARGETS ${PROJECT_NAME}_node -# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -# ) - -## Mark libraries for installation -## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html -# install(TARGETS ${PROJECT_NAME} -# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} -# ) - -## Mark cpp header files for installation install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE ) -## Mark other files for installation (e.g. launch and bag files, etc.) -# install(FILES -# # myfile1 -# # myfile2 -# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} -# ) - -############# -## Testing ## -############# -## Add gtest based cpp test target and link libraries -# if(TARGET ${PROJECT_NAME}-test) -# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) -# endif() -## Add folders to be run by python nosetests -# catkin_add_nosetests(test) add_executable(spawnturtle src/spawnturtle.cpp) target_link_libraries(spawnturtle ${catkin_LIBRARIES}) diff --git a/software_training_assignment/package.xml b/software_training_assignment/package.xml index 33dc040..284d5f2 100644 --- a/software_training_assignment/package.xml +++ b/software_training_assignment/package.xml @@ -4,50 +4,15 @@ 0.0.0 The software_training_assignment package - - - htieu - - - - MIT - - - - - - - - - - - - - - - - - - - - - message_generation - - - - - + message_runtime - gtest - - catkin roscpp std_msgs @@ -61,9 +26,7 @@ actionlib actionlib_msgs actionlib_msgs - - diff --git a/software_training_assignment/src/publisher.h b/software_training_assignment/src/publisher.h index 3d3adcf..3235fee 100644 --- a/software_training_assignment/src/publisher.h +++ b/software_training_assignment/src/publisher.h @@ -14,8 +14,6 @@ namespace P msg.x = x - 5; msg.y = y - 5; msg.distance = sqrt(pow(msg.x, 2) + pow(msg.y, 2)); - - // ROS_INFO_STREAM("x:" << msg.x << " y: " << msg.y); pub.publish(msg); } @@ -23,7 +21,6 @@ namespace P { x = msg->x; y = msg->y; - // ROS_INFO_STREAM("moving turtle x: " << x << " y: " << y); } double x = 0, y = 0; ros::Publisher pub;