-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_sim.py
69 lines (66 loc) · 2.46 KB
/
debug_sim.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
from mujoco_py import load_model_from_path, MjSim, MjViewer
from mymjviewer import MyMjViewer
import numpy as np
import math
import random
import os
import sys
import glfw
# model = load_model_from_path("~/Downloads/darwin/darwin_OP.xml")
model = load_model_from_path("./xml/world5.xml")
sim = MjSim(model)
viewer = MyMjViewer(sim)
t=0
def norm_vec(vec):
norm = np.linalg.norm(vec)
vec = vec/norm
return vec
while True:
sim.step()
robot_x, robot_y = sim.data.body_xpos[1][0:2]
ball_x, ball_y = sim.data.body_xpos[2][0:2]
vx = sim.data.qvel[0:2]
ball_vel = sim.data.qvel[2:4]
ball_pos_local = -(robot_x - ball_x), -(robot_y - ball_y)
# goal_arr = (-ball_y)/(-90 - ball_x)
# goal_oriented_arr = (ball_vel[1])/(ball_vel[0])
goal_arr = np.array([-90-ball_x,-ball_y])
goal_oriented_arr = np.array([ball_vel[0],ball_vel[1]])
goal_arr = norm_vec(goal_arr)
goal_arr_deg = math.degrees(math.atan2(goal_arr[1],goal_arr[0]))
goal_oriented_arr = norm_vec(goal_oriented_arr)
goal_oriented_deg = math.atan2(goal_oriented_arr[1],goal_oriented_arr[0])
goal_oriented_deg = math.degrees(goal_oriented_deg)
distance = math.sqrt(ball_pos_local[0]**2 + ball_pos_local[1]**2)
print("----------------------------")
print("robot: ",robot_x,robot_y)
# print("ball: ",ball_x,ball_y)
# print("local: ",ball_pos_local)
# print("distance: ",distance)
# print("robot_vel:",vx)
# print("goa: ",round(goal_oriented_arr,1))
# print("ga: ",round(goal_arr,1))
# print("diff_arr: ",round(math.fabs(goal_arr-goal_oriented_arr),1))
# print("goa: ",goal_oriented_arr)
print("goal_deg: ",goal_oriented_deg)
# print("ga: ",goal_arr)
print("ga_deg: ",goal_arr_deg)
print("vel: ",vx)
print("vel: ",ball_vel)
print("vel: ",round(sim.data.qvel[5],2))
print("vel: ",round(sim.data.qvel[6],2))
print("vel: ",round(sim.data.qvel[8],2))
print("vel: ",round(sim.data.qvel[9],2))
print("vel: ",round(sim.data.qvel[11],2))
print("vel: ",round(sim.data.qvel[12],2))
print("vel: ",round(sim.data.qvel[14],2))
print("vel: ",round(sim.data.qvel[15],2))
print(math.fabs(round(sim.data.qvel[6])), math.fabs(round(sim.data.qvel[7])))
# print("ball_vel: ",ball_vel)
print("----------------------------")
print()
t+=1
viewer.render()
if ball_x > 80 and -25< ball_y < 25:
print("reset!!")
sim.reset()