TypeError:observation_callback_pose()恰好接受1个参数(给定0个)

时间:2019-11-10 21:59:28

标签: python python-3.x

我正在尝试运行具有三个功能的代码,前两个功能具有单个参数,这对于从订阅服务器获取信息很重要。在第三个函数中,我实际上是在调用前两个函数来获取这些变量,但是由于这两个函数中都有一个自变量,因此会显示一些错误。我如何以满足条件(已传递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()



1 个答案:

答案 0 :(得分:0)

据我了解,您想要默认参数

def observation_callback_pose(poses = "invalid"):
    obs_pose1 = poses
    #print(obs_pose1)
    return obs_pose1

例如,当您像这样调用此函数时:

observation_callback_pose("argument1")

它返回argument1,但是当您这样调用时:

observation_callback_pose()

它返回"invalid"

相关问题