struct.error: required argument is not an integer

Question:

I have the following python code:

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

I am dealing with the following error:

File "control.py", line 125, in __init__  
cmd = struct.pack(">Bhh", 145, vr, vl)  
struct.error: required argument is not an integer
Asked By: J05H

||

Answers:

You are using the incorrect formats for the arguments you are passing in: h format indicates storing of short, while the value you are passing in, i.e. vr and vl, look like doubles.

Consider typecasting them to int or using ">Bdd" format.

Answered By: musically_ut
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.