Page 1 of 1

setObject moving different than commanded

Posted: 30 May 2021, 01:56
by marcosmacp
Hi there.
I have a model which should move according to directions passed by Serial or keyboard commands, going foward, backward and turning left or right.

The thing is when it moves related to the global parameters:
sim.setObjectOrientation(handle,-1,{x, y, changeZ})
sim.setObjectPosition(handle,-1,{changeX, y, z})
After turning, the position is still related to the global parameters, moving sideways, when it should go foward and facing the front of the model.

Then I tried moving it related to itself:
sim.setObjectOrientation(handle, handle, {x, y, changeZ})
sim.setObjectPosition(handle, handle,{changeX, y, z})

This way the model started moving up like there was a ramp to the sky even though I'm only changing position on the x-axis and orientation turning on the z-axis.
I don't understand why this is happening. I would appreciate some help.
Thanks

Re: setObject moving different than commanded

Posted: 31 May 2021, 08:41
by fferri
Don't know about your complete code or your simulation scene.

This code works for me:

Code: Select all

function left()
    sim.setObjectOrientation(handle,handle,{0,0,math.pi/8})
end

function forward()
    sim.setObjectPosition(handle,handle,{0.05,0,0})
end

function right()
    sim.setObjectOrientation(handle,handle,{0,0,-math.pi/8})
end
Just make sure your object's reference frame is correctly aligned (e.g. with the reference frame of the world).

Re: setObject moving different than commanded

Posted: 18 Jun 2021, 20:58
by marcosmacp
Thank you!

It really doesn't look like it's an issue from the code, I've figured out that it might be because of the physics of the model.
Apparently the model wasn't correctly balanced, so when it started moving it also turned a little upwards.

I changed some of the model mass values and positions, to arrange the balance and it worked.
I also changed to jointVelocity as I have motors enabled.

I appreciate a lot!