dqrobotics / python

The DQ Robotics library in Python
https://dqrobotics.github.io
GNU Lesser General Public License v3.0
24 stars 9 forks source link

[BUG] The pose_jacobian() of DQ_DifferentialDriveRobot is trying to access link index 3 #22

Closed marcos-pereira closed 3 years ago

marcos-pereira commented 3 years ago

Hi @mmmarinho , although this issue is similar to issue #20 , I decided to open it because it is related to another file.

Bug description

To Reproduce

Code

import numpy as np
from dqrobotics.robot_modeling import DQ_DifferentialDriveRobot
q = np.array([0.12,   0.0,    0.0])
diff_robot = DQ_DifferentialDriveRobot(1,1)
J = diff_robot.pose_jacobian(q)
print(J)

Output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Tried to access link index 3 which is unnavailable.

Expected behavior

Matlab code

q = [0.12 0 0];
robot = DQ_DifferentialDriveRobot(1,1);
J_pose = robot.pose_jacobian(q)

Matlab output

J_pose =

         0         0
         0         0
         0         0
    0.5000   -0.5000
         0         0
    0.2500    0.2500
    0.0300   -0.0300
         0         0

Environment:

Additional context

mmmarinho commented 3 years ago

Thanks, @marcos-pereira,

Let me know how it goes.

marcos-pereira commented 3 years ago

Hi @mmmarinho , now when running

import numpy as np
from dqrobotics.robot_modeling import DQ_DifferentialDriveRobot
q = np.array([0.12,   0.0,    0.0])
diff_robot = DQ_DifferentialDriveRobot(1,1)
J = diff_robot.pose_jacobian(q)
print(J)

it throws a segmentation fault on the pose_jacobian line. Looking at the DQ_DifferentialDriveRobot.cpp I don't know exactly what is the problem. Maybe on line 52 when adding +1, but I'm not sure. Just a guess: the Matlab version returns a two column Jacobian matrix, hence, the J.block() on line 52 should be (0,0,3,2), in other words, there is no need for the +1. However I can't confirm that only by looking at the DQ_DifferentialDriveRobot.m and I also don't know how the Eigen block() method works.

mmmarinho commented 3 years ago

Hello, @marcos-pereira !

Thanks for testing.

This robot is a bit different from the other ones so I need to fix the implementation. I’ll propose another fix tomorrow when I have access to my computer.

Cheers, Murilo

mmmarinho commented 3 years ago

Hello, @marcos-pereira,

Could you check if it is working now? Thanks in advance.

marcos-pereira commented 3 years ago

Hi, @mmmarinho ,

Thanks for the fix, but it is still not working. When running:

import numpy as np
from dqrobotics.robot_modeling import DQ_DifferentialDriveRobot
q = np.array([0.12,   0.0,    0.0])
diff_robot = DQ_DifferentialDriveRobot(1,1)
J = diff_robot.pose_jacobian(q)

It strangely throws the runtime error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: DQ_DifferentialDriveRobot::pose_jacobian(q,to_link) only accepts to_link in {0,1}

I checked the DQ_DifferentialDriveRobot.cpp. It seems to be correct, but somehow it always enters the if of line 50. I also tried calculating pose_jacobian(q,1) or with different to_link values, but the runtime error always happens.

mmmarinho commented 3 years ago

Hello, @marcos-pereira,

Thanks for all helping me test this. The reason for this bug is quite convoluted so I won't explain in detail but I probably got it all fixed in 67398f0.

Please test it again and let me know if it doesn't work well.

marcos-pereira commented 3 years ago

Hi, @mmmarinho ,

Now the Jacobian is being correctly calculated. Many thanks for fixing this issue! However, I found another issue that is probably related to this one. I believe the issue is the same. I will open another issue since it is related to another code.

Best regards, Marcos