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.
added examples of class based ros node exampels in python
- Loading branch information
Showing
10 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/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,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} | ||
) |
14 changes: 14 additions & 0 deletions
14
fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/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,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> |
30 changes: 30 additions & 0 deletions
30
...torials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example1_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,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() |
12 changes: 12 additions & 0 deletions
12
...torials/demo_ros_nodes/ros_python_class_based_nodes/ros/scripts/class_based_example2_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,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() |
Empty file.
22 changes: 22 additions & 0 deletions
22
...class_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.py
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,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 added
BIN
+1.5 KB
...lass_based_nodes/ros/src/ros_python_class_based_nodes_ros/class_based_python_example2.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
...nodes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/demo_class.py
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,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 added
BIN
+1.42 KB
...odes/ros_python_class_based_nodes/ros/src/ros_python_class_based_nodes_ros/demo_class.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
fc_ros_tutorials/demo_ros_nodes/ros_python_class_based_nodes/setup.py
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,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) |