jr-robotics / robo-gym

An open source toolkit for Distributed Deep Reinforcement Learning on real and simulated robots.
https://sites.google.com/view/robo-gym
MIT License
390 stars 74 forks source link

Unable to create Real World Environment. Connection refused #74

Open KarimHP opened 1 year ago

KarimHP commented 1 year ago

So im at the step "Real Robot Environment" in your github repository. I already started the robot server and am connected to my real world ur5, as you can see in this screenshot: screen

Now the problem is, when i try to run

import gym, robo_gym
#ip adress of the ur5 = 192.168.9.100 and robot server is 50051 as you can see in the screenshot
env = gym.make('EnvironmentNameRob-v0', rs_address='192.168.0.100:50051')

env.reset()

First i get the following error:

Traceback (most recent call last):
  File "/home/moga/Desktop/start.py", line 3, in <module>
    env = gym.make('EnvironmentNameRob-v0', rs_address='192.168.0.100:50051')
  File "/home/moga/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 569, in make
    _check_version_exists(ns, name, version)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 219, in _check_version_exists
    _check_name_exists(ns, name)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 197, in _check_name_exists
    raise error.NameNotFound(
gym.error.NameNotFound: Environment EnvironmentNameRob doesn't exist. Did you mean: `EmptyEnvironmentURRob`?

So i change EnviromentNameRob to EmptyEnvironmentURRob, leaving my code looking like this:


import gym, robo_gym

env = gym.make('EmptyEnvironmentURRob-v0', rs_address='192.168.0.100:50051')

env.reset()
""""
But when i run it now i get the following Error: 

"""
/bin/python3 /home/moga/Desktop/start.py
/home/moga/.local/lib/python3.8/site-packages/gym/spaces/box.py:127: UserWarning: WARN: Box bound precision lowered by casting to float32
  logger.warn(f"Box bound precision lowered by casting to {self.dtype}")
/home/moga/.local/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:174: UserWarning: WARN: Future gym versions will require that `Env.reset` can be passed a `seed` instead of using `Env.seed` for resetting the environment random number generator.
  logger.warn(
/home/moga/.local/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:187: UserWarning: WARN: Future gym versions will require that `Env.reset` can be passed `options` to allow the environment initialisation to be passed additional information.
  logger.warn(
Traceback (most recent call last):
  File "/home/moga/Desktop/start.py", line 5, in <module>
    env.reset()
  File "/home/moga/.local/lib/python3.8/site-packages/gym/wrappers/order_enforcing.py", line 42, in reset
    return self.env.reset(**kwargs)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/wrappers/env_checker.py", line 45, in reset
    return env_reset_passive_checker(self.env, **kwargs)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/utils/passive_env_checker.py", line 192, in env_reset_passive_checker
    result = env.reset(**kwargs)
  File "/home/moga/Desktop/robo-gym/robo_gym/envs/ur/ur_base_env.py", line 104, in reset
    if not self.client.set_state_msg(state_msg):
  File "/home/moga/.local/lib/python3.8/site-packages/robo_gym_server_modules/robot_server/client.py", line 17, in set_state_msg
    msg = self.robot_server_stub.SetState(state_msg, timeout = 60)
  File "/home/moga/.local/lib/python3.8/site-packages/grpc/_channel.py", line 1030, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/moga/.local/lib/python3.8/site-packages/grpc/_channel.py", line 910, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:192.168.0.100:50051: Failed to connect to remote host: Connection refused"
        debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNKNOWN: ipv4:192.168.0.100:50051: Failed to connect to remote host: Connection refused {created_time:"2023-03-31T16:20:50.938544639+02:00", grpc_status:14}"
>

What am i doing wrong here? thank you in advance for every help im a bit lost

UPDATE (still not working):

I also tried with a little bit of a different script and another ip adress:

import gym
import robo_gym
from robo_gym.wrappers.exception_handling import ExceptionHandling

env = gym.make('EndEffectorPositioningURRob-v0', rs_address='127.0.0.1:50051')
env = ExceptionHandling(env)

num_episodes = 10

for episode in range(num_episodes):
    print("start episode")
    done = False
    env.reset()
    while not done:
        state, reward, done, info = env.step(env.action_space.sample())

i then changed https://github.com/jr-robotics/robo-gym-robot-servers/blob/master/ur_robot_server/scripts/joint_trajectory_command_handler.py#L16 this line to:

    if self.real_robot:
            self.jt_pub = rospy.Publisher('/scaled_pos_traj_controller/command', JointTrajectory, queue_size=10)
           # self.jt_pub = rospy.Publisher('/pos_traj_controller/command', JointTrajectory, queue_size=10)

As someone in an older post suggested that this might be the issue: https://github.com/jr-robotics/robo-gym/issues/70#issuecomment-1293897741

But now im getting this Error:

error2

 /bin/python3 /home/moga/Desktop/start.py
/home/moga/.local/lib/python3.8/site-packages/gym/spaces/box.py:127: UserWarning: WARN: Box bound precision lowered by casting to float32
  logger.warn(f"Box bound precision lowered by casting to {self.dtype}")
start episode
/home/moga/.local/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:174: UserWarning: WARN: Future gym versions will require that `Env.reset` can be passed a `seed` instead of using `Env.seed` for resetting the environment random number generator.
  logger.warn(
/home/moga/.local/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:187: UserWarning: WARN: Future gym versions will require that `Env.reset` can be passed `options` to allow the environment initialisation to be passed additional information.
  logger.warn(
Error occurred while calling the reset function. Restarting Robot server ...
Traceback (most recent call last):
  File "/home/moga/Desktop/robo-gym/robo_gym/wrappers/exception_handling.py", line 19, in reset
    return self.env.reset(**kwargs)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/wrappers/order_enforcing.py", line 42, in reset
    return self.env.reset(**kwargs)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/wrappers/env_checker.py", line 45, in reset
    return env_reset_passive_checker(self.env, **kwargs)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/utils/passive_env_checker.py", line 192, in env_reset_passive_checker
    result = env.reset(**kwargs)
  File "/home/moga/Desktop/robo-gym/robo_gym/envs/ur/ur_ee_positioning.py", line 236, in reset
    if not self.client.set_state_msg(state_msg):
  File "/home/moga/.local/lib/python3.8/site-packages/robo_gym_server_modules/robot_server/client.py", line 17, in set_state_msg
    msg = self.robot_server_stub.SetState(state_msg, timeout = 60)
  File "/home/moga/.local/lib/python3.8/site-packages/grpc/_channel.py", line 1030, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/moga/.local/lib/python3.8/site-packages/grpc/_channel.py", line 910, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.DEADLINE_EXCEEDED
        details = "Deadline Exceeded"
        debug_error_string = "UNKNOWN:Deadline Exceeded {created_time:"2023-03-31T17:39:31.690481676+02:00", grpc_status:4}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/moga/Desktop/start.py", line 13, in <module>
    env.reset()
  File "/home/moga/Desktop/robo-gym/robo_gym/wrappers/exception_handling.py", line 22, in reset
    self.env.restart_sim()
  File "/home/moga/.local/lib/python3.8/site-packages/gym/core.py", line 241, in __getattr__
    return getattr(self.env, name)
  File "/home/moga/.local/lib/python3.8/site-packages/gym/core.py", line 241, in __getattr__
    return getattr(self.env, name)
AttributeError: 'EndEffectorPositioningURRob' object has no attribute 'restart_sim'

i even see that the rostopic is publishing there ist just nothing happening

rostopic echo /scaled_pos_traj_controller/command
header: 
  seq: 1927
  stamp: 
    secs: 0
    nsecs:         0
  frame_id: ''
joint_names: 
  - elbow_joint
  - shoulder_lift_joint
  - shoulder_pan_joint
  - wrist_1_joint
  - wrist_2_joint
  - wrist_3_joint
points: 
  - 
    positions: [1.5, -2.5, 0.0, 0.0, -1.399999976158142, 0.0]
    velocities: []
    accelerations: []
    effort: []
    time_from_start: 
      secs: 2
      nsecs:    688332
---
header: 
  seq: 1928
  stamp: 
    secs: 0
    nsecs:         0
  frame_id: ''
joint_names: 
  - elbow_joint
  - shoulder_lift_joint
  - shoulder_pan_joint
  - wrist_1_joint
  - wrist_2_joint
  - wrist_3_joint
points: 
  - 
    positions: [1.5, -2.5, 0.0, 0.0, -1.399999976158142, 0.0]
    velocities: []
    accelerations: []
    effort: []
    time_from_start: 
      secs: 2
jr-b-reiterer commented 8 months ago

Regarding your UPDATE: