缺少1个必需的位置参数,以及另一个和另一个

2024-09-29 02:26:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python非常陌生。为机器人编程,可以让它做一些事情,但不能做其他事情。我使用的许多变量都是在制造商提供的模块中定义的,其中一些会显示大量错误消息,如“缺少1个必需的位置参数”。如果我试图修复另一个出现,等等。因为我对这一点太陌生了,我不敢相信这真的是图书馆模块的错。它真的需要大量的修补,还是我出了什么问题

下面是我收到的几个错误消息:

    Microsoft Windows [Version 10.0.19041.985]
(c) Microsoft Corporation. All rights reserved.

C:\Users\SUL-I>python experiment5.py
Traceback (most recent call last):
  File "C:\Users\SUL-I\experiment5.py", line 36, in <module>
    if fa.ReadLine(fa, 0) >= white:
  File "C:\Users\SUL-I\FA.py", line 185, in ReadLine
    self._flush()
TypeError: _flush() missing 1 required positional argument: 'self'

C:\Users\SUL-I>python experiment5.py
Traceback (most recent call last):
  File "C:\Users\SUL-I\experiment5.py", line 36, in <module>
    if fa.ReadLine(fa, 0) >= white:
  File "C:\Users\SUL-I\FA.py", line 188, in ReadLine
    r = self._readval("ReadLine", 1)
TypeError: _readval() missing 1 required positional argument: 'loop_max'

我正在编写的代码让机器人播放几个音符,闪烁灯光,然后沿着地板上标记的轨迹出发。声音和灯光都能正常工作,但它无法跟随轨道

#brings in external references
import FA 
import time

#defines some constants
black = 0
white = 200
correction = 10
w = 0

#controls the first robot, remember to update the com port number
fa = FA.Create
fa.ComOpen(fa,7)
time.sleep(5) 
fa.PlayNote(fa,294,800)
fa.PlayNote(fa,330,800)
fa.PlayNote(fa,262,800)
fa.LEDOn(fa, 0)
fa.LEDOff(fa,0)
fa.LEDOn(fa,1)
fa.LEDOff(fa,1)
fa.LEDOn(fa,2)
fa.LEDOff(fa,2)
fa.LEDOn(fa,3)
fa.LEDOff(fa,3)
fa.LEDOn(fa,4)
fa.LEDOff(fa,4)
fa.LEDOn(fa,5)
fa.LEDOff(fa,5)
fa.LEDOn(fa,6)
fa.LEDOff(fa,6)
fa.LEDOn(fa,7)
fa.LEDOff(fa,7)

while w < 100:
    if fa.ReadLine(fa, 0) >= white:
                fa.SetMotors(20,10)
    elif fa.ReadLine(fa, 1) >= white:
                fa.SetMotors(10,20)
    else:
                fa.Forwards(10)
    w = w+1

fa.ComClose(fa,7)

Tags: inpyselfreadlineiflineusersfile