Moving an Object with Lua Code
-
- Posts: 49
- Joined: 26 Oct 2021, 01:35
Moving an Object with Lua Code
Hello! I would like to ask what is the proper syntax for the position value/s in the sim.setObjectPosition command. I would like to rectangularly translate my mesh part during a simulation which is why I am asking. Thanks in advance.
Re: Moving an Object with Lua Code
The function arguments are described here: sim.setObjectPosition
The position value is
By the way, sim.setObjectPosition will jump to the set position. If you are looking for a smooth continuous motion, then use sim.moveToPose, e.g.:
The position value is
{x,y,z}
By the way, sim.setObjectPosition will jump to the set position. If you are looking for a smooth continuous motion, then use sim.moveToPose, e.g.:
Code: Select all
function coroutineMain()
local waypoints={
-- define a square. waypoints are {x,y,z,qx,qy,qz,qw}
{0,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,1,0,0,0,0,1},
{0,1,0,0,0,0,1},
}
for n=1,100 do
for i=1,#waypoints do
local from,to=waypoints[i],waypoints[i%4+1]
sim.moveToPose(-1,from,{0.8},{0.02},{0.01},to,function(currentPose,currentVel,currentAccel,auxData)
sim.setObjectPose(self,-1,currentPose)
end,nil,{1,1,1,0.1})
end
end
end
function sysCall_init()
corout=coroutine.create(coroutineMain)
self=sim.getObject'.'
end
function sysCall_actuation()
if coroutine.status(corout)~='dead' then
local ok,errorMsg=coroutine.resume(corout)
if errorMsg then
error(debug.traceback(corout,errorMsg),2)
end
end
end
-
- Posts: 49
- Joined: 26 Oct 2021, 01:35
Re: Moving an Object with Lua Code
So this sample code would be able to move the object named 'self' through a square-shaped trajectory? Is that correct?
Re: Moving an Object with Lua Code
Yes.
See also the examples in the scenes/trajectoryAndMotion/ folder that comes with CoppeliaSim.
See also the examples in the scenes/trajectoryAndMotion/ folder that comes with CoppeliaSim.
-
- Posts: 49
- Joined: 26 Oct 2021, 01:35
Re: Moving an Object with Lua Code
I would just like to clarify Euler angles:
Alpha is about x, beta is about y and gamma is about z? Is this correct?
Alpha is about x, beta is about y and gamma is about z? Is this correct?
-
- Posts: 49
- Joined: 26 Oct 2021, 01:35
Re: Moving an Object with Lua Code
Also, since you gave me a sample algorithm to do smooth movement of an object during a simulation,
how about doing smooth rotation during a simulation? Is it possible to execute that?
Thanks in advance.
how about doing smooth rotation during a simulation? Is it possible to execute that?
Thanks in advance.
Re: Moving an Object with Lua Code
Yes, in the same way. Simply use a different orientation (quaternion) than 0,0,0,1.
Euler angles are explained here: https://www.coppeliarobotics.com/helpFi ... Angles.htm
Euler angles are explained here: https://www.coppeliarobotics.com/helpFi ... Angles.htm
-
- Posts: 49
- Joined: 26 Oct 2021, 01:35
Re: Moving an Object with Lua Code
I wish you could also explain this waypoint arrays in the sample code please.
function coroutineMain()
local waypoints={
-- define a square. waypoints are {x,y,z,qx,qy,qz,qw}
{0,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,1,0,0,0,0,1},
{0,1,0,0,0,0,1},
}
for n=1,100 do
for i=1,#waypoints do
local from,to=waypoints,waypoints[i%4+1]
sim.moveToPose(-1,from,{2},{2},{0.01},to,function(currentPose,currentVel,currentAccel,auxData)
sim.setObjectPose(self,-1,currentPose)
end,nil,{1,1,1,0.1})
end
end
end
Like, how did this
{0,0,0,0,0,0,1}
make a trajectory for the moving object which was going exactly the +x direction?
Thanks
function coroutineMain()
local waypoints={
-- define a square. waypoints are {x,y,z,qx,qy,qz,qw}
{0,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,1,0,0,0,0,1},
{0,1,0,0,0,0,1},
}
for n=1,100 do
for i=1,#waypoints do
local from,to=waypoints,waypoints[i%4+1]
sim.moveToPose(-1,from,{2},{2},{0.01},to,function(currentPose,currentVel,currentAccel,auxData)
sim.setObjectPose(self,-1,currentPose)
end,nil,{1,1,1,0.1})
end
end
end
Like, how did this
{0,0,0,0,0,0,1}
make a trajectory for the moving object which was going exactly the +x direction?
Thanks
Re: Moving an Object with Lua Code
The waypoints are defined as poses: position + orientation. The position are the (x, y, z) coordinates. The orientation is expressed as a quaternion (qx, qy, qz, qw).
See also sim.buildPose, sim.getObjectPose, sim.setObjectPose
Cheers
See also sim.buildPose, sim.getObjectPose, sim.setObjectPose
Cheers
-
- Posts: 49
- Joined: 26 Oct 2021, 01:35
Re: Moving an Object with Lua Code
How do you manipulate the quaternion to get negative rotation?
For example, I know that for it to rotate about x the quarternion is {1,0,0,0}.
I thought maybe making it {-1,0,0,0} would make it rotate opposite when it was a one I cited above, but it did not.
Thanks
For example, I know that for it to rotate about x the quarternion is {1,0,0,0}.
I thought maybe making it {-1,0,0,0} would make it rotate opposite when it was a one I cited above, but it did not.
Thanks