struct.error: 必需的参数不是整数

C0N*_*S3D 5 python python-3.x

我有以下python代码:

velocity = 0
rotation = 0
vr = velocity + (rotation/2)
vl = velocity - (rotation/2)
cmd = struct.pack(">Bhh", 145, vr, vl)
Run Code Online (Sandbox Code Playgroud)

我处理以下错误:

File "control.py", line 125, in __init__  
cmd = struct.pack(">Bhh", 145, vr, vl)  
struct.error: required argument is not an integer
Run Code Online (Sandbox Code Playgroud)

mus*_*_ut 5

您正在使用不正确的格式为您传递的参数:h格式指示存储的short,而值要传递的,即vrvl,样子double秒。

考虑将它们类型转换为int或使用">Bdd"格式。