GithubHelp home page GithubHelp logo

rickstaa / ros-gazebo-gym Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 2.0 23.3 MB

Framework for integrating ROS and Gazebo with gymnasium, streamlining the development and training of RL algorithms in realistic robot simulations.

Home Page: https://rickstaa.dev/ros-gazebo-gym/

License: MIT License

CMake 1.79% Python 98.14% Shell 0.07%
ros gazebo reinforcement-learning framework robotics openai-gym gym gym-environments simulation panda

ros-gazebo-gym's Introduction

ROS Gazebo Gym

ROS Gazebo Gym ROS Test GitHub release (latest by date) Python 3 ROS version Contributions DOI

The ROS Gazebo Gym framework integrates ROS and Gazebo with gymnasium to facilitate the development and training of RL algorithms in realistic robot simulations. It comes equipped with several ready-to-use simulation environments, allowing for a diverse range of applications and experimentation. This framework provides a streamlined way to apply simulation-trained algorithms to actual robots, thereby enhancing their real-world applicability. Our goal with ROS Gazebo Gym is to establish a robust foundation for RL research in robotics, aiding in the advancement of practical, real-world robot control."

Installation and Usage

Please see the docs for installation and usage instructions.

Contributing

We use husky pre-commit hooks and github actions to enforce high code quality. Please check the CONTRIBUTING.md before contributing to this repository.

Note

We used husky instead of pre-commit, which is more commonly used with Python projects. This was done because only some tools we wanted to use were possible to integrate the Please feel free to open a PR if you want to switch to pre-commit if this is no longer the case.

ros-gazebo-gym's People

Contributors

albertoezquerro avatar dependabot[bot] avatar rdaneelolivav avatar rickstaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mdhillon1 dtbinh

ros-gazebo-gym's Issues

AttributeError: module 'numpy' has no attribute 'bool'.

Sometimes you will encounter the following error message when trying to use the ros-gazebo-gym package:

  import pandas._libs.testing as _testing                                                                                                                                                                  
