-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_robot.py
80 lines (62 loc) · 2.61 KB
/
test_robot.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
# E. Culurciello
# February 2021
# PyBullet UR-5 from https://github.com/josepdaniel/UR5Bullety
import numpy as np
from itertools import count
from collections import namedtuple
import time, math
from random import randint
import torch
from argparse import ArgumentParser
import gym
from gym_env import ur5GymEnv
title = 'PyBullet UR5 robot'
def get_args():
parser = ArgumentParser(description=title)
arg = parser.add_argument
# trained model file for demo:
# arg('--inputfile', type=str, help='input model file (.pth)') # trained model
# env:
arg('--seed', type=int, default=543, help='random seed (default: 543)')
arg('--mel', type=int, default=120, help='max episode length')
arg('--repeat', type=int, default=1, help='repeat action')
arg('--render', action='store_true', default=True, help='render the environment')
arg('--randObjPos', action='store_true', default=False, help='fixed object position to pick up')
arg('--useIK', action='store_true', default=False, help='use IK or direct control')
# sim:
# arg('--data_size', type=int, default=30, help='dataset data size')
arg('--lp', type=float, default=0.05, help='learning parameter for task')
arg('--task', type=int, default=0, help='task to learn: 0 move, 1 pick-up, 2 drop')
arg('--simgrip', action='store_true', default=False, help='simulated gripper')
# dataset:
arg('--dataset', action='store_true', default=False, help='create a dataset for imitation learning')
arg('--ds', type=int, default=1000, help='number of episodes to collect for dataset')
args = parser.parse_args()
return args
args = get_args() # all input arguments
np.set_printoptions(precision=2, suppress=True)
torch.set_printoptions(profile="full", precision=2)
# create the environment
print(title)
args.env_name = title
env = ur5GymEnv(renders=args.render, maxSteps=args.mel, useIK=args.useIK,
actionRepeat=args.repeat, task=args.task, randObjPos=args.randObjPos,
simulatedGripper=args.simgrip, learning_param=args.lp)
obs = env.reset()
args.data_size = obs.shape[0]
def main():
positions = [0.,0.,0.,0.,0.,0.,0.]
# [[-0.6,0,0.1,0],[0,0.6,0.1,0],[0,0,-0.6,0],[0,0,0,0],
# [0,0,-0.6,0],[0,-0.6,0.1,0],[-0.6,0.1,0,0],[0,0,0,0]]
state = env.reset()
ep_reward = 0
for i in range(3):
for t in range(1, args.mel):
# p = int(t/20)
action = positions#[p]
state, reward, env_done, info = env.step(action)
# print(t, env.target_dist)
# input()
ep_reward += reward
if __name__ == '__main__':
main()