黄生:18120764596/微信 厦门圣企机电设备有限公司 固话:0592-6081295 QQ:2708880336
淘宝店铺:http://shop578899473.taobao.com/index.htm
import rospy
from std_msgs.msg import Float32
currentPosition = 0.5
IC697BEM711完整IC697BEM711完整IC697BEM711完整
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」,这样一来即可检视顺畅的动作。
$ ./servoencoder.py
A06B-0373-B577
A06B-6066-H266
A06B-0113-B077
A06B-0373-B675
A06B-6069-H104
A06B-0113-B078
A06B-0374-B576 A06B-6070-H004
A06B-0113-B079
A06B-0374-B577
A06B-6070-H500
A06B-0113-B175
A06B-0376-B675
A06B-6070-H600
A06B-0113-B178
A06B-0377-B175
A06B-6073-K001
A06B-0115-B275 A06B-0377-B575
A06B-6073-K250
A06B-0116-B075
A06B-0390-B060
A06B-6076-H001
A06B-0116-B203
A06B-0501-B001
A06B-6077-H106
A06B-0116-B204
A06B-0501-B002
A06B-0116-B503
A06B-0501-B003
A06B-0116-B804
A06B-0501-B004 A06B-6077-H111
A06B-0120-K324
A06B-0501-B005
A06B-6077-K142
A06B-0121-B577
A06B-0501-B006 A06B-6077-K143
A06B-0121-B580
A06B-0501-B032
A06B-6077-K144
A06B-0501-B201
A06B-6077-K250
A06B-0123-B075
A06B-0501-B202
A06B-6078-H206
A06B-0123-B077
A06B-0501-B205
A06B-6078-H211
A06B-0123-B575
A06B-0501-B206
A06B-0123-B675 A06B-0501-B751
A06B-6078-H230