我试图运行这段代码,它有三个函数,前两个函数有一个参数,这对于从订阅者那里获取信息很重要。在第三个函数中,我实际上调用了前两个函数来获取这些变量,但是因为这两个函数中有一个参数,所以显示了一些错误。如何将空参数传递给这两个函数,使其满足条件(已传递1个参数),并检索存储在变量(即obs_ja1和obs_pose1)中的信息
我试图传递一些参数,但出现以下错误
Traceback (most recent call last):
File "./trial_pose.py", line 58, in <module>
take_observation()
File "./trial_pose.py", line 38, in take_observation
obs_ja1 = observation_callback_joint_angles()
TypeError: observation_callback_joint_angles() takes exactly 1 argument (0 given)
代码是
target_orientation = np.asarray([0.500077733518, -0.499998982263, 0.499900998414, 0.500022269464])
def observation_callback_joint_angles(joint_angles):
obs_ja1 = joint_angles
#print(obs_ja1.positions)
#print(message)
return obs_ja1
def observation_callback_pose(poses):
obs_pose1 = poses
#print(obs_pose1)
return obs_pose1
def take_observation():
# Check that the observation is not prior to the action
obs_ja1 = observation_callback_joint_angles()
obs_pose1 = observation_callback_pose()
joint_angles = np.array(obs_ja1.positions)
print(joint_angles)
curr_eef_position = np.array(obs_pose1.positions)
curr_eef_quat = np.ndarray.flatten(obs_pose1.orientation)
quat_error = tf3d.quaternions.qmult(curr_eef_quat, tf3d.quaternions.qconjugate(target_orientation))
eef_points = curr_eef_position - targetPosition
state = np.r_[np.reshape(joint_angles, -1),
np.reshape(eef_points, -1),
np.reshape(quat_error, -1)]
print (state)
return state
'''
RETURNS STATE
'''
take_observation()
rospy.init_node('trial_pose', anonymous= True)
while not rospy.is_shutdown():
# #*************** Uncomment this block if the node should send random points to the action function
# #Gives a random number between 1 and 6, to move the robot randomly with the 6 actions.
# action = random.randint(1,6)
# #Calls move function, which sends the wanted movement to the robot
#rospy.Subscriber("curr_pose_r1", geometry_msgs.msg.Pose, move_action)
obs_sub_pose = rospy.Subscriber("curr_pose_r2", Pose, observation_callback_pose)
obs_sub_ja = rospy.Subscriber("joint_angles_r2", JointTrajectoryPoint, observation_callback_joint_angles)
rospy.spin()
据我所知,您需要默认参数
例如,当您这样调用此函数时:
observation_callback_pose("argument1")
它返回
argument1
,但当您这样调用时:observation_callback_pose()
它返回
"invalid"
相关问题 更多 >
编程相关推荐