problem about sim.alphaBetaGammaToYawPitchRoll

Typically: "How do I... ", "How can I... " questions
Post Reply
SitStudent
Posts: 23
Joined: 05 May 2020, 12:07

problem about sim.alphaBetaGammaToYawPitchRoll

Post by SitStudent »

Hi

I tried this code just putting cylinder on scene as test.

Code: Select all

function sysCall_init()
    
    Graph1 = sim.getObjectHandle("YawPitchRoll")
    Graph2 = sim.getObjectHandle("AlphaBetaGamma")
    cyl = sim.getObjectHandle("Cylinder")
    
    yaw = sim.addGraphStream(Graph1,"Yaw","deg",0,{1,0,0})
    pitch = sim.addGraphStream(Graph1,"Pitch","deg",0,{0,1,0})
    roll = sim.addGraphStream(Graph1,"Roll","deg",0,{0,0,1})
    
    alpha = sim.addGraphStream(Graph2,"alpha","deg",0,{1,0,0})
    beta = sim.addGraphStream(Graph2,"beta","deg",0,{0,1,0})
    gamma = sim.addGraphStream(Graph2,"gamma","deg",0,{0,0,1})
    
end

function sysCall_actuation()
    
    cyl_orien = sim.getObjectOrientation(cyl,-1)
    
    sim.setGraphStreamValue(Graph2,alpha,cyl_orien[1])
    sim.setGraphStreamValue(Graph2,beta,cyl_orien[2])
    sim.setGraphStreamValue(Graph2,gamma,cyl_orien[3])
    
    changeRotate = sim.alphaBetaGammaToYawPitchRoll(cyl_orien[1],cyl_orien[2],cyl_orien[3])
    print(changeRotate)
    sim.setGraphStreamValue(Graph1,Yaw,changeRotate[1])
    sim.setGraphStreamValue(Graph1,pitch,changeRotate[2])
    sim.setGraphStreamValue(Graph1,roll,changeRotate[3])
    
end
However, changeRotate is not table, only 1 number.
why can't I get the result as table?

thank you as usual.

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

Re: problem about sim.alphaBetaGammaToYawPitchRoll

Post by coppelia »

Hello,

if you check the documentation for sim.alphaBetaGammaToYawPitchRoll, you'll see that it returns 3 scalar values, not a table. So use it like:

Code: Select all

local yaw,pitch,roll=sim.alphaBetaGammaToYawPitchRoll(alpha,beta,gamma)
-- then you could create your table, e.g.:
local ypr={yaw,pitch,roll}
Cheers

Post Reply