Skip to content

Commit

Permalink
학습 환경 구성 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sinyeong10 committed Sep 24, 2024
1 parent 9b0363a commit 7902f05
Show file tree
Hide file tree
Showing 34 changed files with 23,090 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ ckpts/
*.npy
play.ipynb

scr/
scr/
mycobot320_script/all_data/
3 changes: 1 addition & 2 deletions aloha_scripts/real_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ def __init__(self, init_node, setup_robots=True, setup_base=False):
if key == ord("q"):
break


self.cap1 = cv2.VideoCapture(1)
while True:
_, frame = self.cap1.read()

cv2.imshow("top", frame)
key = cv2.waitKey(10)
if key == ord("q"):
Expand Down
Binary file added model_run24000.txt
Binary file not shown.
Binary file added model_run24000_frame1.txt
Binary file not shown.
26 changes: 26 additions & 0 deletions model_run_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
wandb: Currently logged in as: cbrnt1210. Use `wandb login --relogin` to force relogin
wandb: wandb version 0.17.9 is available! To upgrade, please run:
wandb: $ pip install wandb --upgrade
wandb: Tracking run with wandb version 0.17.5
wandb: Run data is saved locally in /mnt/c/Users/cbrnt/OneDrive/문서/act-plus-plus/wandb/run-20240911_115447-o1r1nfyb
wandb: Run `wandb offline` to turn off syncing.
wandb: Syncing run twocam_mycobot320
wandb: ⭐️ View project at https://wandb.ai/cbrnt1210/mobile-aloha2
wandb: 🚀 View run at https://wandb.ai/cbrnt1210/mobile-aloha2/runs/o1r1nfyb
['/mnt/c/Users/cbrnt/OneDrive/문서/act-plus-plus', '/mnt/c/Users/cbrnt/OneDrive/문서/act-plus-plus', '/mnt/c/Users/cbrnt/OneDrive/문서/act-plus-plus/detr', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/imitation/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages', 'C:\\Users\\cbrnt\\OneDrive\\문서\\act-plus-plus\\detr', 'C:\\Users\\cbrnt\\OneDrive\\문서\\act-plus-plus\\detr\\models']
twocam_mycobot320
Found 10 hdf5 files


Data from: ['/mnt/c/Users/cbrnt/OneDrive/문서/act-plus-plus/scr/tonyzhao/datasets/sim_mycobot_320']
- Train on [9] episodes
- Test on [1] episodes


Error loading /mnt/c/Users/cbrnt/OneDrive/문서/act-plus-plus/scr/tonyzhao/datasets/sim_mycobot_320/two_cam_episode_0.hdf5 in get_norm_stats
"Unable to synchronously open object (object 'qvel' doesn't exist)"
wandb: - 0.003 MB of 0.003 MB uploadedwandb: \ 0.003 MB of 0.008 MB uploadedwandb: | 0.005 MB of 0.008 MB uploadedwandb: 🚀 View run twocam_mycobot320 at: https://wandb.ai/cbrnt1210/mobile-aloha2/runs/o1r1nfyb
wandb: ⭐️ View project at: https://wandb.ai/cbrnt1210/mobile-aloha2
wandb: Synced 5 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)
wandb: Find logs at: ./wandb/run-20240911_115447-o1r1nfyb/logs
wandb: WARNING The new W&B backend becomes opt-out in version 0.18.0; try it out with `wandb.require("core")`! See https://wandb.me/wandb-core for more information.
Expand Down
Binary file added model_run_chunk20_1.txt
Binary file not shown.
Binary file added model_run_chunk20_30000.txt
Binary file not shown.
Binary file added model_run_chunk20_4.txt
Binary file not shown.
Binary file added model_run_chunk20_5.txt
Binary file not shown.
Binary file added model_run_chunk20_best_27000.txt
Binary file not shown.
57 changes: 57 additions & 0 deletions mycobot320_script/action_cal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

#수정
base = [[(-3.07), 33.39, 32.78, 6.94, (-88.33), (-1.58)], \
[(-3.95), 66.53, 8.17, 6.32, (-88.59), (-1.84)], [(-3.95), 66.53, 8.17, 6.32, (-88.59), (-1.84)],\
[(-4.65), 56.6, 16.17, -7.47, (-91.4), (-3.95)], [(-2.54),29.44,23.81,17.92,(-88.33),(-84.81)],\
[24.08, 47.89, 0.52, 21.89, -89.03, -50.18],\
[24.08, 61.52, (-15.73), 35.5, (-89.12), (-71.19)], [24.08, 61.52, (-15.73), 35.5, (-89.12), (-71.19)]]