Traceback (most recent call last):                                                                                                                                                                         
  File "<string>", line 1, in <module>                                                                                                                                                                     
  File "/home/ricks/venvs/ros-gazebo-gym/lib/python3.8/site-packages/pandas/__init__.py", line 180, in <module>                                                                                            
    import pandas.testing                                                                                                                                                                                  
  File "/home/ricks/venvs/ros-gazebo-gym/lib/python3.8/site-packages/pandas/testing.py", line 5, in <module>                                                                                               
    from pandas._testing import (                                                                                                                                                                          
  File "/home/ricks/venvs/ros-gazebo-gym/lib/python3.8/site-packages/pandas/_testing.py", line 24, in <module>                                                                                             
    import pandas._libs.testing as _testing                                                                                                                                                                
  File "pandas/_libs/testing.pyx", line 10, in init pandas._libs.testing                                                                                                                                   
  File "/usr/local/lib/python3.8/dist-packages/numpy/__init__.py", line 305, in __getattr__                                                                                                                
    raise AttributeError(__former_attrs__[attr])                                                                                                                                                           
AttributeError: module 'numpy' has no attribute 'bool'.                                                                                                                                                    
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the nu
mpy scalar type, use `np.bool_` here.                                                                                                                                                                      
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:                                                                                       
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

This error is caused by the installed [pandas](https://pandas.pydata.org/ and numpy libraries on your system to not be compatible (see https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations). This happens when you install numpy with pip while pandas is installed through the system repositories. You can solve this issue by uninstalling the numpy or installing pandas using pip (i.e. pip uninstall numpy or pip install pandas).

In end_effector_control, set_ee_pose() succeed for reach/push/slide, but fails for pick_and_place

Describe the bug

Thank you so much for contributing this awesome repo!!

However, I get one strange bug (only happen for pick_and_place but not for reach, push and slide), so I feel the bug is with the gripper: I set the control_type as "end_effector". Then I create the env and use env.step(ee_pos) where the ee_pos is exactly the current pose, but the robot doesn't move at all. Then I found that the set_ee_pose() function used return False and the message say "ee pose could not be set". Since the pose I use is exactly the current pose, so I cannot understand why the moveit cannot plan a path to reach it. I guess some collision might happen within the robot?

It's appreciated if you could help with this issue :)

Reproduction steps

  1. Create a new script "playground.py"
  2. Create the env and call the env.step like:
#!/usr/bin/env python3
"""A small example script that shows how to use the `ros_gazebo_gym`_ package to train a
(SAC) agent to solve a `Panda`_ environment using `Stable Baselines3`_.

.. _ros_gazebo_gym: https://github.com/rickstaa/ros-gazebo-gym
"""
import os
import re
import time

import gymnasium as gym
import numpy as np
import rospkg
import rospy
import torch
from ros_gazebo_gym.common.helpers import (
    list_2_human_text,
    to_pascal_case,
    to_snake_case,
)
from ros_gazebo_gym.core.helpers import ros_exit_gracefully
from ros_gazebo_gym.task_envs.task_envs_list import ENVS
from stable_baselines3 import SAC

import pickle

if __name__ == "__main__":  # noqa: C901
    rospy.init_node(
        "playground",
        anonymous=True,
    )

    # Retrieve input arguments.
    try:
        control_type = rospy.get_param("~control_type")
    except KeyError:
        control_type = "effort"
    try:
        env_type = rospy.get_param("~environment_type")
        print("Env Type: ", env_type)
    except KeyError:
        env_type = "slide"
    try:
        print(ENVS.keys())
        print(f"Panda{to_pascal_case(env_type)}")
        env_id = (
            "ros_gazebo_gym:"
            + [
                env
                for env in ENVS.keys()
                if env.startswith(f"Panda{to_pascal_case(env_type)}")
            ][0]
        )
        print("env_id: ", env_id)
    except IndexError:
        valid_env_ids = list(ENVS.keys())
        valid_env_cmds = [
            re.sub(r"panda_|(-v\d+)", "", to_snake_case(env)) for env in valid_env_ids
        ]
        valid_env_str = [
            f"'{cmd}' (ros_gazebo_gym:{id})"
            for cmd, id in zip(valid_env_cmds, valid_env_ids)
        ]
        rospy.logerr(
            f"Could not find 'environment_type' 'Panda{to_pascal_case(env_type)}'. "
            f"Valid options are: {list_2_human_text(valid_env_str)}."
        )
        ros_exit_gracefully(
            shutdown_message=f"Shutting down {rospy.get_name()}", exit_code=1
        )

    # Initialize the ros_gazebo_gym Panda environment.
    rospy.loginfo(f"Creating ros_gazebo_gym '{env_id}' gymnasium environment...")

    env = gym.make(
        env_id,
        control_type=control_type,
        action_space_dtype=np.float32,
        observation_space_dtype=np.float32,
    )

    # Initialize the logging system.
    rospack = rospkg.RosPack()
    pkg_path = rospack.get_path("ros_gazebo_gym_examples")
    outdir = os.path.join(pkg_path, "training_results")
    last_time_steps = np.ndarray(0)

    # Load parameters from the ROS param server.
    # NOTE: Parameters are stored in a yaml files inside the config directory and
    # loaded at runtime by the launch file.
    alpha = rospy.get_param("/ros_gazebo_gym_panda_example_params/alpha")
    gamma = rospy.get_param("/ros_gazebo_gym_panda_example_params/gamma")
    n_episodes = rospy.get_param("/ros_gazebo_gym_panda_example_params/n_episodes")
    n_steps = rospy.get_param("/ros_gazebo_gym_panda_example_params/n_steps")
    inference = rospy.get_param("/ros_gazebo_gym_panda_example_params/inference")
    inference_n_episodes = rospy.get_param(
        "/ros_gazebo_gym_panda_example_params/inference_n_episodes"
    )
    total_timesteps = n_steps * n_episodes

    obs, _ = env.reset()
    ee = env.get_ee_pose().pose
    obs, _, _, _, _ = env.step(np.array([ee.position.x, ee.position.y, ee.position.z,
                                         ee.orientation.x, ee.orientation.y, ee.orientation.z, ee.orientation.w,
                                         0.08, 5]))
  1. write a launch file to start this node with set control_type as "end_effector" and env as "pick_and_place":
<!--
This launch can be used to train a Soft Actor-Critic (SAC) algorithm on the panda task environments found in the
ros-gazebo-gym package. The training parameters can be set in the ros-gazebo-gym-examples/config/panda_example_training_params.yaml 

Control arguments:
    - control_type: The control type used for controlling the panda robot (Options: trajectory, position, effort, end_effector).
    - environment_type: The panda task environment (Options: Reach, PickAndPlace, Slide, Push).
-->
<launch>
    <!--Control arguments-->
    <!--    The control type used for controlling the panda robot (Options: trajectory, position, effort, end_effector)-->
    <arg name="control_type" default="end_effector"/>

    <!--The panda task environment.
        NOTE: Options: Reach, PickAndPlace, Slide, Push
        Valid options are: 'reach' (ros_gazebo_gym:PandaReach-v1), 'pick_and_place' (ros_gazebo_gym:PandaPickAndPlace-v1),
        'push' (ros_gazebo_gym:PandaPush-v1) & 'slide' (ros_gazebo_gym:PandaSlide-v1).
    -->
    <arg name="environment_type" default="pick_and_place"/>

    <!--Retrieve ros_gazebo_gym panda environment training parameters-->
    <include file="$(find ros_gazebo_gym_examples)/launch/load_panda_example_training_params.launch.xml"/>

    <!--Launch the training system-->
    <node pkg="ros_gazebo_gym_examples" name="playground" type="playground.py" output="screen">
        <param name="control_type" value="$(arg control_type)"/>
        <param name="environment_type" value="$(arg environment_type)"/>
    </node>
</launch>

  1. then you can see that the plan doesn't generate at all (you may need to print the output of set_ee_pose()).

Expected behaviour

moveit doesn't plan

Screenshots / Live demo link

No response

System information

  • OS: [e.g. Windows, Mac, Linux, iOS, android]
  • Version [e.g. 22]

Additional context

No response

Incorrect offset application when using `end-effector` control

Bug Report: Incorrect Offset Application in EE Commands and Configurations

Description

In our codebase, while the ee_frame_offset is accurately applied when retrieving the end-effector (EE) position, it appears not to be correctly handled in two specific scenarios:

  1. Sending EE Commands to MoveIt: When the control type is set to end-effector, the offset seems to be improperly applied, potentially leading to inaccuracies in the command execution.

  2. Retrieving EE Joint Configuration: The retrieval of the EE joint configuration might not correctly account for the offset.

Due to current time constraints, a detailed examination and fix of this issue are beyond my current capacity.

Important

This problem is also present when the hand is attached and control_type is set to end-effector because we automatically apply the offset of the panda_EE frame (see panda_env.py#L411-L432).

Reproduction Steps

  1. Set control_type to end-effector.
  2. Define an offset in the panda_reach.yaml configuration file.
  3. Insert a breakpoint at Line 960 in panda_env.py.
  4. Execute the start_panda_training.launch from the ros-gazebo-gym-examples package.
  5. Upon reaching the breakpoint, verify if the EE_frame aligns with the specified ee_position at the function's start.
  6. Anomalies have been noted, especially when the panda arm's rotation causes an inverse application of the offset.

Expected Behavior

The system should accurately apply the ee_frame_offset in all scenarios, ensuring that the end-effector's position and orientation are correctly calculated relative to the specified offset, even when the control type is end-effector and during the retrieval of the EE joint configuration.

System Information

  • OS: Ubuntu 20.04
  • Version: v2.0.0

Additional Context

This issue is critical for ensuring accurate end-effector positioning and movement, particularly in precise manipulation tasks. Immediate attention to rectify these discrepancies is highly recommended.

Panda is_collision also considers collision in joint limits

The current is_collision property uses the /franka_state_controller/franka_states/cartesian_collision topic for judging if the robot is in collision with the world. However, this topic also considers the external torques exerted by the base when the controller is pushing the joints within their joint limits. If we only want to penalize the robot for colliding with the world or itself, we should implement a contact sensor (see http://gazebosim.org/tutorials?tut=contact_sensor&cat=sensors).

/joint_states return inaccurate joints information

Describe the bug

Hi all,

Thank you again for your contributions to the repo!! But I have one small issue while using it, could you help me with that?

In the Reach task, I try to use delta_joints as action space. However, after changing the action space, I found that the robot cannot move as I expect. Actually, I found that the joints information published via /joint_states is not accurate.

Reproduction steps

  1. In src/ros-gazebo-gym/src/ros_gazebo_gym/task_envs/panda/panda_reach.py, aside from those action/observation space modifications I made, the biggest change I made is in _set_action() function. I add several lines of code in the initial of the function:
    def _set_action(self, action):

        if self.robot_control_type == "position":
            crr_joints_pos = copy.deepcopy(np.array(self.joint_states.position)) 
            action = np.array(crr_joints_pos) + action.copy()


        # The following parts are the same
        # Throw error and shutdown if action space is not the right size.
        if not action.shape == self.action_space.shape:
            err_msg = (
                f"Shutting down '{rospy.get_name()}' since the shape of the supplied "
                f"action {action.shape} while the gymnasium action space has shape "
                f"{self.action_space.shape}."
            )
            ros_exit_gracefully(shutdown_msg=err_msg, exit_code=1)
        ......
        ......
        ......
  1. I collect some demonstrations and then do the demonstration replay. In my application, the state is the 7 joints of the robot and the actions are generated via s_{t+1} - s_{t}. However, I found that the robot cannot move as it did in the demonstration. But when I directly let the robot move to s_{t+1}, it works perfectly. The action (i.e., a_t = s_{t+1} - s_{t}) is accurate as well. Therefore, the issue must come from the s_t, which is the self.joint_states.position I use in the above code. I am not sure where is wrong, either the /joint_states is inaccurate, or there's some lag between using the self.joint_states.position and the real current joints.

The demonstration file is attached: demos.zip

Could you help me with this issue? Thank you so much!!

Expected behaviour

No response

Screenshots / Live demo link

No response

System information

  • Ubuntu 20

Additional context

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.