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
setObject moving different than commanded
Re: setObject moving different than commanded
Don't know about your complete code or your simulation scene.
This code works for me:
Just make sure your object's reference frame is correctly aligned (e.g. with the reference frame of the world).
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
-
- Posts: 2
- Joined: 27 May 2021, 16:50
Re: setObject moving different than commanded
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!
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!