#!/usr/bin/env python from time import sleep import numpy as np import rospy from std_msgs.msg import Float32 currentPosition = 0.5 pub = None def moveServo_cb(data): global currentPosition, pub targetPosition = data.data r = targetPosition - currentPosition angles = np.array( (range(190)) [0::10]) -90 m = ( np.sin( angles * np.pi/ 180. ) + 1 )/2 for mi in np.nditer(m): pos = currentPosition + mi*r print “pos: “, pos pub.publish(pos) sleep(0.05) currentPosition = targetPosition print “pos-e: “, currentPosition pub.publish(currentPosition) def listener(): global pub rospy.init_node(‘servoencoder’,anonymous=True) rospy.Subscriber(‘/head/tilt/smooth’,Float32, moveServo_cb) pub = rospy.Publisher(‘/head/tilt’,Float32, queue_size=10) rospy.spin() if __name__ == ‘__main__’: listener() 想要测试伺服机顺畅的动作,就要启动Python脚本,将讯息发布到「/head/tilt/smooth」,这样一来即可检视顺畅的动作。 A06B-0127-B177 A06B-0502-B172 A06B-6079-H104 A06B-0127-B575 A06B-0502-B202 A06B-6079-H106 A06B-0127-B577 A06B-0502-B205 A06B-6079-H201 A06B-0127-B588 A06B-0502-B272 A06B-6079-H203 A06B-0127-B677 A06B-0502-B374 A06B-6079-H206 A06B-0128-B075 A06B-0502-B751 A06B-6079-H208 A06B-0128-B076 A06B-0502-B855 A06B-6079-H301 A06B-0128-B077 A06B-0503-B006 A06B-6079-H304 A06B-0128-B175 A06B-0503-B202 A06B-6079-H401 A06B-0128-B177 A06B-0503-B251 A06B-6079-K815 A06B-0128-B575 A06B-0503-B304 A06B-6081-H101 A06B-0128-B577 A06B-0505-B001 A06B-6081-H103 A06B-0128-B675 A06B-0505-B202 A06B-6081-H106 2017-1 A06B-0128-B677 A06B-0505-B205 A06B-6082-H211 A06B-0128-B688 A06B-0506-B004 A06B-6082-H215 A06B-0141-B075 A06B-0506-B521 140DRC83000配件140DRC83000配件140DRC83000配件 A06B-0141-B077 A06B-0512-B001 A06B-6085-H102 A06B-0141-B175 A06B-0512-B002 A06B-0142-B075 A06B-0512-B003 A06B-6087-H115 A06B-0142-B076 A06B-0512-B004 A06B-6087-H126 A06B-0142-B077 A06B-0512-B005 A06B-6087-H130 A06B-0142-B084 A06B-0512-B006 A06B-6087-H137 A06B-0142-B575 A06B-6087-H145 A06B-0143-B075 A06B-0513-B001 A06B-6087-H155