real-time simulation and high fps
real-time simulation and high fps
Hello,
In my scrip, I use sleep function to achieve time delay, which means that when I control the joystick, the model will response after a second. And I used real-time simulation(Select below the Simulation at top toolbar), because I want to record the model's data(its velocity per second, and its moving state per second and so on). But the fps is too high(above 121) when I start the simulation, which results my uncomfortable controlling. How to solve this problem? Please help me.
In my scrip, I use sleep function to achieve time delay, which means that when I control the joystick, the model will response after a second. And I used real-time simulation(Select below the Simulation at top toolbar), because I want to record the model's data(its velocity per second, and its moving state per second and so on). But the fps is too high(above 121) when I start the simulation, which results my uncomfortable controlling. How to solve this problem? Please help me.
Re: real-time simulation and high fps
Hello,
not sure I understand what you mean. When in real-time mode, the simulation will be artificially slowed-down in order to keep a speed quite to real-time.
When you say you use sleep... what function is that? In CoppeliaSim, you should use
Cheers
not sure I understand what you mean. When in real-time mode, the simulation will be artificially slowed-down in order to keep a speed quite to real-time.
When you say you use sleep... what function is that? In CoppeliaSim, you should use
sim.wait
from a threaded script. Trying to wait or sleep from a non-threaded script, will halt/pause/block everything and does not really make sense in that case.Cheers
Re: real-time simulation and high fps
Hello, appreciate for your answer. Actually, I want to achieve a time delay. For example, I press W on keyboard to forward my car model, and the car will forward after a delay time. I've learned there is a sleep function of lua, the code is following:coppelia wrote: ↑05 Jul 2021, 12:27 Hello,
not sure I understand what you mean. When in real-time mode, the simulation will be artificially slowed-down in order to keep a speed quite to real-time.
When you say you use sleep... what function is that? In CoppeliaSim, you should usesim.wait
from a threaded script. Trying to wait or sleep from a non-threaded script, will halt/pause/block everything and does not really make sense in that case.
Cheers
Code: Select all
function sleep(n)
local t = os.clock()
while os.clock() - t <=n do end
end
Re: real-time simulation and high fps
From a non-threaded script, you could do something like:
From a threaded script on the other hand, you can do:
Cheers
Code: Select all
function sysCall_actuation()
if eventJustOccured then
eventJustOccured=nil
timeEventOccured=sim.getSimulationTime()
end
if timeEventOccured and sim.getSimulationTime()-timeEventOccured>=timeDelay then
timeEventOccured=nil
-- respond to event here
end
end
Code: Select all
if eventJustOccured then
eventJustOccured=nil
sim.wait(timeDelay) -- wait timeDelay seconds (in sim. time)
-- respond to event here
end
Re: real-time simulation and high fps
Thanks for your reply. I've tried to do like you said, but it's failed TOT. I want to control a car by joystick, and achieve time delay, which means when I push the joystick, the car will go forward after a time delay. The code controlling the car is following:coppelia wrote: ↑06 Jul 2021, 14:28 From a non-threaded script, you could do something like:From a threaded script on the other hand, you can do:Code: Select all
function sysCall_actuation() if eventJustOccured then eventJustOccured=nil timeEventOccured=sim.getSimulationTime() end if timeEventOccured and sim.getSimulationTime()-timeEventOccured>=timeDelay then timeEventOccured=nil -- respond to event here end end
CheersCode: Select all
if eventJustOccured then eventJustOccured=nil sim.wait(timeDelay) -- wait timeDelay seconds (in sim. time) -- respond to event here end
Code: Select all
axes, buttons,rotAxes,slider,pov = simJoy.getData(0)
if eventJustOccured then
eventJustOccured=nil
if(axes[2]>114 and -250<rotAxes[3] and rotAxes[3]<250) then
sim.wait(X[b][1])
axes[2]=-axes[2]/10000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*axes[2]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,(linearVelocityRight*axes[2]*v)/(s*wheelRadius))
m=2
elseif(axes[2]<-118 and -250<rotAxes[3] and rotAxes[3]<250) then
sim.wait(X[b][1])
axes[2]=-axes[2]/10000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*axes[2]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,(linearVelocityRight*axes[2]*v)/(s*wheelRadius))
m=1
elseif(131<rotAxes[3]) then
sim.wait(X[b][1])
rotAxes[3]=rotAxes[3]/50000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*rotAxes[3]*v/3)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,-(linearVelocityRight*rotAxes[3]*v/3)/(s*wheelRadius))
m=4
elseif(rotAxes[3]<-131) then
sim.wait(X[b][1])
rotAxes[3]=rotAxes[3]/50000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*rotAxes[3]*v/3)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,-(linearVelocityRight*rotAxes[3]*v/3)/(s*wheelRadius))
m=3
else
sim.wait(X[b][1])
m=0
sim.setJointTargetVelocity(leftJointDynamic,0)
sim.setJointTargetVelocity(rightJointDynamic,0)
end
end
stack traceback:
[C]: in function 'write'
[string "LineTracer@childScript"]:254: in function <[string "LineTracer@childScript"]:67>
and the 254 line is a sentence recording the date:
Code: Select all
fp:write(string.format('%.2f',simulationtime),',',string.format('%.2f',current_position[1]),',',string.format('%.2f',current_position[2]),',',string.format('%.2f',math.deg(current_orientation[3])),',',current_moving(m),',',collisionTimes,',',X[b][1],',',current_map(p),',',current_clearance(c),'\n')
The problem is, only when I used sim.wait, it reports this error. When I used sleep function like I said before, there is no error.
How to solve it, please help me TOT!
Re: real-time simulation and high fps
You say The problem is, only when I used sim.wait, it reports this error. But the error you mention is not at all related to
Cheers
sim.wait
...Cheers
Re: real-time simulation and high fps
Your error is
Check what your variables are (e.g. print them), and if they possibly are nil
Cheers
, that means in other words that instead of a string, you provided the nil argument to write. And it even tells you that the 9th argument is the culprit...bad argument #9 to 'write' (string expected, got nil)
Check what your variables are (e.g. print them), and if they possibly are nil
Cheers
Re: real-time simulation and high fps
Thank you coppelia. I deleted that line of code that reported "#9....." error, and then added sim.wait to the part that controls the movement of the car:coppelia wrote: ↑22 Jul 2021, 09:03 Your error is, that means in other words that instead of a string, you provided the nil argument to write. And it even tells you that the 9th argument is the culprit...bad argument #9 to 'write' (string expected, got nil)
Check what your variables are (e.g. print them), and if they possibly are nil
Cheers
Code: Select all
axes, buttons,rotAxes,slider,pov = simJoy.getData(0) ---transfer the joystick's data
if eventJustOccured then
eventJustOccured=nil
if(axes[2]>114 and -250<rotAxes[3] and rotAxes[3]<250) then
sim.wait(2)
axes[2]=-axes[2]/10000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*axes[2]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,(linearVelocityRight*axes[2]*v)/(s*wheelRadius))
elseif(axes[2]<-118 and -250<rotAxes[3] and rotAxes[3]<250) then
sim.wait(2)
axes[2]=-axes[2]/10000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*axes[2]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,(linearVelocityRight*axes[2]*v)/(s*wheelRadius))
elseif(131<rotAxes[3]) then
sim.wait(2)
rotAxes[3]=rotAxes[3]/50000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*rotAxes[3]*v/3)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,-(linearVelocityRight*rotAxes[3]*v/3)/(s*wheelRadius))
elseif(rotAxes[3]<-131) then
sim.wait(2)
rotAxes[3]=rotAxes[3]/50000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*rotAxes[3]*v/3)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,-(linearVelocityRight*rotAxes[3]*v/3)/(s*wheelRadius))
else
sim.setJointTargetVelocity(leftJointDynamic,0)
sim.setJointTargetVelocity(rightJointDynamic,0)
end
end
All of the code above are written in threaded script.