Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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