Rotation Matrix from sensor to MATLAB

Typically: "How do I... ", "How can I... " questions
Post Reply
codycichosz
Posts: 16
Joined: 06 Dec 2020, 00:39

Rotation Matrix from sensor to MATLAB

Post by codycichosz »

Hello,

I am using MATLAB to control my scene in CoppeliaSim. I am currently trying to attach a proximity sensor to a UR10 and if an object is detected, transform the detected object position with respect to the UR10 frame, not the sensor frame. This is to determine where the detected object is relative to the robot for collision avoidance.

I tried following the below help file as it lists the rotation equation. This helps as it shows the rotation equation.
https://www.coppeliarobotics.com/helpFi ... Angles.htm

I also tried following this topic thread, but my rotation matrix is different and do not know where theirs came from.
https://forum.coppeliarobotics.com/view ... ?f=9&t=975

The problem I am having is, depending on the orientation of my sensor, I receive correct or wrong positions transformations. Below is a link to a simplified scene and MATLAB code. I use the proxy sensor to detect a cuboid, and a dummy grab the correct absolute detected position. The output in MATLAB is supposed to be the absolute position of the detected point. In the current configuration, the position will read correctly. As soon as I rotate the sensor along its Z axis, it reads a different detected position (I.e. [Alpha, beta, gamma] = [-90, 0, 0])

https://app.box.com/s/mbgnoz7uxew1om1wsvi2fxgfr50oadu1

Thanks for the help in advance!
Cody

coppelia
Site Admin
Posts: 8730
Joined: 14 Dec 2012, 00:25

Re: Rotation Matrix from sensor to MATLAB

Post by coppelia »

Hello Cody,

before trying to do frame/coordinate transformations from Matlab, make sure it is working from within CoppeliaSim. In CoppeliaSim you have many matrix and transformation related functions. Once it is working well or as expected in CoppeliaSim, do the same on Matlab side. But best and easiest is probably to directly provide Matlab with the transformed data. For that, simply create a small script function, that you will call from Matlab via simxCallScriptFunction. E.g. to express a point detected by a proximity sensor in absolute coordinates:

Code: Select all

function readProxSensor(inInts,inFloats,inStrings,inBuffer)
    local proxSensorHandle=inInts[1]
    local detectedPoint={}
    local m=sim.getObjectMatrix(proxSensorHandle,-1)
    local r,dist,detectedPoint,objHandle,normalVector=sim.readProximitySensor(proxSensorHandle)
    if r>0 then
        detectedPoint=sim.multiplyVector(m,detectedPoint)
    end
    return {},detectedPoint,{},''
end
Cheers

codycichosz
Posts: 16
Joined: 06 Dec 2020, 00:39

Re: Rotation Matrix from sensor to MATLAB

Post by codycichosz »

Thank you so much! This works perfect. This reduces any error in my calculations.

Cheers!

Post Reply