-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_pygame.py
77 lines (64 loc) · 2.34 KB
/
client_pygame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
import time
from math import *
from controller import UDPCtrlClient
from omniwalk import *
import pygame
from pygame.locals import *
# checks for command line arguments
if len(sys.argv) != 4:
print 'Usage:', sys.argv[0],'server_url server_port client_port'
sys.exit(0)
# creates the UDP client interface
c = UDPCtrlClient(sys.argv[1], sys.argv[2], sys.argv[3])
# Walking phase
tau = 0.0
tauInc = 2.0*pi / 200.0
# control = ControlInterface([3.5,0.0085,0.01,0.009,0.09,0.008,0])
motion = MotionPattern()
leg = LegInterface()
# Init PyGame
pygame.init()
pygame.display.set_mode((800,600))
tela = pygame.display.get_surface()
VX = 0.0
quit = False
while not quit:
for e in pygame.event.get():
if e.type == QUIT:
quit = True
elif e.type == KEYDOWN:
if e.key == K_UP:
print "Seta para cima"
VX = VX + 1.0
# calculates angles for the left leg
angles = motion.final_motion(VX, 0.0, 0.0, tau, -1)
rightJointAngles = leg.joint_angles(angles)
# calculates angles for the right leg
angles = motion.final_motion(0.0, 0.5, 0.0, (tau+2*pi) % (2*pi) - pi, 1)
leftJointAngles = leg.joint_angles(angles)
# prepare the omniwalk commands to be sent
# to the server
command = {'lHipRoll':leftJointAngles['hipRoll'],\
'rHipRoll':rightJointAngles['hipRoll'],\
'lHipTilt':-leftJointAngles['hipPitch'],\
'rHipTilt':-rightJointAngles['hipPitch'],\
'lHipYaw':leftJointAngles['hipYaw'],\
'rHipYaw':rightJointAngles['hipYaw'],\
'lKnee':-leftJointAngles['knee'],\
'rKnee':-rightJointAngles['knee'],\
'lAnkleRoll':leftJointAngles['ankleRoll'],\
'rAnkleRoll':rightJointAngles['ankleRoll'],\
'lAnkleTilt':-leftJointAngles['anklePitch'],\
'rAnkleTilt':-rightJointAngles['anklePitch'],\
}
# sends the desired target angles to server, and
# receive back in r all the current sensor readings
r = c.sendCommand(command)
# prints the tilt sensor reading
if r is not None and 'tilt' in r:
print 'Tilt sensor reading: %+.3f' % r['tilt']
# increments tau keeping it in the [-pi,pi) interval
tau = (tau+tauInc+pi) % (2*pi) - pi
time.sleep(0.01)
pygame.display.update()