test_sensor_scope.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2011 Shadow Robot Company Ltd.
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License as published by the Free
00007 # Software Foundation, either version 2 of the License, or (at your option)
00008 # any later version.
00009 #
00010 # This program is distributed in the hope that it will be useful, but WITHOUT
00011 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013 # more details.
00014 #
00015 # You should have received a copy of the GNU General Public License along
00016 # with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 #
00018 # -*- coding: utf-8 -*-
00019 """
00020 This is an example showing how to publish command messages to the hand.
00021 """
00022 
00023 
00024 import roslib; roslib.load_manifest('sr_hand')
00025 import rospy
00026 
00027 from std_msgs.msg import Int16
00028 import time
00029 import math
00030 
00031 def talker():
00032     """
00033     The Publisher publishes to the different topics on which the sr_subscriber subscribes. It sends commands to
00034     the hand.
00035 
00036     Please set the message you want to test.
00037     """
00038     pub2 = rospy.Publisher('/test_2', Int16)
00039     pub1 = rospy.Publisher('/test_1', Int16)
00040     rospy.init_node('shadowhand_command_publisher_python')
00041     angle1 = 0
00042     angle2 = 0
00043     msg1 = Int16()
00044     msg2 = Int16()
00045 
00046     step_nb = 0
00047 
00048     while not rospy.is_shutdown():
00049         target1 = math.cos( math.radians(angle1) )
00050         angle1 += .01
00051         if angle1 > 90:
00052             angle1 = -90
00053         msg1.data = target1 * 20000
00054         pub1.publish( msg1 )
00055 
00056         if step_nb ==  5:
00057             target2 = math.sin( math.radians(angle2) )
00058             angle2 += 1
00059             if angle2 > 180:
00060                 angle2 = 0
00061 
00062             msg2.data = target2*30000
00063             pub2.publish( msg2 )
00064             step_nb = 0
00065 
00066         step_nb += 1
00067         time.sleep(.005)
00068 
00069 
00070 
00071 if __name__ == '__main__':
00072     try:
00073         talker()
00074     except rospy.ROSInterruptException: pass


sr_hand
Author(s): Ugo Cupcic / ugo@shadowrobot.com, contact@shadowrobot.com
autogenerated on Fri Jan 3 2014 12:03:25