oTypeError: in method 'Motor_setTorque', argument 2 of type 'double

在用Python写webots程序时遇到的问题,robot_motor是一个4*3的矩阵,每一个都是同一个类(软件自带的motor)。之后为了方便对某一个元素进行修改与操作,遍写了一个函数。发现当这个矩阵存在未知量的时候没法正确引出list类型。
但是我在定义函数时已经包含了这两个变量leg和name def set_motor_torque(leg, name, torque)

img

该回答引用ChatGPT

试一下这个

from controller import Motor

# 初始化 robot_motor 矩阵
robot_motor = [[Motor() for j in range(3)] for i in range(4)]

# 定义函数,对某一个元素进行修改与操作
def set_motor_torque(leg, name, torque):
    max_torque = 1800
    if torque > max_torque:
        torque = max_torque
    if torque < -max_torque:
        torque = -max_torque
    robot_motor[leg][name].setTorque(torque)

# 调用函数
leg = 0
name = 1
torque = 1000
set_motor_torque(leg, name, torque)