Robust Robot Kitchen Tasks

Robust Robot Kitchen Tasks#

Robust Robot Kitchen Tasks#

TasksRobust type

Robust State

Robust Action

Robust Reward

FrankaKitchen-v1

A Simple Example

import robust_gymnasium as gym
import json
import os
import time
from datetime import datetime

# Get current date and time for folder naming
currentDateAndTime = datetime.now()
start_run_date_and_time = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())

# Import configuration settings
from robust_gymnasium.configs.robust_setting import get_config
args = get_config().parse_args()

# Set environment and noise factor
args.env_name = "InvertedPendulum"  # Options: "InvertedDoublePendulum-v4", "Reacher-v4", etc.
args.noise_factor = "state"

# Define folder path for storing data
folder = os.getcwd()[:0] + 'data/' + str(args.env_name) + '/' + str(args.noise_type) + '/' + str(
    start_run_date_and_time) + '/'
print("folder---:", folder)

# Create folder if it doesn't exist
if not os.path.exists(folder):
    os.makedirs(folder)

# Save configuration settings to a JSON file
json_path = folder + '/config.json'
argsDict = args.__dict__
with open(json_path, 'w') as f:
    f.writelines('------------------ start ------------------' + '\n')
    for eachArg, value in argsDict.items():
        f.writelines(eachArg + ' : ' + str(value) + '\n')
    f.writelines('------------------- end -------------------')

# Initialize environment
env = gym.make('FrankaKitchen-v1', tasks_to_complete=['microwave', 'kettle'], render_mode="human")

# Reset environment and run simulation
observation, info = env.reset(seed=42)
for i in range(10000):
    action = env.action_space.sample()
    robust_input = {
        "action": action,
        "robust_type": "state",
        "robust_config": args,
    }
    observation, reward, terminated, truncated, info = env.step(robust_input)

    # Render environment
    env.render()
    if terminated or truncated:
        observation, info = env.reset()

# Close environment
env.close()