Пример #1
0
def collect_data():
    robot = Robot()
    cubusm = CubesManager()
    for i in range(MAX_PICTURE_NUM):
        cubusm.reset_cube(rand=True)
        Box_position = cubusm.read_cube_pose("demo_cube")
        # print "cube position:", str(Box_position)
        joint, view = robot.get_state()
        rgb, dep = robot.get_rgb_dep()
        # b, g, r = cv2.split(rgb)
        # print view[0,0,0]
        # print dep
        # rgb = cv2.merge([r, g, b])
        # print dep
        # plt.imshow(dep)
        # plt.show()
        rgb = cv2.resize(rgb, (224, 224))
        dep = cv2.resize(dep, (224, 224))
        # print dep
        cv2.imwrite(
            "/home/ljt/Desktop/images/rgb/" + str(Box_position) + ".png", rgb)
        # cv2.imwrite("/home/ljt/Desktop/ws/src/fetch_moveit_config/images/dep/" + str(Box_position) + ".png", dep)
        # a = np.array(rgb).shape
        # print a
        # print "camera image shape:", view.shape
        np.save("/home/ljt/Desktop/images/dep/" + str(Box_position), dep)
Пример #2
0
import math
from camera import RGBD
from MofanDDPG import DDPG
from Env import Robot, CubesManager
import copy
import numpy as np

MAX_EPISODES = 900
MAX_EP_STEPS = 5
ON_TRAIN = True

if __name__ == '__main__':
    # set env
    robot = Robot()
    cubm = CubesManager()
    observation_dim = 3
    action_dim = 3
    action_bound = -1, 1

    # set RL method (continuous)
    rl = DDPG(action_dim, observation_dim, action_bound)
    number = 0
    steps = []
    # start training
    for i in range(MAX_EPISODES):

        cubm.reset_cube(rand=True)
        Box_position = cubm.read_cube_pose("demo_cube")
        print "cube position:", Box_position
        robot.Box_position = copy.deepcopy(Box_position)
        now_position = robot.gripper.get_current_pose(