From 8413bf73bd6bb8abe9176fdaed5e73e6789ab2b9 Mon Sep 17 00:00:00 2001 From: shehzad ahmed Date: Mon, 8 Sep 2014 22:47:08 +0200 Subject: [PATCH] added examples of class based ros node exampels in python --- .../CMakeLists.txt | 23 ++++++++++++++ .../ros_python_class_based_nodes/package.xml | 14 ++++++++ .../ros/scripts/class_based_example1_node | 30 ++++++++++++++++++ .../ros/scripts/class_based_example2_node | 12 +++++++ .../__init__.py | 0 .../class_based_python_example2.py | 22 +++++++++++++ .../class_based_python_example2.pyc | Bin 0 -> 1533 bytes .../demo_class.py | 11 +++++++ .../demo_class.pyc | Bin 0 -> 1453 bytes .../ros_python_class_based_nodes/setup.py | 11 +++++++ 10 files changed, 123 insertions(+) create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/CMakeLists.txt create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/package.xml create mode 100755 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example1_node create mode 100755 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example2_node create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/__init__.py create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.py create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.pyc create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/demo_class.py create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/demo_class.pyc create mode 100644 fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/setup.py diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/CMakeLists.txt b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/CMakeLists.txt new file mode 100644 index 0000000..f77f69c --- /dev/null +++ b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 2.8.3) +project(ros_python_class_based_nodes) + +find_package(catkin REQUIRED COMPONENTS + rospy +) + +catkin_python_setup() + +catkin_package( + CATKIN_DEPENDS + rospy +) + +install(PROGRAMS + ros/scripts/class_based_example1_node + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) + +install(PROGRAMS + ros/scripts/class_based_example2_node + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) \ No newline at end of file diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/package.xml b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/package.xml new file mode 100644 index 0000000..7e450e0 --- /dev/null +++ b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/package.xml @@ -0,0 +1,14 @@ + + + ros_python_class_based_nodes + 0.1.0 + The ros_python_class_based_nodes package + + Shehzad Ahmed + + GPLv3 + + catkin + rospy + rospy + \ No newline at end of file diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example1_node b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example1_node new file mode 100755 index 0000000..049e5e7 --- /dev/null +++ b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example1_node @@ -0,0 +1,30 @@ +#!/usr/bin/env python +""" +This script initilizes simple class based python node. +""" +#-*- encoding: utf-8 -*- +__author__ = 'shehzad ahmed' +import rospy + +class DemoClass(): + def __init__(self): + self.initilize_parameters(0, 0.0) + + def initilize_parameters(self, number_count, total_sum): + rospy.loginfo("Initlizing class variables.") + self.number_count = number_count; + self.total_sum = total_sum; + +def initlize_node(): + ''' + Initilize node and spin which simply keeps python + from exiting until this node is stopped + ''' + rospy.init_node('class_based_example1_node', anonymous=False) + rospy.loginfo("class_based_example1_node is now running") + demo_class = DemoClass() + demo_class.initilize_parameters(10, 10.0) + rospy.spin() + +if __name__ == '__main__': + initlize_node() \ No newline at end of file diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example2_node b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example2_node new file mode 100755 index 0000000..e63f72c --- /dev/null +++ b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example2_node @@ -0,0 +1,12 @@ +#!/usr/bin/env python +""" +This script is a simple python node which imports +source code of ros_python_example1. +""" +#-*- encoding: utf-8 -*- +__author__ = 'shehzad ahmed' + +import ros_python_class_based_nodes_ros.class_based_python_example2 + +if __name__ == '__main__': + ros_python_class_based_nodes_ros.class_based_python_example2.main() \ No newline at end of file diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/__init__.py b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.py b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.py new file mode 100644 index 0000000..9d56363 --- /dev/null +++ b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +""" +This script initilizes simple class based python node. +""" +#-*- encoding: utf-8 -*- +__author__ = 'shehzad ahmed' +import rospy +from demo_class import * + +def initlize_node(): + ''' + Initilize node and spin which simply keeps python + from exiting until this node is stopped + ''' + rospy.init_node('class_based_example2_node', anonymous=False) + rospy.loginfo("class_based_example2_node is now running") + demo_class1 = DemoClass() + demo_class1.initilize_parameters(10, 10.0) + rospy.spin() + +def main(): + initlize_node() \ No newline at end of file diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.pyc b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..87be250760133cbab47c967d6c969877b0cdec37 GIT binary patch literal 1533 zcmd^9&2H2%5FTfLpxds51RS{ez+uIqp%n)XsH#*1;?hIusTV86-o}vFQS7MQ3Qo&| z@gTef4*=hIvlI!z3)EVV?U}J>=9_Ob`Z1r$Z}an#hLK@C#tbhZG|>g5pbJ4dBR!%z zqYG^C8&f@^b3LK2a2k`Irp<(%-Y@QLUznX&HpozRwvEy{8*OcG3^cZBYa`3L2tj@* zg3+>F#mYPByf*u@Fy|L4Q{5C=7FA=k{fTk95YR^!&r-^~8)KeehPM!r=p&L%`NoXa zLI_rkIIp!J5y!M9`a<*>T4amNC$!FBzvh$5J*QnZE%HE-P85s|*Q8F&kx2@61H$FkIgojFaD05vfMu&>M z;|{Ea^KRAnK7_^peEDVPuVmLdhro6Q=SxhCr^lzMH*tbP=L0b3hq*DEFsy%5)WJk< zVeK!iTl(bl+BE)z+Z7)TH&QEATXaQZqUi#lMH2warb)XvX8S%5T3O|;G$ed1x=(hu3|ux2q8j4bA^wFYgRsc@4U$NMxHe&(RG)H;VpQ8 zJWd_}z8OcMK)k@MytCt-|8Hi~`}xVwU-K^&J**Vx2W&nEsqq6U0u z^mS!Kw#=SD&;Q0+#2MI6t_zoK$^7Wi;PxXnzW{OY1w#@qD|j@@q*N@k1ma4RWlI{D z*!&!1NAyiIK@R(b49u6AXe>MkZH36n#4?J7?|t;Gzj5}e9Lml`H}E7qf|Omm$#9Yq zz5|yxp>sJmuDL1edq}>iv7ETwm~M@&}evrHlXo literal 0 HcmV?d00001 diff --git a/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/setup.py b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/setup.py new file mode 100644 index 0000000..b4a4d64 --- /dev/null +++ b/fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/setup.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +from distutils.core import setup +from catkin_pkg.python_setup import generate_distutils_setup + +d = generate_distutils_setup( + packages=['ros_python_class_based_nodes_ros'], + package_dir={'ros_python_class_based_nodes_ros': 'ros/src'} +) + +setup(**d) \ No newline at end of file