scaled control to (-1,1)
This commit is contained in:
parent
845ead5df4
commit
14ad366484
|
@ -36,7 +36,7 @@ class Robot:
|
||||||
while listening:
|
while listening:
|
||||||
# expected data: '(u1, u2)'\n"
|
# expected data: '(u1, u2)'\n"
|
||||||
# where ui = control for motor i
|
# where ui = control for motor i
|
||||||
# ui \in [10000, 10000]
|
# ui \in [-1.0, 1.0]
|
||||||
data = comm_socket.readline()
|
data = comm_socket.readline()
|
||||||
data_str = data.decode()
|
data_str = data.decode()
|
||||||
print("Data received: {}".format(data_str))
|
print("Data received: {}".format(data_str))
|
||||||
|
@ -44,9 +44,9 @@ class Robot:
|
||||||
print("processing data = {}".format(data_str))
|
print("processing data = {}".format(data_str))
|
||||||
l = data_str.strip('()\n').split(',')
|
l = data_str.strip('()\n').split(',')
|
||||||
print("l = {}".format(l))
|
print("l = {}".format(l))
|
||||||
u1 = int(l[0])
|
u1 = int(float(l[0])*10000)
|
||||||
print("u1 = {}".format(u1))
|
print("u1 = {}".format(u1))
|
||||||
u2 = int(l[1])
|
u2 = int(float(l[1])*10000)
|
||||||
print("u2 = {}".format(u2))
|
print("u2 = {}".format(u2))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("ValueError: Data has wrong format.")
|
print("ValueError: Data has wrong format.")
|
||||||
|
|
|
@ -16,20 +16,20 @@ while True:
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
if event.key == pygame.K_LEFT:
|
||||||
u1 = 10000
|
u1 = 1.0
|
||||||
u2 = -10000
|
u2 = -1.0
|
||||||
print("turn left: ({},{})".format(u1, u2))
|
print("turn left: ({},{})".format(u1, u2))
|
||||||
elif event.key == pygame.K_RIGHT:
|
elif event.key == pygame.K_RIGHT:
|
||||||
u1 = -10000
|
u1 = -1.0
|
||||||
u2 = 10000
|
u2 = 1.0
|
||||||
print("turn right: ({},{})".format(u1, u2))
|
print("turn right: ({},{})".format(u1, u2))
|
||||||
elif event.key == pygame.K_UP:
|
elif event.key == pygame.K_UP:
|
||||||
u1 = -10000
|
u1 = -1.0
|
||||||
u2 = -10000
|
u2 = -1.0
|
||||||
print("forward: ({},{})".format(u1, u2))
|
print("forward: ({},{})".format(u1, u2))
|
||||||
elif event.key == pygame.K_DOWN:
|
elif event.key == pygame.K_DOWN:
|
||||||
u1 = 10000
|
u1 = 1.0
|
||||||
u2 = 10000
|
u2 = 1.0
|
||||||
print("forward: ({},{})".format(u1, u2))
|
print("forward: ({},{})".format(u1, u2))
|
||||||
rc_socket.send('({},{})\n'.format(u1, u2))
|
rc_socket.send('({},{})\n'.format(u1, u2))
|
||||||
elif event.type == pygame.KEYUP:
|
elif event.type == pygame.KEYUP:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user