forked from shehzi001/ros_foundation_course
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
488 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
fc_ros_tutorials/demo_ros_server_client/ros_simple_client_cpp/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(ros_simple_client_cpp) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
ros_services_examples | ||
roscpp | ||
) | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS | ||
ros_services_examples | ||
roscpp | ||
) | ||
|
||
include_directories( | ||
${catkin_INCLUDE_DIRS} | ||
) | ||
|
||
|
||
add_executable(simple_client_cpp_example_node | ||
ros/src/simple_client_cpp_example_node.cpp) | ||
|
||
target_link_libraries(simple_client_cpp_example_node | ||
${catkin_LIBRARIES} | ||
) | ||
|
||
add_executable(client_cpp_class_based_example_node | ||
ros/src/client_cpp_class_based_example_node.cpp) | ||
|
||
target_link_libraries(client_cpp_class_based_example_node | ||
${catkin_LIBRARIES} | ||
) |
16 changes: 16 additions & 0 deletions
16
fc_ros_tutorials/demo_ros_server_client/ros_simple_client_cpp/package.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<name>ros_simple_client_cpp</name> | ||
<version>0.0.0</version> | ||
<description>The ros_simple_client_cpp package</description> | ||
|
||
<maintainer email="[email protected]">Shehzad Ahmed</maintainer> | ||
|
||
<license>GPLv3</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>ros_services_examples</build_depend> | ||
<build_depend>roscpp</build_depend> | ||
<run_depend>ros_services_examples</run_depend> | ||
<run_depend>roscpp</run_depend> | ||
</package> |
77 changes: 77 additions & 0 deletions
77
...o_ros_server_client/ros_simple_client_cpp/ros/src/client_cpp_class_based_example_node.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* simple_client_cpp_example_node.cpp | ||
* | ||
* Created on: September 10, 2014 | ||
* Author: Shehzad Ahmed | ||
**/ | ||
|
||
#include <ros/ros.h> | ||
#include <ros_services_examples/NodeInfoQuery.h> | ||
#include <ros_services_examples/NodeInfoQueryRequest.h> | ||
#include <ros_services_examples/NodeInfoQueryResponse.h> | ||
|
||
class DemoClass | ||
{ | ||
public: | ||
DemoClass(const ros::NodeHandle &nh): | ||
nh_(nh) | ||
{ | ||
client_ = nh_.serviceClient<ros_services_examples::NodeInfoQuery>("node_info_query"); | ||
} | ||
|
||
~DemoClass() | ||
{ | ||
} | ||
|
||
void call_service() | ||
{ | ||
if(client_.exists()) { | ||
ROS_INFO("server is running....."); | ||
ros_services_examples::NodeInfoQuery node_info_query; | ||
ros_services_examples::NodeInfoQueryRequest request; | ||
request.node_name.data = "simple_client_cpp_example_node"; | ||
|
||
node_info_query.request = request; | ||
|
||
if(client_.call(node_info_query)) { | ||
ROS_INFO_STREAM("Response recieved :" << node_info_query.response.node_id.data); | ||
} else { | ||
ROS_INFO("Response failed....."); | ||
} | ||
} else { | ||
ROS_INFO("server is not running....."); | ||
} | ||
} | ||
|
||
private: | ||
ros::ServiceClient client_; | ||
ros::NodeHandle nh_; | ||
}; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
/** | ||
* Initilization of node | ||
**/ | ||
ros::init(argc, argv, "simple_client_cpp_example_node"); | ||
|
||
/** | ||
* Initilization of node handle | ||
**/ | ||
ros::NodeHandle nh; | ||
|
||
/** | ||
* Printing Information message on the console. | ||
**/ | ||
ROS_INFO("simple_client_cpp_example_node is now running"); | ||
|
||
DemoClass demo_class(nh); | ||
|
||
demo_class.call_service(); | ||
|
||
/** | ||
* Running a thread to keep spinning untill the user kills the node. | ||
**/ | ||
|
||
return 0; | ||
} |
52 changes: 52 additions & 0 deletions
52
...s/demo_ros_server_client/ros_simple_client_cpp/ros/src/simple_client_cpp_example_node.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* simple_client_cpp_example_node.cpp | ||
* | ||
* Created on: September 10, 2014 | ||
* Author: Shehzad Ahmed | ||
**/ | ||
|
||
#include <ros/ros.h> | ||
#include <ros_services_examples/NodeInfoQuery.h> | ||
#include <ros_services_examples/NodeInfoQueryRequest.h> | ||
#include <ros_services_examples/NodeInfoQueryResponse.h> | ||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
/** | ||
* Initilization of node | ||
**/ | ||
ros::init(argc, argv, "simple_client_cpp_example_node"); | ||
|
||
/** | ||
* Initilization of node handle | ||
**/ | ||
ros::NodeHandle nh; | ||
|
||
/** | ||
* Printing Information message on the console. | ||
**/ | ||
ROS_INFO("simple_client_cpp_example_node is now running"); | ||
|
||
ros::ServiceClient client = nh.serviceClient<ros_services_examples::NodeInfoQuery>("node_info_query"); | ||
|
||
if(client.exists()) { | ||
ROS_INFO("server is running....."); | ||
ros_services_examples::NodeInfoQuery node_info_query; | ||
ros_services_examples::NodeInfoQueryRequest request; | ||
request.node_name.data = "simple_client_cpp_example_node"; | ||
|
||
node_info_query.request = request; | ||
|
||
if(client.call(node_info_query)) { | ||
ROS_INFO_STREAM("Response recieved :" << node_info_query.response.node_id.data); | ||
} else { | ||
ROS_INFO("Response failed....."); | ||
} | ||
|
||
} else { | ||
ROS_INFO("server is not running....."); | ||
} | ||
|
||
return 0; | ||
} |
13 changes: 13 additions & 0 deletions
13
fc_ros_tutorials/demo_ros_server_client/ros_simple_client_python/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(ros_simple_client_python) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
ros_services_examples | ||
rospy | ||
) | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS | ||
ros_services_examples | ||
rospy | ||
) |
16 changes: 16 additions & 0 deletions
16
fc_ros_tutorials/demo_ros_server_client/ros_simple_client_python/package.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<name>ros_simple_client_python</name> | ||
<version>0.1.0</version> | ||
<description>The ros_simple_client_python package</description> | ||
|
||
<maintainer email="[email protected]">Shehzad Ahmed</maintainer> | ||
|
||
<license>GPLv3</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>ros_services_examples</build_depend> | ||
<build_depend>rospy</build_depend> | ||
<run_depend>ros_services_examples</run_depend> | ||
<run_depend>rospy</run_depend> | ||
</package> |
32 changes: 32 additions & 0 deletions
32
..._ros_server_client/ros_simple_client_python/ros/scripts/simple_client_python_example_node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python | ||
""" | ||
This script demonstrates the way of requesting service. | ||
""" | ||
#-*- encoding: utf-8 -*- | ||
__author__ = 'shehzad ahmed' | ||
import rospy | ||
from ros_services_examples.srv import * | ||
|
||
def initlize_node(): | ||
''' | ||
Initilize node and spin which simply keeps python | ||
from exiting until this node is stopped | ||
''' | ||
rospy.init_node('simple_client_python_example_node', anonymous=False) | ||
rospy.loginfo("simple_client_python_example_node is now running") | ||
|
||
rospy.wait_for_service('node_info_query') | ||
|
||
try: | ||
node_info_service = rospy.ServiceProxy('node_info_query', NodeInfoQuery) | ||
req = NodeInfoQueryRequest() | ||
req.node_name.data = "simple_client_python_example_node" | ||
resp = node_info_service(req) | ||
rospy.loginfo("Response recieved : %d",resp.node_id.data) | ||
except rospy.ServiceException, e: | ||
print "Service call failed: %s"%e | ||
|
||
rospy.spin() | ||
|
||
if __name__ == '__main__': | ||
initlize_node() |
32 changes: 32 additions & 0 deletions
32
fc_ros_tutorials/demo_ros_server_client/ros_simple_server_cpp/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(ros_simple_server_cpp) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
ros_services_examples | ||
roscpp | ||
) | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS | ||
ros_services_examples | ||
roscpp | ||
) | ||
|
||
include_directories( | ||
${catkin_INCLUDE_DIRS} | ||
) | ||
|
||
|
||
add_executable(simple_server_cpp_example_node | ||
ros/src/simple_server_cpp_example_node.cpp) | ||
|
||
target_link_libraries(simple_server_cpp_example_node | ||
${catkin_LIBRARIES} | ||
) | ||
|
||
add_executable(server_cpp_class_based_example_node | ||
ros/src/server_cpp_class_based_example_node.cpp) | ||
|
||
target_link_libraries(server_cpp_class_based_example_node | ||
${catkin_LIBRARIES} | ||
) |
16 changes: 16 additions & 0 deletions
16
fc_ros_tutorials/demo_ros_server_client/ros_simple_server_cpp/package.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<name>ros_simple_server_cpp</name> | ||
<version>0.0.0</version> | ||
<description>The ros_simple_server_cpp package</description> | ||
|
||
<maintainer email="[email protected]">Shehzad Ahmed</maintainer> | ||
|
||
<license>GPLv3</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>ros_services_examples</build_depend> | ||
<build_depend>roscpp</build_depend> | ||
<run_depend>ros_services_examples</run_depend> | ||
<run_depend>roscpp</run_depend> | ||
</package> |
63 changes: 63 additions & 0 deletions
63
...o_ros_server_client/ros_simple_server_cpp/ros/src/server_cpp_class_based_example_node.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* server_cpp_class_based_example_node.cpp | ||
* | ||
* Created on: September 10, 2014 | ||
* Author: Shehzad Ahmed | ||
*/ | ||
#include <ros/ros.h> | ||
#include <ros_services_examples/NodeInfoQuery.h> | ||
#include <ros_services_examples/NodeInfoQueryRequest.h> | ||
#include <ros_services_examples/NodeInfoQueryResponse.h> | ||
|
||
class DemoClass | ||
{ | ||
public: | ||
DemoClass(ros::NodeHandle nh): | ||
nh_(nh) | ||
{ | ||
service = nh.advertiseService("node_info_query", &DemoClass::serviceCB, this); | ||
} | ||
|
||
~DemoClass() | ||
{ | ||
} | ||
|
||
bool serviceCB(ros_services_examples::NodeInfoQueryRequest &req, | ||
ros_services_examples::NodeInfoQueryResponse &resp) | ||
{ | ||
ROS_INFO_STREAM("Request recieved :" << req.node_name.data); | ||
resp.node_id.data = 1.0; | ||
return true; | ||
} | ||
|
||
private: | ||
ros::ServiceServer service; | ||
ros::NodeHandle nh_; | ||
|
||
}; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
/** | ||
* Initilization of node | ||
**/ | ||
ros::init(argc, argv, "server_cpp_class_based_example_node"); | ||
|
||
/** | ||
* Initilization of node handle | ||
**/ | ||
ros::NodeHandle nh; | ||
|
||
/** | ||
* Printing Information message on the console. | ||
**/ | ||
ROS_INFO("server_cpp_class_based_example_node is now running"); | ||
|
||
DemoClass demo_class(nh); | ||
/** | ||
* Running a thread to keep spinning untill the user kills the node. | ||
**/ | ||
ros::spin(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.