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

Problems using 'set_reference_frame' and 'set_base_frame'. #5

Closed juanjqo closed 5 years ago

juanjqo commented 5 years ago

The methods 'set_reference_frame' and 'set_base_frame' are not working. Apparently, they are read-only.
Code base:


from dqrobotics import *
from dqrobotics.robots         import KukaLw4Robot
from dqrobotics.robot_modeling import DQ_Kinematics
import numpy as np
theta = np.random.rand(7,1)
robot = KukaLw4Robot.kinematics()

robot.set_reference_frame = DQ([1,0,0,0,0,0,0,0])  #AttributeError: 'dqrobotics.robot_modeling.DQ_SerialManipulator' object attribute 'set_reference_frame' is read-only
robot.set_base_frame = DQ([1,0,0,0,0,0,0,0])   #AttributeError: 'dqrobotics.robot_modeling.DQ_SerialManipulator' object attribute 'set_base_frame' is read-only

#This works in Matlab, but doesn't in Python:
set_reference_frame(robot, DQ([1,0,0,0,0,0,0,0]) )  #NameError: name 'set_reference_frame' is not defined
DQ_Kinematics.set_reference_frame(robot, DQ([1,0,0,0,0,0,0,0]) ) #DQ_Kinematics.set_reference_frame(robot, DQ([1,0,0,0,0,0,0,0]) )

#By doing as in Matlab currently:
robot.base_frame = DQ([1,0,0,0,0,0,0,0])  #AttributeError: ```
'dqrobotics.robot_modeling.DQ_SerialManipulator' object attribute 'base_frame' is read-only
robot.reference_frame = DQ([1,0,0,0,0,0,0,0])   #AttributeError: 'dqrobotics.robot_modeling.DQ_SerialManipulator' object attribute 'reference_frame' is read-only

It does not work either. How I can set the reference frame or the base frame?

mmmarinho commented 5 years ago

Hello, @juanjqo !

As I mentioned in #4, those are methods and not attributes. I don't know why those are working in MATLAB. Are you using the latest MATLAB version?

Anyways, this works in Python:

from dqrobotics import *
from dqrobotics.robots         import KukaLw4Robot
import numpy as np
import math

robot = KukaLw4Robot.kinematics()
reference_frame = robot.reference_frame()
print(reference_frame)
robot.set_reference_frame(math.cos(math.pi/2.0)+i_*math.sin(math.pi/2.0));
reference_frame = robot.reference_frame()
print(reference_frame)

And outputs

1 0i 0j 0k +E( 0 0i 0j 0k )
0 1i 0j 0k +E( 0 0i 0j 0k )

PS: As far as I know, this is how it is supposed to work now. We recently changed (or should have changed) most attributes to protected so that they can't be accessed directly.

juanjqo commented 5 years ago

@mmmarinho Thank you for your help.

Yes, you're right. Now, it is not working anymore in Matlab. I was not using the last version in Matlab (My mistake).

Cheers,

Juancho.