Set Robot Orientation Using CustomUI

Typically: "How do I... ", "How can I... " questions
Post Reply
aapurnama
Posts: 18
Joined: 26 Apr 2013, 12:19

Set Robot Orientation Using CustomUI

Post by aapurnama » 04 Jul 2013, 12:11

Hello,

How to set Robot Orientation Using CustomUI?

i used simSetObjectOrientation(robot,-1,{0,0,90}). But that Code is not work for all part of robot.

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

Re: Set Robot Orientation Using CustomUI

Post by coppelia » 04 Jul 2013, 13:00

Hello,

Not sure about the relationship with the custom UI.

The function to set the orientation of an object with simSetObjectOrientation or simSetObjectQuaternion is correct. If other objects are attached to the object that you are reorienting, they will follow ONLY IF they are static!

If you have a dynamic model you wish to reorient, this represents a physically impossible action (in real-life). So before reorienting them you normally have to dynamically reset them:

If your model objects all share a common base object, do something like this:

Code: Select all

-- Init (get the handles of all objects involved):
baseObjectHandle=simGetObjectHandle('theBaseObjectName')
objectHandlesExceptBase={}
toExplore={baseObjectHandle}
while #toExplore>0 do
	obj=table.remove(toExplore,1)
	index=0
	while true do
		h=simGetObjectChild(obj,index)
		index=index+1
		if h==-1 then
			break
		else
			table.insert(objectHandlesExceptBase,h)
			table.insert(toExplore,h)
		end
	end
end

-- Now reorient the base object:
-- 1. dynamically reset all objects:
simResetDynamicObject(baseObjectHandle)
for i=1,#objectHandlesExceptBase,1 do
	simResetDynamicObject(objectHandlesExceptBase[i])
end
-- 2. reorient the base object:
simSetObjectOrientation(baseObjectHandle,-1,{0,0,90*math.pi/180})
And never forget: API function expects "regular" units, like meters, kilogramms, seconds, radians. So your 90 should probably be 90*math.pi/180!

Cheers

aapurnama
Posts: 18
Joined: 26 Apr 2013, 12:19

Re: Set Robot Orientation Using CustomUI

Post by aapurnama » 04 Jul 2013, 13:29

thanks :)

Post Reply