Comments (7)
There is no native argument that does this. I suggest you constrain the action. You can do this by wrapping the send (with gym.Wrapper
). Your wrapper would look like
from gym import Wrapper
class StayFrontWrapper(gym.Wrapper):
def reset(self):
obs = super().reset()
self._last_obs = obs["observation"]
return obs
def step(self, action):
if not self.is_front():
action[0] = 0.0 # x displacement
obs, reward, done, info = super().step(action)
self._last_obs = obs["observation"]
return obs, reward, done, info
def is_front(self):
if self._last_obs[0] > 0.0: # x ee position
return True
else:
return False
I haven't tested this code, but it gives you an idea of what I would do if I were you.
Feel free to publish the solution you finally choose here, it could help other people.
from panda-gym.
Thanks a lot!
from panda-gym.
Hello,I just only change this RobotTaskEnv class(add def is_front(),modify the steps by adding :if not self.is_front():
action[0] = 0.0 # x displacement,adding self._last_obs = obs["observation"] in init),but don't work,the robot still go back as usual,Do you know Why,thanks!
`class RobotTaskEnv(gym.GoalEnv):
metadata = {"render.modes": ["human", "rgb_array"]}
def __init__(self):
self.seed() # required for init for can be changer later
obs = self.reset()
observation_shape = obs["observation"].shape
achieved_goal_shape = obs["achieved_goal"].shape
desired_goal_shape = obs["achieved_goal"].shape
self._last_obs = obs["observation"]
self.observation_space = spaces.Dict(
dict(
observation=spaces.Box(-np.inf, np.inf, shape=observation_shape),
desired_goal=spaces.Box(-np.inf, np.inf, shape=achieved_goal_shape),
achieved_goal=spaces.Box(-np.inf, np.inf, shape=desired_goal_shape),
)
)
self.action_space = self.robot.action_space
self.compute_reward = self.task.compute_reward
self.render = self.sim.render
def _get_obs(self):
robot_obs = self.robot.get_obs() # robot state
task_obs = self.task.get_obs() # object position, velococity, etc...
observation = np.concatenate([robot_obs, task_obs])
achieved_goal = self.task.get_achieved_goal()
return {
"observation": observation,
"achieved_goal": achieved_goal,
"desired_goal": self.task.get_goal(),
}
def reset(self):
with self.sim.no_rendering():
self.robot.reset()
self.task.reset()
return self._get_obs()
def step(self, action):
if not self.is_front():
action[0] = 0.0 # x displacement
self.robot.set_action(action)
self.sim.step()
obs = self._get_obs()
done = False
info = {
"is_success": self.task.is_success(obs["achieved_goal"], self.task.get_goal()),
}
reward = self.task.compute_reward(obs["achieved_goal"], self.task.get_goal(), info)
return obs, reward, done, info
def seed(self, seed=None):
"""Setup the seed."""
return self.task.seed(seed)
def close(self):
self.sim.close()
def is_front(self):
if self._last_obs[0] > 0: # x ee position
return True
else:
return False`
from panda-gym.
Have you check whether the is_front
method work as expected? You can print something when is_front
returns True
and compare with what you observe in the rendering.
from panda-gym.
Have you check whether the
is_front
method work as expected? You can print something whenis_front
returnsTrue
and compare with what you observe in the rendering.
thanks ,I will try
from panda-gym.
Have you check whether the
is_front
method work as expected? You can print something whenis_front
returnsTrue
and compare with what you observe in the rendering.
@qgallouedec ,thanks a lot,I put self._last_obs = obs["observation"] in the _get_obs,not in the init.It works.
Btw, do you know some useful Rl Library(except RB3(which takes a long time for me to train,may be the environment is too hard ))to train or you write the Rl algorithm yourself?
from panda-gym.
I use mainly SB3. You can speed up learning by using multiprocessing, but AFIK it is not released yet for off-policy algorithms (soon, maybe ?). Check DLR-RM/stable-baselines3#179 (comment), it can help.
from panda-gym.
Related Issues (20)
- When is it panda-gym going to be compatible with python 3.11? HOT 1
- how to realize the sb3 train demo code with panda-gym? HOT 2
- Typo in the `core.py` script HOT 1
- Render screen is out of sync HOT 6
- `NAN` in the training HOT 1
- How to get `predict` data from a saved model? HOT 2
- TypeError: catching classes that do not inherit from BaseException is not allowed HOT 6
- Shape of `achieved_goal` and `desired_goal` HOT 6
- Discussion about the future work HOT 9
- Decreasing Size of Action Space HOT 2
- Compatibility of gym-0.24 branch? HOT 2
- panda-gym v2 error; "TypeError: catching classes that do not inherit from BaseException is not allowed". HOT 2
- Clarification about 'observation', 'achieved_goal' and 'desired_goal' HOT 5
- Flip and Stack question HOT 3
- change the observation and return HOT 1
- reproduce the results HOT 1
- reproduce the results HOT 2
- Set to move in a two-dimensional plane HOT 6
- Clarification about the observation or system state returned by the task class HOT 1
- Can the SAC algorithm without using HER converge in some of the environments in this project?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from panda-gym.