Hello,
How can i convert speed to position. I have a file with speed data on my computer and i want to make my object move. How can i do it ?
How can i convert speed to position with the api python
Re: How can i convert speed to position with the api python
Hello,
what does the file look like? I mean what does speed data mean? Is it a list of speed value, associated with time values? Where your object would have infinite acceleration geoing from one speed value to the next?
Cheers
what does the file look like? I mean what does speed data mean? Is it a list of speed value, associated with time values? Where your object would have infinite acceleration geoing from one speed value to the next?
Cheers
Re: How can i convert speed to position with the api python
First of all, thank you for your quick response.
The file is a . CSV generate after the measurement. In this file I have acceleration and speed according to x,y and z. and I also have time. So these data are associated.
The file is a . CSV generate after the measurement. In this file I have acceleration and speed according to x,y and z. and I also have time. So these data are associated.
Re: How can i convert speed to position with the api python
You can try with something like that:
Make sure the object you want to move is not dynamically enabled, so that you can instantaneously set its position.
Cheers
Code: Select all
speedData={{time=10,speed={0.1,0,0}},
{time=10.5,speed={0.2,0,0}},
{time=11,speed={0.01,0,0}},
{time=15,speed={0,0,0}},
{time=20,speed={-0.1,0,0}},
{time=40,speed={0,0,0}}
}
function sysCall_init()
corout=coroutine.create(coroutineMain)
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
function coroutineMain()
sim.setThreadAutomaticSwitch(false)
local dt=sim.getSimulationTimeStep()
local i=1
local h=sim.getObject('.')
while i<=#speedData do
local speed=speedData[i].speed
print(speed)
while sim.getSimulationTime()<speedData[i].time do
local p=sim.getObjectPosition(h,sim.handle_world)
p[1]=p[1]+speed[1]*dt
p[2]=p[2]+speed[2]*dt
p[3]=p[3]+speed[3]*dt
sim.switchThread()
sim.setObjectPosition(h,sim.handle_world,p)
end
i=i+1
end
end
Cheers