-
Notifications
You must be signed in to change notification settings - Fork 0
/
kick_ball.py
99 lines (73 loc) · 2.73 KB
/
kick_ball.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import gym
import qi
import humanoid_gym
import pybullet as p
import pybullet_data as pd
import numpy as np
import time
env = gym.make("nao-v1")
# p.removeBody()
p.setAdditionalSearchPath(pd.getDataPath())
s = qi.Session()
IP = "127.0.0.1"
port = 9559
# env.joint_names
# https://developer.softbankrobotics.com/sites/default/files/repository/70_html_nao/_images/naov6_almotion_names.png
s.connect("tcp://{}:{}".format(IP, port))
motion = s.service("ALMotion")
# name = "LLeg" #RLeg
# frame = motion.FRAME_WORLD
# useSensorValues = True
# result = motion_service.getPosition(name, frame, useSensorValues)
# planeId = p.loadSDF("stadium.sdf")
goalPostStartPos = [4, 0, 0] # -26.7
goalPostStartOrientation = p.getQuaternionFromEuler([np.pi/2, 0, np.pi])
goalPostId = p.loadURDF("goal_post.urdf", goalPostStartPos,
goalPostStartOrientation, globalScaling=0.1, useFixedBase=False)
# Ball config
# 68–70 cm
mass = 0.044 # 410 - 450 g
z = 0.314
root = [0, 0, 0]
sphereRadius = 0.05 # 0.05
legPose = np.array(env.robot.getPosition())+np.array([0.16, -0.08, 0])
x, y, z = legPose # result #0, 0, 0
basePosition = [x, y, z] # location of the leg
offset = 0
scale = 1
ball = p.loadURDF("soccerball.urdf", basePosition, globalScaling=scale*0.1)
p.changeDynamics(ball, -1, linearDamping=0, angularDamping=0,
rollingFriction=0.001, spinningFriction=0.001)
p.changeVisualShape(ball, -1, rgbaColor=[0.8, 0.8, 0.8, 1])
def swapAction(action, lstPos1, lstPos2):
"""
# lstPos1 = [start, length]
# lstPos2 = [start, length]
"""
start1, start2 = lstPos1[0], lstPos2[0]
end1, end2 = lstPos1[0] + lstPos1[1], lstPos2[0] + lstPos2[1]
action[start2:end2], action[start1:end1] = action[start1:end1], action[start2:end2]
return action
# baseOrientation = [0, 0, 0, 1]
# colSphereId = p.createCollisionShape(p.GEOM_SPHERE, radius=sphereRadius)
# visualShapeId = p.createVisualShape(p.GEOM_SPHERE, radius=sphereRadius)
# sphereUid = p.createMultiBody(
# mass, colSphereId, visualShapeId, basePosition, baseOrientation)
# for i in range(100_000):
while p.isConnected():
actions = np.array(motion.getAngles("Body", False)
) # env.action_space.sample()
lstPos1 = [2, 6] # LArm
lstPos2 = [8, 6] # RLeg
corrected_actions = np.array(swapAction(
actions.tolist().copy(), lstPos1, lstPos2))
lstPos3 = [14, 6] # LLeg
corrected_actions = np.array(swapAction(
corrected_actions.tolist().copy(), lstPos2, lstPos3))
env.step(corrected_actions)
# p.applyExternalForce(sphereUid,-1, force, [0,0,0], p.LINK_FRAME)
# p.stepSimulation()
# time.sleep(2)
input('Press enter to continue....')
env.close()
s.close()