Strange behavior in…
 
Share:
Notifications
Clear all

Strange behavior in Python when sen valut > 327 degree


44cbc7aedc90f661cb8a3bc67180d460?s=80&d=mm&r=g
(@jan-kromhout)
Member Customer
Joined: 2 months ago
Posts: 3
Topic starter  

Build the Laserpointer without any problem. All seems to work fine. Now I tested the software.When I run the python application a lot of trouble found. Reason the games in Pygame. I have no gamepad on my MacBook so I delete all stuf related to this gamepad. Program is running now and display to put in value is working only when I give in the Angle1 and Angle2. Az/El is not working, but I will found out why. But when I give the Angle1 a value of 350 I get an error by exception. It seems the sendCommand is giving the problem with these values. I think the problem is the behavior of the integer range (-32,768 to 32,767). The value of 327 is working fine, but the value of 328 gives an error.

Have tried to fiend the position in the Arduino code to change this but it is hard to find. Please can you help me out with this.

 

Cheers,

Jan Kromhout, Hellevoetsluis-NL

 


Quote
Topic Tags
44cbc7aedc90f661cb8a3bc67180d460?s=80&d=mm&r=g
(@jan-kromhout)
Member Customer
Joined: 2 months ago
Posts: 3
Topic starter  

Found the problem, it is in the python routine sendCommand.

If the value  a1*100 or a2*100 is outside <-32,768 .. 32,767> there is a problem with byte array(struct.pack(“>h”,p1)

I don’t know how to solve this problem.

 

def sendCommand(Header,p1,p2,p3=0,p4=0,p5=0,p6=0,p7=0,p8=0):
    base = bytearray(Header)  # message
    param1 = bytearray(struct.pack(">h",p1))
    param2 = bytearray(struct.pack(">h",p2))
    param3 = bytearray(struct.pack(">h",p3))
    param4 = bytearray(struct.pack(">h",p4))
    param5 = bytearray(struct.pack(">h",p5))
    param6 = bytearray(struct.pack(">h",p6))
    param7 = bytearray(struct.pack(">h",p7))
    param8 = bytearray(struct.pack(">h",p8))
    message = base+param1+param2+param3+param4+param5+param6+param7+param8

ReplyQuote
Share: