frankaemika / franka_ros

ROS integration for Franka research robots
https://frankaemika.github.io
Apache License 2.0
350 stars 307 forks source link

Gazebo model joints move by themselves #160

Open saalimperator opened 3 years ago

saalimperator commented 3 years ago

Hello!

I'm currently working with your Gazebo model to test my controller. To do this, I modified one of your example controllers so that all joints except the first one keep their current angle. The first one is waiting for input from my controller, which is applied directly to the joint using the ".setCommand(tau)" function.

Now for my problem: when I start Gazebo, it seems to maintain the initial state, but after a few seconds the first joint starts to move slightly counterclockwise without any input from me. Is this normal behavior of this joint when the input is set to zero? Or is there something wrong with the inertia, friction and damping of this joint. When I send some inputs to this joint, it starts to move, but it is not slowed down by friction or damping and just bounces back when it hits the joint limits.

Can you give me a hint where I am doing something wrong?

rickstaa commented 2 years ago

@saalimperator Thanks for creating this issue.

It might not be related to your problem but I also noticed this behaviour even when no controllers are loaded. In that case, one would expect the robot to just fall down and stay there. The behaviour that occurs is however very strange (See gif 1 below). The first time I saw this, I thought it was because of gravity compensation, but there is no code for this the franka_state_controller or franka_gripper controllers.

This behaviour is also present when using the force_example_controller roslaunch franka_gazebo panda.launch controller:=force_example_controller which does contain gravity compensation. Probably, since the PID gains start at 0.

https://github.com/frankaemika/franka_ros/blob/b9b60e8a8316593b6a82d3bfa48a5b89155f42a5/franka_example_controllers/src/force_example_controller.cpp#L115)

The other strange thing is that the path that the arm takes with not controllers looks the same every time the simulation is started.

strange_movement

It could be related to the unstable dynamics that is described in https://github.com/justagist/franka_panda_description/issues/5.

gollth commented 2 years ago

In that case, one would expect the robot to just fall down and stay there.

Not really. The franka_hw_sim plugin simulates the real robot in that it compensates the gravity of arm when you send zero (or no) commands from the controller.

https://github.com/frankaemika/franka_ros/blob/1922fc9d24e37b2a8226c522e736eaa9a65d66ca/franka_gazebo/src/franka_hw_sim.cpp#L310-L317

Imagine this on the real robot. When you have a ROS controller which sends zero torque, the robot won't fall to the ground either but behaves like in "free space" essentially. This is also what happens when no controller is running.

Why the robot is drifting is unclear to me, though. I suspect numerical instabilities somewhere between franka_hw_sim and Gazebo.

when I start Gazebo, it seems to maintain the initial state, but after a few seconds the first joint starts to move slightly counterclockwise without any input from me.

@saalimperator a possible solution would be to have the controller active at all times. So while you are waiting for input, generate commands in your controller that hold the robot at a defined configuration. This should stop the drifting

rickstaa commented 2 years ago

In that case, one would expect the robot to just fall down and stay there.

Not really. The franka_hw_sim plugin simulates the real robot in that it compensates the gravity of arm when you send zero (or no) commands from the controller.

https://github.com/frankaemika/franka_ros/blob/1922fc9d24e37b2a8226c522e736eaa9a65d66ca/franka_gazebo/src/franka_hw_sim.cpp#L310-L317

Imagine this on the real robot. When you have a ROS controller which sends zero torque, the robot won't fall to the ground either but behaves like in "free space" essentially. This is also what happens when no controller is running.

Why the robot is drifting is unclear to me, though. I suspect numerical instabilities somewhere between franka_hw_sim and Gazebo.

when I start Gazebo, it seems to maintain the initial state, but after a few seconds the first joint starts to move slightly counterclockwise without any input from me.

@saalimperator a possible solution would be to have the controller active at all times. So while you are waiting for input, generate commands in your controller that hold the robot at a defined configuration. This should stop the drifting

@gollth At the time of writing, I forgot to check the franka_hw_sim for any gravity compensation. Thanks for pointing me to the relevant code. In that case, numerical instabilities could indeed cause this drifting. I have seen the same behaviour in other simulated robots.

For now, in my experiments, I will use your workaround and try to send control commands to mitigate the drift.

saalimperator commented 2 years ago

@saalimperator a possible solution would be to have the controller active at all times. So while you are waiting for input, generate commands in your controller that hold the robot at a defined configuration. This should stop the drifting

Thanks for the answer. I already expected something like this. Unfortunately, your proposed solution does not work for my project, because I am trying to determine the complete dynamics of the robot by means of an experiment. I have already found a better simulation environment for my case. Much success with the programming!

rickstaa commented 2 years ago

@saalimperator Just out of interest, may I ask which simulation environment you switched?

@gollth As this bug leads to strange behaviour, I was wondering if there are plans to fix this bug in the future?

saalimperator commented 2 years ago

Sorry I got that wrong, I didn't switch to another environment I switched the model. I am now working with an UR in Gazebo. But what I want to do is rather special. My programm communication looks like this: Matlab<->Simulink<->ROS<->Gazebo

rickstaa commented 2 years ago

@saalimperator Thanks for your response! Ah, I see colleagues of my have the same communication scheme.

Since the issue you described above still exists in the franka_gazebo package, maybe let's re-open it for now? In this way, it can serve as a bug report.

rickstaa commented 2 years ago

@gollth I managed to improve the behaviour by passing the gravity vector from the Gazebo simulator to the gravity compensation function. See #177.

After applying this pull request, the behaviour becomes more stable, but the robot still drifts a bit. I, however, could not find anything wrong with the current implementation. Do you maybe know other factors that can cause this drift?

Things I checked

https://github.com/frankaemika/franka_ros/blob/1922fc9d24e37b2a8226c522e736eaa9a65d66ca/franka_description/robots/panda_arm.xacro#L102

Other causes

rickstaa commented 2 years ago

@gollth Are there any updates on this?

I tried using your suggestion, but for my use case, sending control commands at every time step are not optional. I'm training a RL algorithm to try to control the robot arm. When gravity control is not working, the task becomes a lot harder, since it needs to be able to send control commands and thus do inference at a high frequency.

gollth commented 2 years ago

I'm currently investigating the issue

rickstaa commented 2 years ago

Great! I'm curious about what causes the drift that is still there. Based on the gazebo gravity compensation tutorial I think this drift should not be there. πŸ€”

gollth commented 2 years ago

Okay I think I have an idea where the problem comes from. It's part of a systematic error in the current calculation of the efforts coming from Gazebo. It's not only related to joints moving on their own without controller, but will affect any controller!

Let me try to explain what I think is going on:

Hypothesis

There is a bug in the way Gazebo calculates torques if the joint origin is rotated. The critical function is gazebo::physics::ODEJoint::GetForceTorque()

Bug Reproduction

Nominal Case

To see more clearly what is going on, let's create a simplified URDF containing only equally long sticks (length 10cm) with equal masses (5kg), where joints have zero rotation (i.e. <origin rpy="0 0 0" />) and bring the robot in the following configuration:

nominal

Let's focus on joint6 individually. We would expect a (negative) torque around joint6's Y axis because of gravity of link 6 and 7. If we print some values from during the writeSim() step, we see this confirmed:

Quantity Value Source
Effort acting on joint -0.750765 body2Torque.dot(joint->axis)
KDL Gravity Term 0.750765 model->gravity(q)
Torque calculated by Gazebo [-0.000793, -0.750765, -0.225921] GetForceTorque(0).body2Torque
Joint Axis in World frame [0.000000, 1.000000, 0.000000] joint->GetGlobalAxis()
Joint Axis in Local frame [0.000000, 1.000000, 0.000000] joint->GetLocalAxis()
Joint Axis defined in URDF [0, 1, 0] joint->axis_

As expected Gazebo measures a torque around the Y-axis of the joint, which is the degree of freedom, and some stray torques in other directions. The magnitue also seems to match. We have the torque from link6 (5kg Γ— 0.05m β‰ˆ 0.25Nm) plus the torque from link7 (5kg Γ— 0.1m β‰ˆ 0.5Nm). This matches the torque which KDL calculates for its gravity term.

Bugged Case

Now let's do the same thing, but rotate the joint's origin by 90 degrees, i.e. <origin rpy="${pi/2} 0 0" />. Bringing the robot in a similar configuration should now make it experience (negative) torque, this time only coming from the weight of link7 alone, since joint6 is now rotating around Z.

rotated

Again we look at the interessting values:

Quantity Value Source
Effort acting on joint -0.507839 body2Torque.dot(joint->axis)
KDL Gravity Term 0.250255 model->gravity(q)
Torque calculated by Gazebo [-0.000254, -0.507839, 0.000003] GetForceTorque(0).body2Torque
Joint Axis in World frame [0.000000, -1.000000, 0.000000] joint->GetGlobalAxis()
Joint Axis in Local frame [0.000000, -1.000000, 0.000000] joint->GetLocalAxis()
Joint Axis defined in URDF [0, 1, 0] joint->axis_

Here something strange is happening! KDL correctly calculates that the gravity term acting on the joint should only come from link7 (5kg Γ— 0.05m β‰ˆ 0.25Nm). But the result of GetForceTorque() yields a different result namely 0.5Nm. It seems that this is the result of the torque before rotation? Also the signs don't match.

Panda URDF

For the original Panda URDF this get's of course more complicated. When we plot the difference between the gravity term of KDL and the torque measured by Gazebo over time we see that this is really a systematic error and not (only) related to numerical noise as initially assumed:

error

Solutions

  1. Create a bug report in osrf/gazebo, however there are 1.4k other issues already waiting...
  2. Transform meshes/frames/inertias/axis such that the joint in the URDF do not contain any rotation.
  3. Hope anybody has an idea how to correctly transform the result of GetForceTorque(). Would appreciate any further ideas or insights πŸ˜•
gavanderhoorn commented 2 years ago
  1. Create a bug report in osrf/gazebo, however there are 1.4k other issues already waiting...

I would suggest to always do this, if you believe there is no other bug report already open about this.

The osrf/gazebo issue tracker is sort-of also used as a (public) todo-list, so don't let that high nr of open issues dissuade you from reporting something you believe is wrong.

Getting this fixed -- provided the analysis is correct -- would be tremendously valuable.


Edit: what would be good though perhaps would be to check whether Ignition has this same problem.

As Ignition has developer focus, finding the same problem there would probably make it easier to dedicate engineering resources to fix it, and back-porting it to Gazebo should then not be too difficult.


Edit 2:

Transform meshes/frames/inertias/axis such that the joint in the URDF do not contain any rotation.

no, that would be a work-around. Not a solution.

And would also not be very nice to those other 1000s of users who cannot do this (with their models).

rickstaa commented 2 years ago

@gollth Thanks a lot for finding the root cause of this issue and for creating the steps to reproduce it. Can you maybe push a small example repo to GitHub with the files you used to debug this problem? This will save me time when repeating the steps you describe above.

I agree with @gavanderhoorn this problem is likely affecting multiple repositories and users and should be fixed on osrf/gazebo. I think @gavanderhoorn's suggestion to check if the problem exists in ignition would be an excellent first step. If it does, we can create an issue there and backport the solution. If it does not, we can check what ignition does differently.

I will try to reproduce your example and then check if I can find more information about what causes the issue inside the gazebo/ignition code.


Edit1: I will first fix https://github.com/frankaemika/franka_ros/pull/177

gollth commented 2 years ago

Hey @rickstaa, thanks for taking a look. You can find the Stick URDF and the prints in this commit. Also look at its commit message to see how to reproduce the above described behavior.

rickstaa commented 2 years ago

@gollth I will start my investigation of this issue. I will keep this comment as a notepad.

TODOS

Reproduce the bug in gazebo

  1. Clone the gazebo-torque-calculation-bug repository using the --recursive. flag.
  2. Install the ROS dependencies.
  3. Build the catkin workspace.
  4. Start the example launch file using roslaunch gazebo_torque_calculation_bug stick.launch load_two_sticks:=true
  5. Check the plot to see that the torque of stick 2 is incorrect.

I can not reproduce the bug in the Gazebo v11 simulator.

Check if the bug is present in the ignition simulator

I do not see the bug in the Ignition v6.0 simulator

Possibly related issues

rickstaa commented 2 years ago

@gollth quick question. I think

$(calc 'deg2rad(90)')

is a syntax that is specific to your setup? I think calc is referring to the calc-common package but I could not find the deg2rad function. I used hardcoded values for now but I think these methods are very useful when having to deal with non 0/30/45/60/90 degree angles.

rickstaa commented 2 years ago

@gollth Based on your commit, I created a minimal example repository (i.e. no dependency on franka_ros) we can use in our Gazebo issue. This repository can be found here. I will make sure an RQT plot displays the torque, the joints can be controlled through a GUI, and some information is printed to the cmd line. Further, I will also add an Ignition launch file to this repo. I will keep you posted.

gollth commented 2 years ago

@gollth quick question. I think

$(calc 'deg2rad(90)')

is a syntax that is specific to your setup? I think calc is referring to the calc-common package but I could not find the deg2rad function. I used hardcoded values for now but I think these methods are very useful when having to deal with non 0/30/45/60/90 degree angles.

Hi @rickstaa,

thanks for looking into the issue. No calc is way dirtier than that, and comes from my local setup:

calc () {
  expression=$@ 
  python -c "from numpy import *; print($expression)"
}

Feel free to use whatever else you find suitable

rickstaa commented 2 years ago

Ha nice little trick! I mostly write bash scripts but this is a lot faster and versatile.

rickstaa commented 2 years ago

@gollth I investigated your issue, but I'm not able to reproduce it using your steps provided in https://github.com/frankaemika/franka_ros/issues/160#issuecomment-961780423. First, it looks like the figure included in the Bugged Case does not correspond with the data shown in the table. In the figure, the local URDF axis is 0 0 1 where the table shows 0 1 0. Further, I cannot reproduce the error between the KDL GravComp and Total Effort using your example; I also do not see any problems using my example.

Your example

I used a modified version of your example that I included as a submodule in my example repository. The franka_ros submodule that is in there includes your commit. The only thing I did was to add a rotated launch file argument to make it easier to inspect both cases (see c8b153b14dfd27ff513289bdf2f916e343ce66c3) and published the debug info to topics (see 01c8011a2ddd9c402a76c21e31e77b216a4d4037). But the error you described above also doesn't show up on my system when I revert these commits and test your original example.

Results

Nominal case

roslaunch franka_gazebo panda.launch \
  use_gripper:=false \
  headless:=false \
  paused:=true \
  rotated:=false \
  initial_joint_positions:="-J panda_joint6 $(calc 'deg2rad(-90)')"

image

initial result

panda_joint6: Error:                 0.750765
panda_joint6: Total Effort:          0.000000
panda_joint6: KDL GravComp:          0.750765
panda_joint6: KDL GravComp flipped:  -0.750765
panda_joint6: Gazebo body2Torque:   [0.000000, 0.000000, 0.000000]
panda_joint6: Desired joint command: 0.000000
panda_joint6: Joint command:         0.750765
panda_joint6: Global Axis: [0.000000, 1.000000, 0.000000]
panda_joint6: Local Axis:  [0.000000, 1.000000, 0.000000]
panda_joint6: URDF Axis:   [0, 1, 0]
panda_joint6: Joint velocity:        0.000000

after one step

panda_joint6: Error:                 0.000000
panda_joint6: Total Effort:          -0.750765
panda_joint6: KDL GravComp:          0.750765
panda_joint6: KDL GravComp flipped:  -0.750765
panda_joint6: Gazebo body2Torque:   [-0.000793, -0.750765, -0.225921]
panda_joint6: Desired joint command: 0.000000
panda_joint6: Joint command:         0.750765
panda_joint6: Global Axis: [0.000000, 1.000000, 0.000000]
panda_joint6: Local Axis:  [0.000000, 1.000000, 0.000000]
panda_joint6: URDF Axis:   [0, 1, 0]
panda_joint6: Joint velocity:        0.000277

All looks correct to me:

Bugged case

roslaunch franka_gazebo panda.launch \
  use_gripper:=false \
  headless:=false \
  paused:=true \
  rotated:=true \
  initial_joint_positions:="-J panda_joint6 $(calc 'deg2rad(90)')"

image

initial result

panda_joint6: Error:                 0.250255
panda_joint6: Total Effort:          0.000000
panda_joint6: KDL GravComp:          0.250255
panda_joint6: KDL GravComp flipped:  -0.250255
panda_joint6: Gazebo body2Torque:   [0.000000, 0.000000, 0.000000]
panda_joint6: Desired joint command: 0.000000
panda_joint6: Joint command:         0.250255
panda_joint6: Global Axis: [-0.000000, -1.000000, -0.000004]
panda_joint6: Local Axis:  [0.000000, 0.000000, 1.000000]
panda_joint6: URDF Axis:   [0, 0, 1]
panda_joint6: Joint velocity:        0.000000

after two steps

panda_joint6: Error:                 0.000000
panda_joint6: Total Effort:          -0.250255
panda_joint6: KDL GravComp:          0.250255
panda_joint6: KDL GravComp flipped:  -0.250255
panda_joint6: Gazebo body2Torque:   [-0.000317, -0.780290, -0.250255]
panda_joint6: Desired joint command: 0.000000
panda_joint6: Joint command:         0.250255
panda_joint6: Global Axis: [0.000000, -1.000000, -0.000004]
panda_joint6: Local Axis:  [0.000000, 0.000000, 1.000000]
panda_joint6: URDF Axis:   [0, 0, 1]
panda_joint6: Joint velocity:        0.000022

It also looks correct to me:

How to use my example

You can find a guide on using my example in the README. To quickly start, run the following command after building the catkin workspace:

roslaunch gazebo_torque_calculation_bug stick.launch initial_joint_positions:="-J stick_joint1 $(calc 'deg2rad(-90)')"

or for the bugged case

roslaunch gazebo_torque_calculation_bug stick.launch rotated:=true initial_joint_positions:="-J stick_joint1 $(calc 'deg2rad(90)')"

In my example, I got the same results as your example. Maybe I misunderstood your example, or I overlooked something. I will investigate further.

rickstaa commented 2 years ago

@gollth The only two things that I have found so far from Gazebos side that could perturb your gravity compensation are:

image

control_error_delay

I also saw these effects in the Ignition simulator.

EDIT:

When we add gravity compensation the initial delay only exists for a one-time step since the compensation applies an effort in the first time step:

image

Therefore this should not have an effect. Also, the control delay becomes smaller when gravity compensation is enabled

control_delay

rickstaa commented 2 years ago

I also tried to migrate the example to the Ignition simulator see gazebo-torque-calculation-bug#ignition-gazebo. I, however, think that this requires a bit more work since the ros-simulation/gazebo_ros_pkgs is not ignition compatible. I could not find an Ignition equivalent in the ros_ign.

I think testing only the bug in the ignition simulator requires us to create a small sensor plugin since I saw no ignition topic that contained the joint effort. I will check if we can use the ForceTorque sensor that is contained in the ign-sensors package. The nominal and bugged configurations are now hardcoded into the stick_description xacro file since the ros_ign_gazebo/create.cpp method does not yet take joint angles. I further changed the revolute joint to a fixed joint so that we don't need to implement a control plugin.

As I have no experience with the ignition simulator, I am not sure the easiest way to test this bug. Maybe @gavanderhoorn has some suggestions. However, let's first find the proper steps to reproduce the bug in Gazebo.

gavanderhoorn commented 2 years ago

I'm not sure I completely understand what you're looking for, but perhaps ignitionrobotics/ign_ros2_control#1 helps?

rickstaa commented 2 years ago

@gavanderhoorn Thanks for your answer. I did not see that pull request; it will undoubtedly be helpful in the future!

For now, I ended up coding the configurations directly in the world file while using a rotated launch argument to switch between the nominal and bugged position. I then use the ignition-gazebo-forcetorque-system plugin to get the torque. I then use the ignition::gazebo::systems::JointPositionController plugin to control the joints through the Joint position control ignition GUI.

rickstaa commented 2 years ago

@gollth The ignition example can now also be found under the example repository. Use the following command to start the nominal case:

roslaunch gazebo_torque_calculation_bug stick_ignition.launch

To start the bugged case use:

roslaunch gazebo_torque_calculation_bug stick_ignition.launch rotated:=true

After you started the simulation you can check the joint force and torque by using the following command:

ign topic -e -n1 -t /stick_joint1/force_torque

In both options, you can control the stick joints using the Joint position controller GUI.

Results

The torques/forces below are taken from the child to the parent as expressed in the child frame.

Nominal case

image

force {
  x: -9.9999906227737618
  y: -1.0384421671310667e-18
  z: 0.012471274055568547
}
torque {
  x: -0.00031178185139543513
  y: -0.74999929510605634
  z: -0.24999976556444289
}

Bugged case

image

force {
  x: -9.9683132042998146
  y: 2.2186868122886389e-15
  z: -2.775557117473697e-16
}
torque {
  x: -1.5946189417214406e-16
  y: -0.74683136042998111
  z: -3.7261796105162911e-06
}

Current conclusion

It looks like the configurations you provided does not give any problems in the ignition simulator.

rickstaa commented 2 years ago

@gollth I did one last inspection, and it looks like, in my example, the torque and force calculations are working fine in both the Gazebo 11 and Ignition v6.0 simulators (see gif below). I will add a gravity compensator to the stick and check other things that might go wrong. We can reopen the Gazebo investigation if you find the configurations that caused the problems.

Nominal version

nominal_case

Bugged version

bugged_case_is_not_bugged

rickstaa commented 2 years ago

Gravity compensation investigation

Here I will add the results of my gravity compensation investigation. I will compare my long_stick.launch with the example provided by @gollth. While doing this I will check the following things.

Reproduce gravity compensation bug

Check my example

To test this out in my example, we can use the following commands:

roslaunch gazebo_torque_calculation_bug long_stick.launch initial_joint_positions:="-J stick_joint1 $(calc 'deg2rad(-90)')"

or for the bugged case:

roslaunch gazebo_torque_calculation_bug long_stick.launch rotated:=true initial_joint_positions:="-J stick_joint1 $(calc 'deg2rad(90)')"

Results

Nominal

see plots ![image](https://user-images.githubusercontent.com/17570430/144598777-565f3dc6-d16a-4fda-aedf-1a77d2548a48.png) ![image](https://user-images.githubusercontent.com/17570430/144598659-126a9247-039f-415a-8b6e-a019ad822295.png) ![image](https://user-images.githubusercontent.com/17570430/144598596-cc918629-90e6-493f-a515-026bbae422ed.png)

Bugged

see plots ![image](https://user-images.githubusercontent.com/17570430/144600161-bb044b82-4949-4064-9106-a58bc8810a70.png) ![image](https://user-images.githubusercontent.com/17570430/144600155-8ade5232-62df-4539-a6f9-6b3b96926afe.png) ![image](https://user-images.githubusercontent.com/17570430/144600137-43e720a3-771d-4910-af4c-9cd2414c9197.png)

There is a motion when a joint has non-zero velocity when the controller is enabled. This however is expected since the gravity compensator only compensates gravity.

Check Gollths example

To test it out in @gollth example, we can use the following commands:

roslaunch franka_gazebo panda.launch \
  use_gripper:=false \
  headless:=false \
  paused:=true \
  initial_joint_positions:="-J panda_joint6 $(calc 'deg2rad(-90)')"

or for the bugged case:

roslaunch franka_gazebo panda.launch \
  use_gripper:=false \
  headless:=false \
  paused:=true \
  rotated:=true \
  initial_joint_positions:="-J panda_joint6 $(calc 'deg2rad(90)')"

Results

Nominal

see plots ![image](https://user-images.githubusercontent.com/17570430/144602300-4ece2b36-2a3d-4250-bf5a-4200c56caf08.png) ![image](https://user-images.githubusercontent.com/17570430/144602264-50df3b96-6679-48ac-882b-b3bdc22566f0.png) ![image](https://user-images.githubusercontent.com/17570430/144602233-56beb95e-b3ca-4b79-bcd6-b6fad8ba869d.png)

Bugged

Same behaviour the spikes below are because the joint reached its limit.

see plots ![image](https://user-images.githubusercontent.com/17570430/144603956-4dee9e07-3e0b-4b7b-8da2-1d649f4a5f82.png) ![image](https://user-images.githubusercontent.com/17570430/144603949-cbcd2088-4d70-429d-b6d3-a64f1677264d.png) ![image](https://user-images.githubusercontent.com/17570430/144603929-42de0a50-1767-4770-85b8-0573278c2059.png)

There is a motion when a joint has non-zero velocity when the controller is enabled. This however is expected since the gravity compensator only compensates gravity.

Conclusion

The gravity compensation you implemented contains a small bug that causes the joint to drift. I will continue my investigation into this bug in the next comment.

rickstaa commented 2 years ago

Gravity compensation bug investigation

This comment will show the results of my investigation into the bug that is found in the gravity compensation algorithm in your example:

Bug 1: Wrong gravity vector

The first obvious error has already been discussed above and was fixed when #177 was merged. In the old code, the hardcoded gravity vector was different from the actual gravity vector used by Gazebo. After applying #177 onto the example repository see check_gazebo_gravity_problem-fixed we got the following behaviour:

see figure ![image](https://user-images.githubusercontent.com/17570430/144605976-1cf81c26-032a-4cc3-9b27-8f4c8ce04c94.png) ![image](https://user-images.githubusercontent.com/17570430/144605998-1e4ab0bd-3be4-4117-80cd-7dd65b44393a.png) ![image](https://user-images.githubusercontent.com/17570430/144606014-d72f076b-5318-4d66-bd5f-6289d64f865a.png)

Conclusion

@gollth, @marcbone I concluded my investigation into the gravity compensator see https://github.com/frankaemika/franka_ros/issues/160#issuecomment-982682096, https://github.com/frankaemika/franka_ros/issues/160#issuecomment-982933376, https://github.com/frankaemika/franka_ros/issues/160#issuecomment-984520245 and https://github.com/frankaemika/franka_ros/issues/160#issuecomment-984604733.

In the end, I could not find any problems with the gravity controller other than the one that I already fixed in #177. I am therefore unsure why the panda robot is drifting when no controllers are enabled but it looks like the gravity compensator is working fine. I have the following hypothesis about why the robot might drift when no controllers are active:

https://github.com/frankaemika/franka_ros/blob/17ea46264f8f982d00d859abe5058d564f9ae3ce/franka_gazebo/src/franka_hw_sim.cpp#L325

rickstaa commented 2 years ago

Investigate panda simulation stability

Results

Let's check several parameters to see if the Gazebo simulator is stable. To test it out, go to the rickstaa/franka_ros/check_gazebo_start_velocity build the catkin workspace and start the simulation without the hand:

roslaunch franka_gazebo panda.launch use_gripper:=false paused:=true

Then take one time in the simulation before plotting the following plots:

rosrun rqt_plot rqt_plot /total_energy
rosrun rqt_plot rqt_plot /total_kinetic_energy
rosrun rqt_plot rqt_plot total_potential_energy
 rosrun rqt_plot rqt_plot /joint_states/velocity[0] /joint_states/velocity[1] /joint_states/velocity[2] /joint_states/velocity[3] /joint_states/velocity[4] /joint_states/velocity[5] /joint_states/velocity[6]
rosrun rqt_plot rqt_plot /panda_joint1/error /panda_joint2/error /panda_joint3/error /panda_joint4/error /panda_joint5/error /panda_joint6/error /panda_joint7/error
 rosrun rqt_plot rqt_plot /velocity_norm

Plots

see plots ![image](https://user-images.githubusercontent.com/17570430/144915771-06b2c1f6-2e13-481e-b5b8-c89e15073870.png) ![image](https://user-images.githubusercontent.com/17570430/144915810-7617b881-41f1-493e-9899-291122538c79.png) ![image](https://user-images.githubusercontent.com/17570430/144916106-46aeaa5c-1a4d-4f4c-b131-4c8771dfae7a.png) ![image](https://user-images.githubusercontent.com/17570430/144916088-f77546be-ae06-4599-a088-b70c65ef6d5a.png) ![image](https://user-images.githubusercontent.com/17570430/144915914-9263fc0e-9d00-4c73-b77c-fff1f51a2ea2.png) ![image](https://user-images.githubusercontent.com/17570430/144916060-5213e1f4-8ebc-4a31-9076-1afaf4dc28d9.png) ![image](https://user-images.githubusercontent.com/17570430/144915840-47985738-7a84-4b77-9b7d-7b1976306ffe.png)

Conclusion

Although the total energy calculation below is not 100% correct (i.e. I did not account for the work done by the gravity compensator and energy that is lost due to joint friction), it allows us to check if significant energy is added to the system. When inspecting the velocity norm plots, we see that the energy and norm velocity of the system is not increasing over time. We can therefore conclude that the system as a whole is stable. We further see that the error between the gravity compensator and the gravity component is close to zero except where the robot is in a collision, meaning that the compensator works. However, when zooming in on the velocities, we see that the starting velocities are non-zero. It looks like they are responsible for the robot movement, since the gravity compensator only compensates for gravity. The interaction between the different joints probably causes the observed complex movements. The strange thing, however, is that these velocities are increasing.

image

Try to remove start velocities using joint trajectory controller

This does not work since the controller is imperfect, meaning an initial joint velocity causes the same result as above.

Disable gravity compensation

When the gravity compensation is disabled, the robot falls to the ground and stays as expected. We can see that the drift is only there when we have the gravity compensation enabled.

Effect of the initial position

Changing the initial position of the panda robot does not remove the drift.

rickstaa commented 2 years ago

Migrate stick to panda

Let's slowly transfer the stick into the panda robot. I will do this on the https://github.com/rickstaa/gazebo-torque-calculation-bug/tree/migrate_stick_to_panda branch. Each commit will represent a migration step. The first change is found in 12e4a432e7cf3374d4d1d63288ccf4236b1e3d2b. We will use the stick_long.launch launch file to do so:

roslaunch gazebo_torque_calculation_bug stick_long.launch paused:=true

While doing so, let's take one step in the simulation and plot the following plots:

rosrun rqt_plot rqt_plot /stick/total_energy
rosrun rqt_plot rqt_plot /stick/total_kinetic_energy
rosrun rqt_plot rqt_plot /stick/total_potential_energy
rosrun rqt_plot rqt_plot /stick/joint_states/velocity[0] /stick/joint_states/velocity[1] /stick/joint_states/velocity[2] /stick/joint_states/velocity[3] /stick/joint_states/velocity[4] /stick/joint_states/velocity[5] /stick/joint_states/velocity[6]
rosrun rqt_plot rqt_plot /stick/gazebo_bug/stick_joint1/error /stick/gazebo_bug/stick_joint2/error /stick/gazebo_bug/stick_joint3/error /stick/gazebo_bug/stick_joint4/error /stick/gazebo_bug/stick_joint5/error /stick/gazebo_bug/stick_joint6/error /stick/gazebo_bug/stick_joint7/error

Same configuration

ODE engine

Let's modify the long_stick urdf and launch files such that the initial configuration is the same as the one used in the panda simulation.

Start configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/144920991-cf5b526b-6576-4627-8a07-d7f254f1d042.png)

End configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145005568-aa5be73f-76a6-457e-8646-1a7acf93324f.png)

plots

see plots ![image](https://user-images.githubusercontent.com/17570430/145005661-2d8cd0d7-c4d3-4a36-9509-0104a994efa1.png) ![image](https://user-images.githubusercontent.com/17570430/145005787-8c1c89d9-7b3c-4c47-9f70-ffc30b704742.png) ![image](https://user-images.githubusercontent.com/17570430/145006169-9f3c304f-70cf-4246-a55a-424e39157f6b.png) ![image](https://user-images.githubusercontent.com/17570430/145006273-979c2bae-9bc0-4240-b3c3-6f164b696ae2.png) ![image](https://user-images.githubusercontent.com/17570430/145006446-0aa4e6ed-b5d0-4eb4-bfdb-162443744bd9.png) ![image](https://user-images.githubusercontent.com/17570430/145006652-b5f31a14-1a82-4683-8659-2ee17f57fc8d.png)

conclusion

The calculated gravity and effort error is close to zero but not entirely zero. This means that the gravity compensation works but has a slight numerical instability. Further, there also appears to be a minimal initial joint velocity for all the joints. The strange thing is that these velocities increase over time. We can also see that there is a slight increase in the total_energy. Maybe this is caused by numerical instabilities in the gravity compensator or Gazebo simulator? The effect of this is most prominent in joint 5.

Nevertheless, as these velocities are small, they take a long time to create a significant configuration change and should not cause any problems in experiments. Of course, these effects go away when the joint damping is increased. I, however, think that increasing the joint damping to fix (instabilities) in the simulation is not wise if it is not kept comparable to the joint damping used on the real robot. @gollth can you please check whether the joint damping you currently use is comparable with the joint damping in the real robot.

Dart engine

Let's try to use the dart physics engine by setting the physics:=dart launch file argument. To do this checkout 89ab71507f76ed646e908d516522f7943892b681 and run the following command:

roslaunch gazebo_torque_calculation_bug stick_long.launch paused:=true physics:=dart

plots

see plot ![image](https://user-images.githubusercontent.com/17570430/145011117-f3926f3e-5cad-4779-8fa5-32c862823cee.png)

conclusion

Similar results to ode engine. The error is a bit bigger.

Same joint lengths/positions

Let's make the joint lengths and positions the same while keeping the old collision meshes, masses and inertias. This change is found in 7219024d0cce8f4f873d6a879e238668081321bf. We now have a rather strange robot, but let's look at it for testing sake.

start configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145011489-f9147fb5-247b-42b0-9511-2a176f57edcd.png)

end configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145014714-7d454762-e446-4da9-a817-291b7ab189a5.png)

plots

see plots ![image](https://user-images.githubusercontent.com/17570430/145014771-0302007c-b96e-4e1b-975e-b6e4871730ed.png) ![image](https://user-images.githubusercontent.com/17570430/145014895-747f8fc7-9b68-4b71-a2a0-abef72adf8df.png) ![image](https://user-images.githubusercontent.com/17570430/145014961-cd1e2110-0994-4e4e-80aa-0fbbc2ad1e80.png) ![image](https://user-images.githubusercontent.com/17570430/145015346-9610bca5-b1a6-4794-a281-8dc0c4663b9c.png) ![image](https://user-images.githubusercontent.com/17570430/145015489-9919cd52-256d-4cfd-957a-600544e1f6b3.png) ![image](https://user-images.githubusercontent.com/17570430/145015193-92eabe42-1249-4d76-93fd-686afaff59cb.png)

conclusion

Same meshes

start configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145016325-5468157a-d45d-405f-83b4-d13cbf3c2754.png)

end configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145020693-84cc275d-ad86-4c3d-bd05-4c6de2818de0.png)

plots

see plots ![image](https://user-images.githubusercontent.com/17570430/145020768-0713ae35-a537-40e3-a12e-a36971043234.png) ![image](https://user-images.githubusercontent.com/17570430/145020806-17cedee3-d04e-4707-8c96-4dc11e927503.png) ![image](https://user-images.githubusercontent.com/17570430/145020842-f32316ec-db14-494f-b1f0-135695c3f1d6.png) ![image](https://user-images.githubusercontent.com/17570430/145020909-b91aae25-8e70-47c3-97cd-bd32d6ade2af.png) ![image](https://user-images.githubusercontent.com/17570430/145020945-3a4e40ee-1258-4115-a569-2fae83c132e0.png) ![image](https://user-images.githubusercontent.com/17570430/145020989-6a699057-7d7b-4bd8-8db2-9a853d599347.png) ![image](https://user-images.githubusercontent.com/17570430/145021026-4afd598b-6064-4302-804d-f2b33d6be693.png) ![image](https://user-images.githubusercontent.com/17570430/145021064-ffdd7add-698a-4b11-a99b-94cf2aa9f679.png)

conclusion

It looks like adding the collision messes makes the velocity drift and gravity compensation error worse. The exciting thing is that it now also contains a lot of high-frequency signals. Could this be due to the interaction between the different collision meshes? Unfortunately, I think the drift we see after adding the meshes is not acceptable anymore for experiments. Some of the COMs are still outside the robot links so let's check if this drift improves when we adjust the mass positions.

Same mass position

start configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145026365-2b287fe6-0fa9-4c06-a38a-5853684417ad.png)

end configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145029364-35b330f9-97a4-408d-8360-9b3f6fff7f30.png)

plots

see plots ![image](https://user-images.githubusercontent.com/17570430/145029421-411af9e6-3308-4c86-acf8-35aca0648417.png) ![image](https://user-images.githubusercontent.com/17570430/145029454-961b1d78-7ade-4b6d-8804-eafb3c298c5f.png) ![image](https://user-images.githubusercontent.com/17570430/145029483-a59441d0-604e-4749-a4d3-3a1d3f49179d.png) ![image](https://user-images.githubusercontent.com/17570430/145029531-dcde01ca-a2e4-43a8-8c89-543a5e4b68ea.png) ![image](https://user-images.githubusercontent.com/17570430/145029574-41095953-9ef4-4901-b98e-33d967a196e6.png) ![image](https://user-images.githubusercontent.com/17570430/145029619-aaf1a386-0213-4c78-863a-218552ed4d05.png) ![image](https://user-images.githubusercontent.com/17570430/145029687-61d7e702-28ac-4cf2-a3b1-3229b3ea3dcd.png) ![image](https://user-images.githubusercontent.com/17570430/145029793-76e393d9-6d18-4803-a25c-3d33e60a7c4e.png)

conclusion

The results are similar to when we added the meshes.

Same mass

end configuration

see figure ![image](https://user-images.githubusercontent.com/17570430/145053130-ca543c42-ae8a-46f0-818b-6019ac55e502.png)

plots

see plots ![image](https://user-images.githubusercontent.com/17570430/145053217-8f2a21be-3ec5-4940-9f69-e2ac3f734ac5.png) ![image](https://user-images.githubusercontent.com/17570430/145053294-1a2bd5c6-8fa7-4588-8f48-026a445db886.png) ![image](https://user-images.githubusercontent.com/17570430/145054020-8d3852c3-c75b-4e69-8cb8-1c40a3c8ad86.png) ![image](https://user-images.githubusercontent.com/17570430/145054065-a371ead8-7bf3-4c2a-b52d-c61782a09847.png) ![image](https://user-images.githubusercontent.com/17570430/145054214-37c67426-d6a2-4b97-9c99-518e04e86e2d.png) ![image](https://user-images.githubusercontent.com/17570430/145054300-d4c407f8-0981-4d0b-bdbc-b929a98f5e6a.png) ![image](https://user-images.githubusercontent.com/17570430/145054375-2ed175a4-0969-491f-837f-82990dd0480d.png) ![image](https://user-images.githubusercontent.com/17570430/145056100-48ae39b2-6d1a-40c1-8b0e-7cd083f52a39.png)

conclusion

It looks like the velocity drift and gravity compensation error increased a bit while the initial velocity stayed the same. It, however, is tough to conclude since the differences are very small.

Same moment of inertia

The modified gazebo_ros_control/DefaultRobotHWSim does not seem to work with this configuration. The robot is very unstable now (see gif below):

unstable_behavoir

It looks like there is a very big error when the robot reaches a certain configuration.

Same joint properties

Same behaviour as the previous configuration, the robot is still very unstable after a certain configuration has been reached.

gollth commented 2 years ago

Hello @rickstaa,

first of all thanks a lot for your great efforts you put into investigation of this bug. I didn't have yet the time to retrace your whole steps but definitely will in the near future.

Quick comment I noticed right away: I think there is a difference between Gazebo 9 & Gazebo 11. I tried the example from your fork on my machine (Ubuntu 18.04) and got different results than you (I guess you run 20.04?) after a few time steps:

▏ WARNβ–• /gazebo ⟩ FrankaHWSim::writeSim() ⟩ L335 ⟫ panda_joint6: Error:                 0.250258
▏ WARNβ–• /gazebo ⟩ FrankaHWSim::writeSim() ⟩ L336 ⟫ panda_joint6: Total Effort:          0.000003
▏ WARNβ–• /gazebo ⟩ FrankaHWSim::writeSim() ⟩ L337 ⟫ panda_joint6: KDL GravComp:          0.250255
▏ WARNβ–• /gazebo ⟩ FrankaHWSim::writeSim() ⟩ L338 ⟫ panda_joint6: KDL GravComp flipped:  -0.250255

Notice the error is not zero. I was trying on ROS Noetic (20.04) and there I get similar values to those you posted above.

I cannot reproduce the error between the KDL GravComp and Total Effort using your example

That might also explain why you couldn't reproduce my bugged case. Could you verify that?

rickstaa commented 2 years ago

@gollth Thanks for working with me on this bug! I suspected a version difference to be the cause of the reproducibility problem. I, however, did not have time to verify this since my experiments are in Gazebo 11. That is handy information since we can probably back-port the fix from Gazebo 11 to Gazebo 9. I will verify this today so that we can open a Gazebo issue.

In the meantime, I found the leading case of the resulting movement observed in Gazebo 11. It looks like two things cause it.

I, however, am still performing some experiments before I can conclude. I will update https://github.com/frankaemika/franka_ros/issues/160#issuecomment-985620934 and let you know.

rickstaa commented 2 years ago

Investigate error blowup

Let's quickly investigate what goes wrong when we see the gravity compensation error explode. We investigate this using the fully migrated stick (see rickstaa/gazebo-torque-calculation-bug#29adee633458e29ee344f25b8690cb794d588acf).

Check the behaviour around the explosion

show plots ![image](https://user-images.githubusercontent.com/17570430/145179633-673c03b3-276a-4e5a-b3ed-86157ae2eabb.png) ![image](https://user-images.githubusercontent.com/17570430/145179662-3fd1c81e-e34c-4c55-8ba2-98d0d61bc504.png) ![image](https://user-images.githubusercontent.com/17570430/145179725-f0ab8ecc-cdff-46d2-81ce-0b56bee8bdab.png) ![image](https://user-images.githubusercontent.com/17570430/145179765-f8970bf1-58a3-4b2b-a3d6-b881e7c7c0d5.png) ![image](https://user-images.githubusercontent.com/17570430/145179785-67fd7e65-5231-40f4-9a8c-f0dbd8d6f7c0.png) Let's zoom in on the error a bit to see how fast the explosion goes: ![image](https://user-images.githubusercontent.com/17570430/145179940-4e5289a2-90ff-4fc5-85fe-29b64242fda6.png) ![image](https://user-images.githubusercontent.com/17570430/145180037-a99c08e1-7c44-4503-9c16-b4fadae2379c.png) ![image](https://user-images.githubusercontent.com/17570430/145183458-64f35f63-2086-47cc-9dbf-4bba049efbea.png) ![image](https://user-images.githubusercontent.com/17570430/145196429-dd624dee-f42d-49a8-b4cb-ce94dcf33d89.png) ### Check initial error/velocity Also, let's check the initial error and velocity: ![image](https://user-images.githubusercontent.com/17570430/145182368-ab6a19d5-7573-4f0f-8398-34352ed89746.png) ![image](https://user-images.githubusercontent.com/17570430/145182312-7f89cf0e-e1d3-4b65-aa63-aae713bb152f.png) ![image](https://user-images.githubusercontent.com/17570430/145197933-ca048d9f-3f9e-41b9-b8f6-d02b7a5899d7.png)

After some seconds:

show plots ![image](https://user-images.githubusercontent.com/17570430/145180299-78843e73-2a62-46bd-bee9-42e34325b5b1.png) ![image](https://user-images.githubusercontent.com/17570430/145180325-897b1d66-8373-4683-bd73-272758114398.png) ![image](https://user-images.githubusercontent.com/17570430/145180354-cae9f3b2-001f-4477-bc05-4882248cb106.png) ![image](https://user-images.githubusercontent.com/17570430/145180387-6e0ab032-01fd-40a5-8f58-ca65b796e169.png) ![image](https://user-images.githubusercontent.com/17570430/145180403-eec898ff-8c72-4861-8755-8dc0ee6433c2.png) ![image](https://user-images.githubusercontent.com/17570430/145180479-c562ee34-2e9b-4194-987f-2827cea6ad59.png)

Conclusion

First, we see that the initial velocities of the joints are more prominent than before we added the moments of inertia. Further, the initial error looks slightly smaller. Finally, we see that around 20 seconds, the explosion happens. We see that from 19.9 s, the gravity compensation torque begins to converge from the actual joint effort. For most of the joints, this error decreases again after some time. However, for joint 4, the gravity controller oscillates and does not converge to the actual effort again. Maybe because of some singularity that is reached in the KDL calculation or a bug in my code? One configuration in which the gravity component from orocos KDL is wrong is found at 20.634 s:

position: [1.0239263566109518, 0.5960596715412674, -1.269196156791847, -1.3912509739159447, 0.6797047110628416, 2.132753824903997, 1.1042482208897306]
roslaunch gazebo_torque_calculation_bug stick_long.launch paused:=true initial_joint_positions:="-J stick_joint1 1.0239263566109518 -J stick_joint2 0.5960596715412674 -J stick_joint3 -1.269196156791847 -J stick_joint4 -1.3912509739159447 -J stick_joint5 0.6797047110628416 -J stick_joint6 2.132753824903997 -J stick_joint7 1.1042482208897306"

Investigate bad configuration

Let's try to start from the bad configuration:

roslaunch gazebo_torque_calculation_bug stick_long.launch paused:=true initial_joint_positions:="-J stick_joint1 0.629052096614803 -J stick_joint2 1.7260168916830132 -J stick_joint3 -2.431480455925368 -J stick_joint4 -0.4789728572990013 -J stick_joint5 1.4027805093682248 -J stick_joint6 2.352817784556791 -J stick_joint7 1.1476455418911584"

From this configuration, the error on joint4 starts to increase and becomes eventually unstable (see figure below):

image

Conclusion

Most of the joints do have a significant gravity compensation error when the robot is at the following configuration:

position: [0.09654970403330143, 1.5832436223876893, 1.8650816451372636, -1.101766637453536, 2.7164232834515225, 1.198539552336471, 1.0820332807641506]

However, the strange thing is that the error explosion does not occur when we start from this configuration. I'm not sure what is going on, but I can think of several possible causes:

Investigate the effect of safety_controller

Let's check if disabling the safety controller removes the strange gravity compensation error explosion problem. This can be done using the safety_controller:=false launch file argument:

roslaunch gazebo_torque_calculation_bug stick_long.launch paused:=true initial_joint_positions:="-J stick_joint1 1.0239263566109518 -J stick_joint2 0.5960596715412674 -J stick_joint3 -1.269196156791847 -J stick_joint4 -1.3912509739159447 -J stick_joint5 0.6797047110628416 -J stick_joint6 2.132753824903997 -J stick_joint7 1.1042482208897306" safety_controller:=false
show plots ![image](https://user-images.githubusercontent.com/17570430/145257963-33622d4c-0db5-4577-9097-b45d40ee6573.png) ![image](https://user-images.githubusercontent.com/17570430/145257982-f57d5534-541d-44f2-8464-0b1b4f3c9ecf.png) ![image](https://user-images.githubusercontent.com/17570430/145258009-7e8696d9-43f0-4ea1-b90d-033b9191ffe8.png) ![image](https://user-images.githubusercontent.com/17570430/145258036-fe4c57dc-2f57-4546-9574-9482635dd4e9.png) ![image](https://user-images.githubusercontent.com/17570430/145258095-00d1ee27-4179-4e58-9558-e6c19f8df6f6.png) ![image](https://user-images.githubusercontent.com/17570430/145258141-4995966e-ff4c-4824-8641-6f79d3f4d580.png)

Conclusion

As the unstable behaviour goes away when we disable the safety_controller, it looks like the unstable behaviour is caused by the interaction between the safety_controller and the gravity compensation. This conclusion is strengthened since the strange behaviours go away when we disable the gravity compensation.

Check the behaviour at the hard joint limits

Let's also quickly check if the strange error spikes coincide with the times when the hard joint_limits are reached. This can be done using the plot_joint_positions_and_limits.launch launch file. This launch file plots the joint positions and the joint limits. When we do this, we get the following plots:

show plots ![image](https://user-images.githubusercontent.com/17570430/145268407-bf3b2ae1-c729-408c-9868-501a02e77466.png) ![image](https://user-images.githubusercontent.com/17570430/145268497-8afed52f-77d4-490c-b128-af54832a14f6.png) ![image](https://user-images.githubusercontent.com/17570430/145268539-8a2d2b0b-3079-4aa3-8b81-51f2ae96c14d.png) ![image](https://user-images.githubusercontent.com/17570430/145268600-930dd288-9e9f-4ce4-993f-87ca5d3722c0.png) ![image](https://user-images.githubusercontent.com/17570430/145268648-42eb20bc-2cea-4cf4-8bf3-57e6ba0fecb3.png) ![image](https://user-images.githubusercontent.com/17570430/145268687-1155ce9e-deb0-4a86-8ffc-9967cf140f47.png) ![image](https://user-images.githubusercontent.com/17570430/145268765-c27f5648-522a-4e0d-837c-af3cab773a86.png) ![image](https://user-images.githubusercontent.com/17570430/145268821-500d1273-27a9-4878-8870-c4418c34fb01.png) ![image](https://user-images.githubusercontent.com/17570430/145268889-2056551f-0266-4039-8897-adb0b595454f.png) ![image](https://user-images.githubusercontent.com/17570430/145268938-93698762-b05b-4280-be05-f4b67d44519a.png) ![image](https://user-images.githubusercontent.com/17570430/145269007-f7fef08b-486d-4c23-927f-eae3c14a5a74.png) ![image](https://user-images.githubusercontent.com/17570430/145269056-7b8967d8-8621-4373-870c-54c4f908dd99.png) ![image](https://user-images.githubusercontent.com/17570430/145269103-7dac4353-211a-4ea4-8d6e-a7a50488bd14.png) ![image](https://user-images.githubusercontent.com/17570430/145269240-1cdd69d1-a952-4110-95bb-f69f82239aea.png)

Conclusion

It looks indeed that the error spikes are because the hard joint limits are reached.

End conclusion

The error explosion that was seen in my previous investigation is caused by the interaction between the hard joint limits, the safety_controller and the gravity compensation. I, therefore, think the gravity compensation should account for the instances when the soft or hard joint limits are being reached.

rickstaa commented 2 years ago

Compare different physics engine

Let's quickly try to use a different physics engine while launching the panda simulation. I added 4c7d16536b86102f849ad9d94ff9c4455b543882 onto the develop branch to do this (see rickstaa/franka_ros/develop-gazebo-bug-test). This commit adds the physics argument to the panda.launch file. Let's also check what happens to the starting drift when the safety_controller is disabled. I added 96d769b31d3edc087faf11a040f2aaffdb85bc1d to provide a way to turn the safety_controller on and off.

ODE

see result **no gripper with the safety_controller** ```bash roslaunch franka_gazebo panda.launch use_gripper:=false physics:=ode ``` ![ode_no_gripper_with_safety](https://user-images.githubusercontent.com/17570430/145845340-84161cd1-e630-4a5c-9d16-91d18798c440.gif) **no gripper without the safety_controller** ```bash roslaunch franka_gazebo panda.launch use_gripper:=false physics:=ode safety_controller:=false ``` ![ode_no_gripper_without_safety](https://user-images.githubusercontent.com/17570430/145845351-c5ec4b47-a86a-4c67-9324-b40f285985b1.gif) **gripper with safety_controller** ![ode_gripper_with_safety](https://user-images.githubusercontent.com/17570430/145845443-8ec940dc-4529-4148-afc2-820038d28171.gif) **gripper without safety_controller** ![ode_gripper_without_safety](https://user-images.githubusercontent.com/17570430/145845455-c4a775e3-77c1-498c-abe3-7fb543058bf2.gif)

Conclusion

There appears to be a large starting drift both with and without the safety controller enabled.

DART

see result **no gripper with the safety_controller** ![dart_no_gripper_with_safety](https://user-images.githubusercontent.com/17570430/145844425-17a6b05d-bbd2-4677-9402-97d4498bb371.gif) **no gripper without the safety_controller** ![dart_no_gripper_without_safety](https://user-images.githubusercontent.com/17570430/145844456-e37f08f0-54b0-4f8e-9d6d-dab0d1d23cfb.gif) **gripper with safety_controller** ![dart_gripper_with_safety](https://user-images.githubusercontent.com/17570430/145844491-9f9ad223-9cb0-4d35-a21d-4ffad40ec0ec.gif) **gripper without safety_controller** ![dart_gripper_without_safety](https://user-images.githubusercontent.com/17570430/145844501-5281d1fc-a457-4a40-ae5d-c1756d8c0506.gif)

Conclusion

The simulation now is a lot more stable. There still is a slight starting drift, but it is significantly reduced by using the Dart engine. After 3 minutes, the arm will have lowered a bit because joint four has drifted:

see result ![image](https://user-images.githubusercontent.com/17570430/145964973-e24d7c2b-cbf4-41bd-8d54-0defb4537606.png)

Bullet

see result ![bullet](https://user-images.githubusercontent.com/17570430/145279751-adc19449-c170-4e6b-b732-864083dda4fd.gif)

Simbody

see result ![simbody](https://user-images.githubusercontent.com/17570430/145279837-d4d95c43-9336-4c33-9998-c3b3981c03aa.gif)

Conclusion

It looks like the drift is less significant when we use the dart physics engine compared to the ODE physics engine. Disabling the safety controller does not affect this starting drift. Most drift is introduced when the hand is added to the robot.

rickstaa commented 2 years ago

@gollth, @marcbone I concluded my investigation into the motion drift (i.e. for Gazebo 11); you can check the comments above. I added the plots and figures under a collapsable <details> section to remove noise. I summarized my results below:

Conclusions

Next steps

The starting drift can be reduced by switching to the DART physics engine from the conclusions above. Changing the ODE parameters might yield a similar result. After this is done, the drift that is still left when the hand is not attached can be removed by taking the soft and hard joint limits into account when applying for gravity compensation. This can be done by adding a simple check before applying for the gravity compensation. The drift experienced with the attached hand is caused by the gravity compensation bot taking into account the physical properties of the hand.

I will leave these changes up to you since there are many ways to implement this. I think solving this will significantly improve the gravity compensation.

Another thing I noticed while migrating from the stick to the panda was that the drift becomes problematic when the collision geometries are added. I did not yet find why this is the case. The drift is too big to be caused by the small error found between the KDL gravity component calculation. Maybe the drift can also be reduced by improving the link, joint and physics engine properties?

Since I have been working on this issue for a long time, I think a fresh pair of eyes is needed to verify my conclusions. I am looking forward to hearing your take on this problem. Feel free to let me know if anything is unclear or needs clarification.

rickstaa commented 2 years ago

@gollth I used the singularity recipe below to verify that the bug is present in Gazebo 9. The only result that is different from your initial example is that Gazebo's effort is 0.0. My result, however, is similar to the values shown in https://github.com/frankaemika/franka_ros/issues/160#issuecomment-987682342. Nevertheless, in the new example, Gazebo's torque and joint effort are incorrect. Maybe you can open an issue on osrf/gazebo_models repository if you Franka also wants to support ROS melodic?

My result

I get the following result when using:

roslaunch franka_gazebo panda.launch   use_gripper:=false   headless:=false   paused:=true   rotated:=true initial_joint_positions:="-J panda_joint6 1.5707963267948966"
[ WARN] [1639081235.413943968, 2.107000000]: panda_joint6: Error:                 0.250003
[ WARN] [1639081235.413970640, 2.107000000]: panda_joint6: Total Effort:          0.000003
[ WARN] [1639081235.414014090, 2.107000000]: panda_joint6: KDL GravComp:          0.250000
[ WARN] [1639081235.414040982, 2.107000000]: panda_joint6: KDL GravComp flipped:  -0.250000
[ WARN] [1639081235.414069299, 2.107000000]: panda_joint6: Gazebo body2Torque:   [0.000007, -0.500000, 0.000003]
[ WARN] [1639081235.414095318, 2.107000000]: panda_joint6: Desired joint command: 0.000000
[ WARN] [1639081235.414120661, 2.107000000]: panda_joint6: Joint command:         0.250000
[ WARN] [1639081235.414149246, 2.107000000]: panda_joint6: Global Axis: [-0.000001, -1.000000, -0.000001]
[ WARN] [1639081235.414176269, 2.107000000]: panda_joint6: Local Axis:  [0.000000, -1.000000, 0.000000]
[ WARN] [1639081235.414204518, 2.107000000]: panda_joint6: URDF Axis:   [0, 0, 1]
[ WARN] [1639081235.414230392, 2.107000000]: panda_joint6: Joint velocity:        -0.000009

Singularity recipe

I used the following recipe to build my ubuntu 18.04 container. For more information see https://sylabs.io/guides/latest/user-guide. Please make sure you use the --nv flag and added your user name to the xhost control access list when you can not open GUI applications like RVIZ and Gazebo (see apptainer/singularity#3800).

# Ubuntu 18.04 - Ros melodic Franka gazebo gravity compensation test container
Bootstrap: docker
From: osrf/ros:melodic-desktop-full

%help
    A small container used for testing the problems explained in
    https://github.com/frankaemika/franka_ros/issues/160#issuecomment-961780423.
%labels
    Maintainer: Rick Staa
    Github: https://github.com/frankaemika/franka_ros/issues/160#issuecomment-961780423
    Version: v0.0.0
    Type: Public
%environment
    # Set language options
    export LANG=C.UTF-8 LC_ALL=C.UTF-8

    # Set ROS vars
    export ROS_DISTRO=melodic
%post
    # Install extra system package dependencies
    apt update --fix-missing
    apt install -q -y git

    # Install ros build tools
    apt install -q -y python-catkin-tools

    # Install libfranka from source
    # NOTE: Uncomment if you want to install from source
    apt update
    apt install -q -y \
       cmake \
       libpoco-dev \
       libeigen3-dev
    bash -c "cd / \
       && apt remove -y \"*libfranka*\" \
       && git clone --recursive https://github.com/frankaemika/libfranka.git \
       && cd libfranka \
       && mkdir build \
       && cd build \
       && cmake -DCMAKE_BUILD_TYPE=Release .. \
       && cmake --build ."

    # Build the gazebo gravity compensation test catkin workspace
    mkdir -p /gazebo_gravity_comp_test_ws; cd /gazebo_gravity_comp_test_ws
    git clone -b melodic-devel --recursive https://github.com/rickstaa/gazebo-torque-calculation-bug.git src
    rosdep install --from-paths src --ignore-src --rosdistro melodic -y --skip-keys libfranka
    . /opt/ros/melodic/setup.sh; catkin build -DCMAKE_BUILD_TYPE=Release -DFranka_DIR:PATH=/libfranka/build
rickstaa commented 2 years ago

@golth, @marco I just updated my conclusion since I noticed that the drift I removed entirely when the safety_controller is disabled in the DART physics engine. I now have a clear picture of what caused this drift and how we can solve it.

rickstaa commented 2 years ago

@gollth, @marcbone The first part of the solution is implemented in #211.

rickstaa commented 2 years ago

@gollth, @marcbone I just noticed that I made an error while looking at the safety controller. It is not the safety controller that causes the starting drift but the addition of the hand. It however does cause unstable behaviour (see https://github.com/frankaemika/franka_ros/issues/160#issuecomment-988621107).

I updated https://github.com/frankaemika/franka_ros/issues/160#issuecomment-989175979 so that it reflects the right conclusion.

rickstaa commented 2 years ago

@gollth, @marcbone, I think I found the cause of the drift experienced when the hand is attached. It looks that your gravity compensation is not taking into account the physical properties of the attached hand:

https://github.com/frankaemika/franka_ros/blob/cbe64f9e9499dcb192c152f5a6a9473fefc1ff91/franka_gazebo/src/model_kdl.cpp#L277

The currently used KDL::Chain starts from panda_link0 and ends at panda_link8. Can you verify that this is indeed the case?

I did not create a pull request since it requires me to rewrite a significant part of your codebase. I, therefore, first wanted to discuss the issue with you.

I updated https://github.com/frankaemika/franka_ros/issues/160#issuecomment-989175979 to include the new cause. To summarize, the causes I found for the drift, ordered from most serious to less severe, are:

rickstaa commented 2 years ago

@gollth, @marcbone sorry for the enormous amount of information, but I just noticed I forgot something in my previous conclusion https://github.com/frankaemika/franka_ros/issues/160#issuecomment-992776684. It did not include the fact that although the starting drift is not caused by the safety_controller it does cause some unstable behaviour at the soft joint limits. I hope I have given you a good picture of all the problems that are currently present in the gravity compensation. I will leave the further investigation to you now. Please let me know when things are unclear.

gollth commented 2 years ago

It looks that your gravity compensation is not taking into account the physical properties of the attached hand:

Yes it does (kind of), directly with the line after your snippets:

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/src/model_kdl.cpp#L277-L278

This appends a load frame to the end of the chain. This load frame is defined by the mass of the EE (m_total) and the CoM (F_x_Ctotal) which both come ultimately from the URDF (unless the user sets custom values via ROS parameters):

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/src/franka_hw_sim.cpp#L440-L455

Although you are right, the inertia tensor of this augmented link is still identity

gollth commented 2 years ago

Thanks for all your investigation @rickstaa

rickstaa commented 2 years ago

@gollth Thanks a lot for your response. You are right thanks for clarifying that! Based on the naming (i.e. load), I assumed that the augmented frame only accounted for the external load. I quickly checked the code, and overall, it looks correct. I, however, have some concerns about the current implementation:

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/launch/panda.launch#L54

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/src/franka_hw_sim.cpp#L421

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/src/franka_hw_sim.cpp#L431-L434

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/src/franka_hw_sim.cpp#L445-L447

I think adding the fingers to the chain might be more correct. I, however, am not sure if KDL allows for parallel links in a chain. I vaguely remember it does not, but I haven't looked at it for a while. If adding parallel links is not allowed, we could use a single link that contains the combined COM and inertia matrix of both the hand and the two fingers. Lastly

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/src/franka_hw_sim.cpp#L315

https://github.com/frankaemika/franka_ros/blob/8efef6235b969c68ec1f8d5bc85026e4bca9cf19/franka_gazebo/src/model_kdl.cpp#L271

I hope we can find the cause of this drift. Please let me know if you need help from my side.

rickstaa commented 2 years ago

@gollth I created an issue on the gazebo repository for the drift difference that is observed between the ODE and DART physics engine (see https://github.com/osrf/gazebo/issues/3149). Did you already create an issue for the ROS melodic torque calculation problem? In my issue, I quickly mention the melodic torque problem but I currently link it to https://github.com/frankaemika/franka_ros/issues/160#issuecomment-987682342.

justagist commented 2 years ago

Although franka_hw_sim_plugin handles the gravity compensation for the arm, there is no gravity compensation in franka_gripper_sim. This causes the gripper commands to not work correctly when the gripper fingers are not in the same horizontal plane. I had to completely disable gravity in the simulation to make the gripper work in such configurations.

rickstaa commented 2 years ago

@gollth, @marcbone do you have any updates on what goes wrong with the gravity compensation when the gripper is attached?

I think using the DART simulator is a good workaround for now when the gripper is not attached. I can successfully train my RL algorithm using the DART simulator as the gravity compensation seems stable. I am unsure what causes the drift when the ODE physics engine is used. I did not have time to dive deeper into the Gazebo codebase, and the gazebo team has not yet responded to the issue I opened about this drift. I, therefore, think for now it might be best to merge https://github.com/frankaemika/franka_ros/pull/211 since this gives users the ability to use the DART physics engine when using effort control.

I, however, found one problem when using the DART physics engine. See the section below. Nevertheless, the gravity compensation does not seem to work both in the ODE and DART physics engine, the panda robot keeps drifting, so I think this should be fixed first.

Grasp action DART crash

When the gripper is attached and the franka_gripper/grasp/goal, franka_gripper/move/goal or franka_gripper/gripper_action/goal actions are used the simulator sometimes crashes with the following error message:

Show error message ```bash Error [BoxedLcpConstraintSolver.cpp:291] [BoxedLcpConstraintSolver] The solution of LCP includes NAN values: -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan nan nan nan nan nan nan nan -nan -nan. We're setting it zero for safety. Consider using more robust solver such as PGS as a secondary solver. If this happens even with PGS solver, please report this as a bug. [ WARN] [1643023521.425695656, 90.305000000]: Command for panda_joint1is NaN, won't send to robot [ WARN] [1643023521.425777956, 90.305000000]: Command for panda_joint2is NaN, won't send to robot [ WARN] [1643023521.425795056, 90.305000000]: Command for panda_joint3is NaN, won't send to robot [ WARN] [1643023521.425808456, 90.305000000]: Command for panda_joint4is NaN, won't send to robot [ WARN] [1643023521.425855257, 90.305000000]: Command for panda_joint5is NaN, won't send to robot [ WARN] [1643023521.426084258, 90.305000000]: Command for panda_joint6is NaN, won't send to robot [ WARN] [1643023521.426113458, 90.305000000]: Command for panda_joint7is NaN, won't send to robot [ WARN] [1643023522.488360928, 90.307000000]: Command for panda_joint1is NaN, won't send to robot [ WARN] [1643023522.488449328, 90.307000000]: Command for panda_joint2is NaN, won't send to robot [ WARN] [1643023522.488477629, 90.307000000]: Command for panda_joint3is NaN, won't send to robot [ WARN] [1643023522.488506729, 90.307000000]: Command for panda_joint4is NaN, won't send to robot [ WARN] [1643023522.488532129, 90.307000000]: Command for panda_joint5is NaN, won't send to robot [ WARN] [1643023522.488556229, 90.307000000]: Command for panda_joint6is NaN, won't send to robot [ WARN] [1643023522.488580929, 90.307000000]: Command for panda_joint7is NaN, won't send to robot [ WARN] [1643023523.534044389, 90.307000000]: Command for panda_joint1is NaN, won't send to robot [ WARN] [1643023523.534135489, 90.307000000]: Command for panda_joint2is NaN, won't send to robot [ WARN] [1643023523.534164089, 90.307000000]: Command for panda_joint3is NaN, won't send to robot [ WARN] [1643023523.534194190, 90.307000000]: Command for panda_joint4is NaN, won't send to robot [ WARN] [1643023523.534219690, 90.307000000]: Command for panda_joint5is NaN, won't send to robot [ WARN] [1643023523.534244590, 90.307000000]: Command for panda_joint6is NaN, won't send to robot [ WARN] [1643023523.534268890, 90.307000000]: Command for panda_joint7is NaN, won't send to robot Segmentation fault (core dumped) franka_gripper_sim_test: /usr/include/boost/smart_ptr/shared_ptr.hpp:734: typename boost::detail::sp_member_access::type boost::shared_ptr::operator->() const [with T = const sensor_msgs::JointState_ >; typename boost::detail::sp_member_access::type = const sensor_msgs::JointState_ >*]: Assertion `px != 0' failed. ```
See the problem in action **Branch used for the test:** https://github.com/rickstaa/franka_ros/tree/dart_engine_tests ![gripper_close_problem](https://user-images.githubusercontent.com/17570430/150782558-5dd72aa5-aac8-4e1e-b9f3-50cd4238209b.gif) ![gripper_Close_problem2](https://user-images.githubusercontent.com/17570430/150785257-0490b32b-f6d2-4659-be33-9e46e7cbd131.gif)

Funny enough, this issue showed that the new tests you introduced are working (see https://github.com/frankaemika/franka_ros/runs/4920586653?check_suite_focus=true) πŸš€ .

This only seems to happen when the gripper is controlled to the fully closed and fully opened position (i.e. 0.0 and 0.08). I, therefore, think this is caused by a bug or the instability of the gripper control logic, which causes some numbers to become singular. It might be closely related to the problems I pointed out in https://github.com/frankaemika/franka_ros/pull/173#issuecomment-979223037. However, I did not yet investigate since the gravity compensator for when the gripper is attached is not working yet, which might also cause the crash. However, this hypothesis is strengthened since it does not seem to happen when I stabilize the panda arm by putting it down on the ground (see figure below). I know that getting the gripper to work in simulation is not easy, but I just wanted to make you aware of all the problems I found.

See stabilized position ![image](https://user-images.githubusercontent.com/17570430/150779998-a6b43e3f-301b-4701-a430-87b3adf920f2.png)
rickstaa commented 2 years ago

Although franka_hw_sim_plugin handles the gravity compensation for the arm, there is no gravity compensation in franka_gripper_sim. This causes the gripper commands to not work correctly when the gripper fingers are not in the same horizontal plane. I had to completely disable gravity in the simulation to make the gripper work in such configurations.

@justagist Thanks for your comment! @marcbone I think this is closely related to my comment in https://github.com/frankaemika/franka_ros/pull/173#issuecomment-979223037. The gripper PID gains might be easier to tune when the gravity of the fingers is also compensated! I however do not think that this is the major cause of the drift we observe when the hand is attached when using the DART physics engine (see figure below).

See gif ![gripper_drift](https://user-images.githubusercontent.com/17570430/150786487-2da0ec20-5c2a-4138-ad27-e6e244f48faf.gif)
gollth commented 2 years ago

For reference, the movement of the joints should now be gone also in Melodic with the new feature from @rickstaa & @marcbone: https://github.com/frankaemika/franka_ros/pull/181#issuecomment-1064120809 (although it does only mask the underlying real problem in Gazebo).

@rickstaa what do you think, shall we close this ticket or do you want to keep it open for reference?