scaled control to (-1,1)

master
Simon Pirkelmann 2019-05-05 11:01:40 +02:00
parent 845ead5df4
commit 14ad366484
2 changed files with 11 additions and 11 deletions

View File

@ -36,7 +36,7 @@ class Robot:
while listening:
# expected data: '(u1, u2)'\n"
# where ui = control for motor i
# ui \in [10000, 10000]
# ui \in [-1.0, 1.0]
data = comm_socket.readline()
data_str = data.decode()
print("Data received: {}".format(data_str))
@ -44,9 +44,9 @@ class Robot:
print("processing data = {}".format(data_str))
l = data_str.strip('()\n').split(',')
print("l = {}".format(l))
u1 = int(l[0])
u1 = int(float(l[0])*10000)
print("u1 = {}".format(u1))
u2 = int(l[1])
u2 = int(float(l[1])*10000)
print("u2 = {}".format(u2))
except ValueError:
print("ValueError: Data has wrong format.")

View File

@ -16,20 +16,20 @@ while True:
for event in events:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
u1 = 10000
u2 = -10000
u1 = 1.0
u2 = -1.0
print("turn left: ({},{})".format(u1, u2))
elif event.key == pygame.K_RIGHT:
u1 = -10000
u2 = 10000
u1 = -1.0
u2 = 1.0
print("turn right: ({},{})".format(u1, u2))
elif event.key == pygame.K_UP:
u1 = -10000
u2 = -10000
u1 = -1.0
u2 = -1.0
print("forward: ({},{})".format(u1, u2))
elif event.key == pygame.K_DOWN:
u1 = 10000
u2 = 10000
u1 = 1.0
u2 = 1.0
print("forward: ({},{})".format(u1, u2))
rc_socket.send('({},{})\n'.format(u1, u2))
elif event.type == pygame.KEYUP: