JeanElsner / panda-py

Python bindings for real-time control of Franka Emika robots.
https://jeanelsner.github.io/panda-py/
Apache License 2.0
77 stars 14 forks source link

Recording positions #9

Open colormotor opened 10 months ago

colormotor commented 10 months ago

Hi, first of all thanks for the work! I want to record the robot pose while "teaching", is there a suggested way or examples on how to do this with panda-py? I currenly am getting the the pose with panda.get_robot().read_once().O_T_EE

JeanElsner commented 10 months ago

Hi there! There is a teaching mode that can be activated by calling panda.teaching_mode(True). This will basically only run gravity compensation and allows you to move the robot freely, similarly to the built-in guiding mode. There are also short-hands to read the joint positions or pose, i.e. panda.q and panda.get_pose(). The later will directly return a 4 by 4 numpy array representing the end-effector pose. However, all the short-hands as well as panda.get_state()are only updated while controllers, motion generators or teaching mode is active. By calling read_once directly, the current state will be retrieved, even without an active controller.

I added a simple example to show how to simply read positions and record a trajectory and play them back. The example is in joint space but the same principle applies to Cartesian poses.

colormotor commented 10 months ago

That's great, many thanks!

xzhuzhu commented 10 months ago

Thanks for your great work! Now my robot is holding a extra load, how can I compensate the gravity of the load when doing teaching? Then when I am doing the impedance control, how can I change the impedance?

JeanElsner commented 10 months ago

You can set the load by calling Panda.get_robot().set_load(). This function uses the libfranka interface to set the end-effector load, i.e. mass, COM and inertia matrix. This is applied while running all controllers - including teaching mode and impedance control. Impedance for the CartesianImpedance controller can be set in the constructor or by calling CartesianImpedance.set_impedance(). However, if properly configured, you shouldn't need to adapt the impedance to compensate the load.

xzhuzhu commented 10 months ago

It works, thanks so much~

JKBehrens commented 9 months ago

Hi @JeanElsner,

thanks for the great work!

robot = panda_py.Panda(hostname)
robot.read_once()

I get

INFO:panda:Connected to robot (192.168.88.140).
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[75], line 2
      1 robot = panda_py.Panda(hostname)
----> 2 robot.read_once()

AttributeError: 'panda_py._core.Panda' object has no attribute 'read_once'

For the gripper, read_once works as expected.

I installed panda_py via pip.

Thank you for a hint how to call read_once() to get a current robot state.

Best, Jan

JKBehrens commented 9 months ago

I found my mistake: It should be:

robot = panda_py.Panda(hostname)
state = robot.get_robot().read_once()
colormotor commented 9 months ago

Hi, regarding my first question, while panda.teaching_mode(True) works great, it can be useful to take advantage of the guiding mode settings in the desk programming mode and then use read_once() to retrieve the current robot configuration. While I can set guiding modes programmatically through the robot interface and set execution vs. programming mode in the Desk UI , are you aware if it possible to switch between these modes using the Desk object?