Skip to content

Commit

Permalink
added examples of using std ros message in python
Browse files Browse the repository at this point in the history
  • Loading branch information
shehzi001 committed Sep 8, 2014
1 parent a42f273 commit 6d8ab29
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8.3)
project(ros_python_std_messages_examples)

find_package(catkin REQUIRED COMPONENTS
rospy
std_msgs
)

catkin_python_setup()

catkin_package(
CATKIN_DEPENDS
rospy
std_msgs

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<package>
<name>ros_python_std_messages_examples</name>
<version>0.1.0</version>
<description>The ros_python_std_messages_examples package</description>

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

<license>GPLv3</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
</package>
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 std_messages_examples.
"""
#-*- encoding: utf-8 -*-
__author__ = 'shehzad ahmed'

import ros_python_std_messages_examples_ros.std_messages_examples

if __name__ == '__main__':
ros_python_std_messages_examples_ros.std_messages_examples.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
'''
This script demostrates the way of filling
ros std_msgs by giving few examples.
'''
import rospy
from std_msgs.msg import Bool
from std_msgs.msg import Float32
from std_msgs.msg import Int32
from std_msgs.msg import String


class DemoClass():
def __init__(self):
self.prepare_std_msg()

def prepare_std_msg(self):
rospy.loginfo("Preparing std_msgs......")
'''
Fill Bool message
'''
bool_msg = Bool()

bool_msg.data = False

'''
Fill Float32 message
'''
float32_msg = Float32()

float32_msg.data = 1.0

'''
Fill Int32 message
Please, do it your self for practice
'''

'''
Fill String message
Please, do it your self for practice
'''
rospy.loginfo("std_msgs preparation done......")
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""
This script demostrates the way of filling
ros std_msgs by giving few examples.
"""
#-*- 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('std_messages_examples_node', anonymous=False)
rospy.loginfo("std_messages_examples_node is now running")
demo_class1 = DemoClass()
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

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

d = generate_distutils_setup(
packages=['ros_python_std_messages_examples_ros'],
package_dir={'ros_python_std_messages_examples_ros': 'ros/src'}
)

setup(**d)

0 comments on commit 6d8ab29

Please sign in to comment.