#초기
# base = [[(-3.07), 33.39, 32.78, 6.94, (-88.33), (-1.58)], \
# [(-3.95), 66.53, 8.17, 6.32, (-88.59), (-1.84)], [(-3.95), 66.53, 8.17, 6.32, (-88.59), (-1.84)],\
# [(-4.65), 56.6, 16.17, -7.47, (-91.4), (-3.95)], [(-2.54),29.44,23.81,17.92,(-88.33),(-84.81)],\
# [24.16,23.55,37.96,10.63,(-91.58),(-84.81)], [23.81,85.42,(-50.71),44.64,(-89.38),(-71.01)], [23.81,85.42,(-50.71),44.64,(-89.38),(-71.01)]]

print(len(base))
#10FPS기준
timestep = [1, 1, 1.5, 3, 1.5, 2.5, 1]
framestep = [10, 10, 15, 30, 15, 25, 10]
print(sum(timestep))
print(sum(framestep))

import numpy as np
def cal(a,b,framestep, FPS = 10):
a = np.array(a)
b = np.array(b)

step_time = 1 / FPS
# 나눌 갯수
# num_steps = int(total_time / step_time)

# 각도 간격을 나누는 함수 (등간격)
angles_over_time = np.linspace(a, b, framestep)
return angles_over_time[1:]
# print(len(angles_over_time), angles_over_time)

pre_base = np.array(base[0])
frame = [pre_base[np.newaxis, :]]
# print(frame)
# print(frame[0].shape)
for cur_base, cur_time in zip(base[1:], framestep):
cur_value = cal(pre_base, cur_base, cur_time+1)
# print(cur_value)
frame.append(cur_value)
pre_base = cur_base
angles_data = list(np.concatenate(frame, axis=0))

gripper_data = [70]*10+list(np.linspace(70, 20, 10))+[20]*85+list(np.linspace(20,70,10))
print(len(gripper_data), len(angles_data)) #그리퍼가 한개 작음, qpos에서 끝난 값이 다음 값과 연동되어 겹치는 값을 삭제하고 처음에 값을 추가시켰기 때문

cnt = 0
filename = "frame_base_action.txt"
with open(filename, 'w') as f:
for a, b in zip(gripper_data, angles_data):
print(cnt, a,b)
# 각 행의 데이터를 문자열로 변환하고 저장
f.write(str(cnt)+" : "+str(a)+" : "+str(list(b))+'\n')
cnt += 1
201 changes: 201 additions & 0 deletions mycobot320_script/best_gripper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
70
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
68
64
61
53
47
41
35
30
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
30
35
41
47
53
59
68
73
76
78
78
79
82
85
89
94
97
98
99
99
99
99
99
99
58 changes: 58 additions & 0 deletions mycobot320_script/cheak_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import threading
import time
from pymycobot.mycobot import MyCobot
import cv2

def print_motor_angles(mc):
try:
while True:
# 현재 모터 각도 출력
angles = mc.get_angles()
print(f"현재 모터 각도: {angles}")

# 1초간 대기
time.sleep(1)

except KeyboardInterrupt:
print("\n스레드가 사용자에 의해 종료됨")

# MyCobot 객체 초기화
mc = MyCobot('COM7', 115200) # 포트와 속도에 맞게 수정

# MyCobot 초기 설정
# mc.init_eletric_gripper()
# mc.set_eletric_gripper(0)
# mc.set_gripper_value(100, 20, 1)
mc.set_gripper_mode(0)
mc.send_angles([0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 20)

# 모터 각도 출력을 담당할 스레드 생성 및 실행
thread = threading.Thread(target=print_motor_angles, args=(mc,))
thread.start()


#벌리고 초기 이동
mc.init_eletric_gripper()
mc.set_eletric_gripper(0)
mc.set_gripper_value(100, 20, 1)
time.sleep(1)
mc.send_angles([0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 20)
time.sleep(5)

cv2.waitKey(0)
print(1)

try:
# 5초간 기다림
time.sleep(5)

except KeyboardInterrupt:
print("\n메인 프로그램이 사용자에 의해 종료됨")

finally:
# 스레드 종료
thread.join()

# 리소스 정리
mc.release_all_servos()
mc.disconnect()
Loading

0 comments on commit 7902f05

Please sign in to comment.