Example #1
0
def simple_rgb_profile_zigzag():
    PaintGymEnv.change_action_mode(1, 'discrete', 4)
    PaintGymEnv.change_obs_mode('grid', 10)

    with PaintGymEnv(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  'PaintRLEnv'),
                     with_robot=False,
                     renders=False,
                     render_video=False,
                     rollout=False,
                     extra_config=EXTRA_CONFIG) as env:
        for _ in range(100):
            env.reset()
            horizontal_move = 0
            up = True
            done = False
            obs = [0, 0]
            total_return = 0
            step_counter = 0
            while not done:
                if up:
                    if obs[1] < 0.95:
                        obs, reward, done, info = env.step(1)
                        step_counter += 1
                    elif horizontal_move < 2:
                        obs, reward, done, info = env.step(0)
                        step_counter += 1
                        horizontal_move += 1
                    else:
                        horizontal_move = 0
                        reward = 0
                        up = False
                else:
                    if obs[1] > 0.05:
                        obs, reward, done, info = env.step(3)
                        step_counter += 1
                    elif horizontal_move < 2:
                        obs, reward, done, info = env.step(0)
                        step_counter += 1
                        horizontal_move += 1
                    else:
                        horizontal_move = 0
                        reward = 0
                        up = True
                print('OBS: {0}, REWARD: {1}'.format(obs, reward))
                total_return += reward
            print('In {0} steps get {1} rewards'.format(
                step_counter, total_return))
Example #2
0
def simple_rgb_zigzag():
    PaintGymEnv.change_action_mode(1, 'discrete', 4)
    PaintGymEnv.change_obs_mode('discrete', 4)

    with PaintGymEnv(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  'PaintRLEnv'),
                     with_robot=False,
                     renders=True,
                     render_video=False,
                     rollout=True,
                     extra_config=EXTRA_CONFIG) as env:
        horizontal_move = 0
        up = True
        done = False
        obs = [0] * 5
        total_return = 0
        step_counter = 0
        while not done:
            current_pos = 0 if obs[-1] == 0 else round(1 / obs[-1])
            if up:
                if current_pos % 22 != 19:
                    obs, reward, done, info = env.step(1)
                    step_counter += 1
                elif horizontal_move < 2:
                    obs, reward, done, info = env.step(0)
                    step_counter += 1
                    horizontal_move += 1
                else:
                    horizontal_move = 0
                    reward = 0
                    up = False
            else:
                if current_pos % 22 != 2:
                    obs, reward, done, info = env.step(3)
                    step_counter += 1
                elif horizontal_move < 2:
                    obs, reward, done, info = env.step(0)
                    step_counter += 1
                    horizontal_move += 1
                else:
                    horizontal_move = 0
                    reward = 0
                    up = True
            print('OBS: {0}, REWARD: {1}'.format(obs, reward))
            total_return += reward
        print('In {0} steps get {1} rewards'.format(step_counter,
                                                    total_return))
Example #3
0
def simple_hsi_zigzag():
    EXTRA_CONFIG['COLOR_MODE'] = 'HSI'
    PaintGymEnv.change_action_mode(2, 'continuous')
    PaintGymEnv.change_obs_mode('simple', 4)

    with PaintGymEnv(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  'PaintRLEnv'),
                     with_robot=False,
                     renders=True,
                     render_video=False,
                     rollout=True,
                     extra_config=EXTRA_CONFIG) as env:
        horizontal_move = 0
        up = True
        done = False
        obs = [0, 0]
        total_return = 0
        step_counter = 0
        while not done:
            if up:
                if obs[1] < 0.95:
                    obs, reward, done, info = env.step([0, 1])
                    step_counter += 1
                elif horizontal_move < 2:
                    obs, reward, done, info = env.step([0.5, 0])
                    step_counter += 1
                    horizontal_move += 1
                else:
                    horizontal_move = 0
                    reward = 0
                    up = False
            else:
                if obs[1] > 0.05:
                    obs, reward, done, info = env.step([0, -1])
                    step_counter += 1
                elif horizontal_move < 2:
                    obs, reward, done, info = env.step([0.5, 0])
                    step_counter += 1
                    horizontal_move += 1
                else:
                    horizontal_move = 0
                    reward = 0
                    up = True
            print('OBS: {0}, REWARD: {1}'.format(obs, reward))
            total_return += reward
        print('In {0} steps get {1} rewards'.format(step_counter,
                                                    total_return))
Example #4
0
def simple_hsi_spiral():
    EXTRA_CONFIG['COLOR_MODE'] = 'HSI'
    PaintGymEnv.change_action_mode(1, 'discrete', 4)
    PaintGymEnv.change_obs_mode('simple', 4)

    with PaintGymEnv(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  'PaintRLEnv'),
                     with_robot=False,
                     renders=True,
                     render_video=False,
                     rollout=True,
                     extra_config=EXTRA_CONFIG) as env:
        start_points = getattr(env, '_start_points')
        axis_1, axis_2 = [], []
        for sp in start_points:
            axis_1.append(sp[0][1])
            axis_2.append(sp[0][2])

        x = min(axis_1) + (max(axis_1) - min(axis_1)) / 2
        y = min(axis_2) + (max(axis_2) - min(axis_2)) / 2

        center_point = [[start_points[0][0][0], x, y], start_points[0][1]]
        env.robot.reset(center_point)
        done = False
        total_return = 0
        step_counter = 0
        direction = 0
        strait_counter = 1
        current_counter = strait_counter
        while not done:
            current_counter -= 1
            obs, reward, done, info = env.step(direction % 4)
            if current_counter == 0:
                strait_counter += 1
                direction += 1
                current_counter = strait_counter
            step_counter += 1
            print('OBS: {0}, REWARD: {1}'.format(obs, reward))
            total_return += reward
        print('In {0} steps get {1} rewards'.format(step_counter,
                                                    total_return))