Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 6 additions & 42 deletions software_training/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
cmake_minimum_required(VERSION 3.0.2)
project(software_training)

## 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
rospy
Expand All @@ -16,57 +11,26 @@ find_package(catkin REQUIRED COMPONENTS
actionlib
)

## 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
# Message1.msg
# Message2.msg
# )

## Generate services in the 'srv' folder
add_service_files(
FILES
service.srv
)

## Generate actions in the 'action' folder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be adding the action file for building

# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
add_action_files(
FILES
action.action
)

## Generate added messages and services with any dependencies listed here
generate_messages(
Expand Down Expand Up @@ -224,5 +188,5 @@ target_link_libraries(listener ${catkin_LIBRARIES})

add_executable(service src/service.cpp)
target_link_libraries(service ${catkin_LIBRARIES})
add_dependencies(service software_training_generate_cpp)
add_dependencies(service software_training_generate_messages_cpp)

13 changes: 7 additions & 6 deletions software_training/src/action.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <ros/ros.h>
#include <actionlib/client/simple_action_client.h>
#include <actionlib/>
#include "std_msgs/String.h"
#include "geometry_msgs/Twist.h"
#include <actionlib>
#include <std_msgs/String.h>
#include <geometry_msgs/Twist.h>
#include <sstream>
#include <cmath>
#include "software_training/Distance.h"
Expand All @@ -17,15 +17,16 @@ int main (int argc, char **argv)
= nh.advertise<geometry_msgs::Twist>("/moving_turtle/cmd_vel", 1000);
// create the action client
// true causes the client to spin its own thread

actionlib::SimpleActionClient<goemetry_msgs::Twist>("action", true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry forgot to mention this, action Client and Server should never be in the same node, it defeats the purpose of having an action server.

//actionlib::SimpleActionClient<goemetry_msgs::Twist>("action", true);
actionlib::SimpleActionClient<software_training_assignment::Action> actionClient("action", true);

Server server(n, "action", boost::bind(&execute, _1, &server), false);
server.start();

ROS_INFO("Waiting for action server to start.");
// wait for the action server to start
ac.waitForServer(); //will wait for infinite time
actionClient.waitForServer(); //will wait for infinite time

ROS_INFO("Action server started, sending goal.");
// send a goal to the action
Expand Down
9 changes: 8 additions & 1 deletion software_training/src/addTurtle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ int main(int argc, char **argv){

ros::service::waitForService("spawn", ros::Duration(5));
bool success = spawnClient.call(req,resp);
success = spawnClient.call(req2,resp2);
bool success2 = spawnClient.call(req2,resp2);


if(success){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good but if the first turtle does not spawn but the second one does this will be true.
better to evaluate individually and use the response msg

ROS_INFO_STREAM("Spawned a turtle named "
<< resp.name);
}else{
ROS_ERROR_STREAM("Failed to spawn.");
}

if(success2){
ROS_INFO_STREAM("Spawned a turtle named "
<< resp2.name);
}else{
ROS_ERROR_STREAM("Failed to spawn.");
}
}