0
我製作了一個程序來控制robonau2(R2)。ROS robonaut2控制
我從外部發布者處獲取數據。
我可以一次控制R2。
'print(data.x)'是檢查接收數據的代碼。
數據成功接收,但R2不動... TT
如何控制R2幾次?
#!/usr/bin/env python
import sys, rospy, tf, moveit_commander, random
from geometry_msgs.msg import Pose, Point, Quaternion
from project_pkg.msg import arminfo
def left_callback(data):
orient = \
Quaternion(*tf.transformations.quaternion_from_euler(data.phi, data.theta, data.psi)) # <1>
pose = Pose(Point(data.x, data.y, data.z), orient)
moveit_commander.MoveGroupCommander("left_arm").set_pose_target(pose)
moveit_commander.MoveGroupCommander("left_arm").go(True)
print(data.x)
def right_callback(data):
orient = \
Quaternion(*tf.transformations.quaternion_from_euler(data.phi, data.theta, data.psi)) # <1>
pose = Pose(Point(data.x, data.y, data.z), orient)
moveit_commander.MoveGroupCommander("right_arm").set_pose_target(pose)
moveit_commander.MoveGroupCommander("right_arm").go(True)
print(data.x)
if __name__ == '__main__':
moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node('r2_cli',anonymous=True)
argv = rospy.myargv(argv=sys.argv) # filter out any arguments used by ROS
rospy.Subscriber("mat_left",arminfo,left_callback)
rospy.Subscriber("mat_right",arminfo,right_callback)
rospy.spin()
moveit_commander.roscpp_shutdown()
,它是控制R2幾次示例代碼..
有什麼不同?
#!/usr/bin/env python
import sys, rospy, tf, moveit_commander, random
from geometry_msgs.msg import Pose, Point, Quaternion
from math import pi
orient = [Quaternion(*tf.transformations.quaternion_from_euler(pi, -pi/2, -pi/2)),Quaternion(*tf.transformations.quaternion_from_euler(pi, -pi/2, -pi/2))]
pose = [Pose(Point(0.5,-0.5,1.3),orient[0]), Pose(Point(-0.5,-0.5,1.3),orient[1])]
moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node('r2_wave_arm',anonymous=True)
group = [moveit_commander.MoveGroupCommander("left_arm"), moveit_commander.MoveGroupCommander("right_arm")]
# now, wave arms around randomly
while not rospy.is_shutdown():
pose[0].position.x = 0.5 + random.uniform(-0.1, 0.1)
pose[1].position.x = -0.5 + random.uniform(-0.1, 0.1)
for side in [0,1]:
pose[side].position.z = 1.5 + random.uniform(-0.1, 0.1)
group[side].set_pose_target(pose[side])
group[side].go(True)
moveit_commander.roscpp_shutdown()
不同之處在於你沒有在循環中執行代碼(例如在'while'內部),因此代碼只執行一次。 –