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

How to consider impedance control and position control at the same time? #12

Closed elenacliu closed 8 months ago

elenacliu commented 9 months ago

I'm conducting some grasping experiments where the gripper may contact the desk a little. But I've noticed that in the grasping process, after the gripper closed, the program just stuck and finally aborted (core dumped).

my code is like:

self.panda.move_to_joint_position(pre_grasp_joints, speed_factor=self.move_speed)
time.sleep(0.03)

self.panda.move_to_joint_position(grasp_joints, speed_factor=self.move_speed)
self.gripper.move(width=0.0, speed=self.gripper_speed)
time.sleep(0.03)

self.panda.move_to_joint_position(after_grasp_joints, speed_factor=self.move_speed)
self.gripper.move(width=self.max_gripper_width, speed=self.gripper_speed)
time.sleep(0.03)

here is the output:

....(previous ignored)
INFO - 2023-11-08 22:57:14,710 - grasp_panda - Stopping active controller (Trajectory).
INFO - 2023-11-08 22:57:14,712 - grasp_panda - Initializing motion generation (moveToJointPosition).
INFO - 2023-11-08 22:57:14,724 - grasp_panda - Computed joint trajectory: 1 waypoint, duration 5.72 seconds.
INFO - 2023-11-08 22:57:14,724 - grasp_panda - Starting new controller (Trajectory).
INFO - 2023-11-08 22:57:20,850 - grasp_panda - Stopping active controller (Trajectory).
INFO - 2023-11-08 22:57:20,853 - grasp_panda - Initializing motion generation (moveToJointPosition).
INFO - 2023-11-08 22:57:20,860 - grasp_panda - Computed joint trajectory: 1 waypoint, duration 2.17 seconds.
INFO - 2023-11-08 22:57:20,861 - grasp_panda - Starting new controller (Trajectory).
  File "grasp_panda.py", line 136, in _execute_pick_and_place
    self.gripper.move(width=0.0, speed=self.gripper_speed)
RuntimeError: libfranka gripper: Command failed!
INFO - 2023-11-08 22:59:13,746 - core - signal_shutdown [atexit]
Aborted (core dumped)
elenacliu commented 9 months ago

I also used another package (named frankapy and franka-interface), its goto_pose function will consider impedance as default. But there might be bugs in that repository because the trajectory it planned always met joint limits in the way. So I refer to your repo and the trajectory is very impressive with no similar "joint limit" status.

Besides, how can we add impedance control into position control?

elenacliu commented 9 months ago

Sorry to bother, I found I should use gripper.grasp() function to grasp something, instead of move(width=0.0). Now it will not jump into core dump! But it failed to grasp the object.

JeanElsner commented 9 months ago

Sorry to bother, I found I should use gripper.grasp() function to grasp something, instead of move(width=0.0). Now it will not jump into core dump! But it failed to grasp the object.

The gripper functions are the same as in the libfranka class (cf. here). Regarding the gripper, panda-py is only a thin wrapper, all functionality comes from libfranka and unfortunately there is no way to extend the gripper's behavior. However, I may add more documentation and explanations about the gripper in this repository soon. You should be able to use both move and grasp without any exceptions. Maybe check that you use sensible parameters, i.e. the maximum speed is around 0.2m/s, width should be between 0m and 0.08m etc. The difference between moving and grasping is that the latter continues to apply a force after the call has returned. Both calls are blocking, but move expects that the fingers can freely move to the desired position and will block until it succeeded (this is just the behavior of the gripper). Additionally, the grasp function requires you to specify a desired force (this is fairly inaccurate and only works somewhat if the width of the grasp is known, i.e. a feed-forward term) as well as allowed deviation from the desired width. If the grasp is without the allowed deviation the grasp will be considered a failure and the gripper won't apply any force. If you're still having trouble try to run homing before using the gripper and maybe verify your gripper is set up properly by controlling it through Desk.

Finally, this could also be a bug, maybe you're using the Franka Research 3? I currently don't have access to the FR3 for testing.

elenacliu commented 9 months ago

Additionally, the grasp function requires you to specify a desired force (this is fairly inaccurate and only works somewhat if the width of the grasp is known, i.e. a feed-forward term) as well as allowed deviation from the desired width. If the grasp is without the allowed deviation the grasp will be considered a failure and the gripper won't apply any force.

Thank you! I didn't noticed that before. I checked my code and the default value of epsilon_inner and epsilon_outer, then I guess that is the problem.

My robot is FER and I found it failed to grasp because the after the gripper closed and seized the object, it suddenly let it go a little.