Rotation of a Body (Roll Pitch)

Typically: "How do I... ", "How can I... " questions
Post Reply
DannyYeong
Posts: 44
Joined: 24 Feb 2015, 17:06

Rotation of a Body (Roll Pitch)

Post by DannyYeong » 07 Jul 2015, 18:21

Hi,

I'm trying to implement a roll pitch rotation on a body. For the moment I'm using simSetJointTargetVelocity to manipulate the rotation. Are there other ways to control the revolute joint's rotation angle/velocity under a non threaded script? I'm trying to make a "swinging motion" like a real quad that's achieving balance after moving. My file is below:


http://www.filedropper.com/orientationbodytest

My coding part for the rotation is below (also included in the file script):

Code: Select all

---------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------ RP-Orientation------------------------------------------------------------

	
	posnew=simGetObjectPosition(body,-1)
	posnew1=simGetObjectPosition(target,-1)

	posnew[2]=math.sqrt(posnew[2]*posnew[2])
	posnew[1]=math.sqrt(posnew[1]*posnew[1])
	posnew1[2]=math.sqrt(posnew1[2]*posnew1[2])
	posnew1[1]=math.sqrt(posnew1[1]*posnew1[1])

	

	mathdiff=posnew1[2]-posnew[2]
	mathdiff1=posnew1[1]-posnew[1]

		if mathdiff>0.075 then
			Vroll=-0.075
		elseif mathdiff<-0.2 then
			Vroll=0.075
		else
			Vroll=0
		end


	simSetJointTargetVelocity(roll,Vroll)

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

Re: Rotation of a Body (Roll Pitch)

Post by coppelia » 08 Jul 2015, 17:02

Hello,

as far as I understand it, you want to control your joint in position, not in velocity or torque. If this is the case, make sure your joint is in force/torque mode, the motor enabled, and the control loop enabled too. Then set the desired position with simSetJointTargetPosition.

Cheers

Post Reply