Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full robot state while moving #44

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Toni-SM
Copy link

@Toni-SM Toni-SM commented Sep 19, 2022

This pull request allows getting the robot state (for all motion types) when the robot is already in motion. It is a solution for the issue #32

The modified API is fully compatible with the current original version since it only adds one optional parameter (set by default to the behavior of the original API) to the existing methods. In addition, it exposes the current_joint_positions method and the InvalidOperationException exception.


API call

The following snippet shows the recommended way to call the API (See Robot State section in README for more details)

robot = Robot("172.16.0.2")

# Get the current state handling the read exception when the robot is in motion
try:
    robot_state = robot.get_state(read_once=True)
except frankx.InvalidOperationException:
    robot_state = robot.get_state(read_once=False)

# Get the current pose handling the read exception when the robot is in motion
try:
    pose = robot.current_pose(read_once=True)
except frankx.InvalidOperationException:
    pose = robot.current_pose(read_once=False)

# Get the current joint positions handling the read exception when the robot is in motion
try:
    joint_positions = robot.current_joint_positions(read_once=True)
except frankx.InvalidOperationException:
    joint_positions = robot.current_joint_positions(read_once=False)

Compiled files

The following are the compiled files, for different versions of Python, to support the use of the proposed modification without the need to compile the library. Make sure the files are available in the active Python environment. Set the LD_LIBRARY_PATH to the folder that contains those files if you are experiencing the ImportError: libmovex.so: cannot open shared object file: No such file or directory exception, for example (export LD_LIBRARY_PATH=/home/user/frankx-lib)


Example

Visit the skrl (reinforcement learning library) documentation skrl - Real-world examples to see an example of application of the proposed modification applied to reinforcement learning, where it is necessary to read the state of the robot in motion to build the observation or compute the reward

reaching_franka.mp4

@Toni-SM Toni-SM mentioned this pull request Sep 19, 2022
@MiguelASTavares
Copy link

MiguelASTavares commented Nov 17, 2022

Hi @Toni-SM i pulled your version of the frankx, with the changes, since the capability to access the robot state is while on motion something very interesting for my application. After the pull, i compile the code and installed the frankx library using the pip install .. However, when I try to runit I get the following error

robot_state = robot.get_state(read_once=True)
TypeError: get_state(): incompatible function arguments. The following argument types are supported:
    1. (self: _frankx.Robot) -> _frankx.RobotState

Invoked with: <frankx.robot.Robot object at 0x7ff81d2cb720>; kwargs: read_once=True

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pk.py", line 8, in <module>
    except frankx.InvalidOperationException:
NameError: name 'frankx' is not defined

Is this something you have seen before and if soo can you please tell me what im doing wrong?

A big thanks in advance.

Miguel Tavares.

@Toni-SM
Copy link
Author

Toni-SM commented Nov 17, 2022

Hi @MiguelASTavares

Make sure you are compiling the robot-state branch and not the main branch. The robot-state branch has the modified code for getting the robot state while moving and the modified API, for example:

.def("get_state", &Robot::get_state, "read_once"_a = true) in https://github.com/Toni-SM/frankx/blob/5a15f5b1937cb30228b6431823a2faa6f0de170f/src/frankx/python.cpp#L299

By the way, are you able to use the compiled files provided above?

@MiguelASTavares
Copy link

Hi, @Toni-SM I am running the robot-state branch. I can run the code now but the exception raised in the try continues to give me an error saying that ```
except frankx.InvalidOperationException:
NameError: name 'frankx' is not defined

And the problem of not allowing two controls continues. I didn't try the compile files could that be a better way to use this version? 

Thanks once again,
Miguel Tavares.  

@Toni-SM
Copy link
Author

Toni-SM commented Nov 18, 2022

Hi @MiguelASTavares

Are you importing frankx?

import frankx

And, the compiled files provided above are just a compilation of the branch...

@MiguelASTavares
Copy link

Hi @Toni-SM, I was missing the import, but now it's working. Can you give an explanation of what you did in order for this to work?

@Toni-SM
Copy link
Author

Toni-SM commented Nov 19, 2022

Hi @MiguelASTavares

This pull request just stores the current RobotState on each motion update and modifies the API to return the RobotState when the original methods are called with the read_once set to False.

Since this update is only performed when the robot is in motion, it is necessary to invoke the API as follows to ensure that the state of the robot is obtained when it is stopped. Otherwise, when it is stopped (and read_once=False), it would be returning the last updated state during the movement.

# Get the current state handling the read exception when the robot is in motion
try:
    robot_state = robot.get_state(read_once=True)
except frankx.InvalidOperationException:
    robot_state = robot.get_state(read_once=False)

@bwunaver
Copy link

Hi,

Thanks for creating this feature. The links of the submodules don't work. Could you please fix the submodules?

So I tried to git clone the original frankx and added your modification manually. But, the frankx library used remains the original one and for some reason, pybind does not seem to work. The c++ function get_state(read_once) is well created, but not the python one. Do you know potentially what is going wrong?

@Toni-SM
Copy link
Author

Toni-SM commented Mar 17, 2023

Hi @bwunaver

Can you please check that all changes defined in this pull request are for all related files?

@cidxb
Copy link

cidxb commented Apr 16, 2024

Any progress on this merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants