Skip to content

Commit

Permalink
added examples of class based ros node exampels in python
Browse files Browse the repository at this point in the history
  • Loading branch information
shehzi001 committed Sep 8, 2014
1 parent 28bbecf commit 8413bf7
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<package>
<name>ros_python_class_based_nodes</name>
<version>0.1.0</version>
<description>The ros_python_class_based_nodes package</description>

<maintainer email="[email protected]">Shehzad Ahmed</maintainer>

<license>GPLv3</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<run_depend>rospy</run_depend>
</package>
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
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;
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8413bf7

Please sign in to comment.