How to speed up the simulation without accuracy loss?

Typically: "How do I... ", "How can I... " questions
Post Reply
wode
Posts: 18
Joined: 12 Oct 2019, 03:47

How to speed up the simulation without accuracy loss?

Post by wode »

Hello,
I try to use vrep to do some Quadricopter simulations.
I use matlab to run the control algorithm and vrep to simulation. The point is that there are more than 50 Quadricopters in my vrep scene and the simulation process is very very slow. But i check my computer and find that the CPU utilization, memory utilization, and GPU utilization of my computer are less than 70%.
So i want to know is there any method to speed up the simulation without accuracy loss? If i upgrade my computer which hardware is the most important one? Or I must buy a server to do some more than 100 Quadricopters in simulation?
Thanks a lot.

coppelia
Site Admin
Posts: 8125
Joined: 14 Dec 2012, 00:25

Re: How to speed up the simulation without accuracy loss?

Post by coppelia »

Hello,

how do you simulate your quadcopters? Do you simulate/emulate the wind particles? This will of course drastically slow down the simulation. Do you display and rotate the propellers? For such a large number of quadcopters or robots, it is usually a good idea to abstract away as much as possible, to gain simulation speed. You could simply use a cylinder as a representation of your quadcopter, and appropriately apply the thrust forces to it. This will be very effective for simulation.
Always check which part of the simulation is taking up most CPU time, then you have identified the bottleneck, and can start optimizing your simulation model.

Cheers

wode
Posts: 18
Joined: 12 Oct 2019, 03:47

Re: How to speed up the simulation without accuracy loss?

Post by wode »

Hello.

Thank you so much for your answer!And there are still some questions.
FIrstly, I don't know what are wind particles and how could i turn down the particles.
What's more, if i ignore the wind particles, how could it influence my simulation?
Then where could i find the cylinder ? The quadcopters in my simulation must fly, are the cylinder are good substitutes?

Sincerely.

coppelia
Site Admin
Posts: 8125
Joined: 14 Dec 2012, 00:25

Re: How to speed up the simulation without accuracy loss?

Post by coppelia »

If you look at the demo model in models/robots/mobile/Quadricopter.ttm you'll see that particles are being simulated. You can turn them off in the user parameters. They really are most of the times not needed (they could slightly disturb another object below it).

You can create a cylinder with [Menu bar --> Add --> Primitive shape --> Cylinder]

Whether cylinders are a good substitute depends on many things that you best know. But one question is: should your quadcopter ever collide with an obstacle? And if yes, does the collision response need to be very accurate?

Cheers

wode
Posts: 18
Joined: 12 Oct 2019, 03:47

Re: How to speed up the simulation without accuracy loss?

Post by wode »

Thanks again.
I open the Script Parameters find there are three parameters here: " particlesAreVisible", "fakeShadow", "simulateParticles". Would it make a big difference to my simulation if i turn all of them off?
Then i have some questions in quadcopter simulation. I study the control algorithm in the quadricopter script carefully. I find the kernel of control algorithm is to calculating the distance between the Quadricopter_base and Quadricopter_target. So at the first of the Quadricopter script, the base is detatched to the parents .
However, I want to give velocities (vx,vy) to control the Quadricopters instead of moving the Quadricopter_target, so i firstly comment out the detach line then add my control codes to the horizontal control of quadcopter. The codes are as follows:
vre1 is the velocity of Quadricopter_base. inputV is input velocity of quadricopter . ax, ay are my control params which added to the alpahaCorr and betaCorr.

Code: Select all

    vrel=sim.getObjectVelocity(d);
    vxe=inputV[1]-vrel[1]
    ax=0.1*vxe+0.5*(vxe-vxeo)
    vxeo=vxe
    vye=inputV[2]-vrel[2]
    ay=0.1*vye+0.5*(vye-vyeo)
    vyeo=vye
     ...
    alphaCorr=alphaCorr+sp[2]*0.005+1*(sp[2]-psp2+ay)
Then the simulation shows that quadricopters fly normally for a while, more than 10 seconds, but suddenly lose conrol. I check the inputV of Quadricopters and there is no mutation in the velocities. So i can't find where is the problem, could you give me some advices?

coppelia
Site Admin
Posts: 8125
Joined: 14 Dec 2012, 00:25

Re: How to speed up the simulation without accuracy loss?

Post by coppelia »

Yes, it would make a big difference, probably. The easiest is for you to try it!

The default algorithm of the quadcopter is a very simple algorithm, just for demo purposes. You should rewrite things entirely if you want something better, and not rely on that algorithm. Basically, you need to write a controller that takes some inputs, and that computes the 4 thrust forces of your quadcopter.

Cheers

wode
Posts: 18
Joined: 12 Oct 2019, 03:47

Re: How to speed up the simulation without accuracy loss?

Post by wode »

Hi,
I try to write a controller to control the quadricopter but i don't know what particlesTargetVelocities means.
For example, if i just want the UAV to fly along the X-axis, how could i set the value of particlesTargetVelocities[1],particlesTargetVelocities[2],particlesTargetVelocities[3],particlesTargetVelocities[4] to control the motors?

Thanks a lot!

coppelia
Site Admin
Posts: 8125
Joined: 14 Dec 2012, 00:25

Re: How to speed up the simulation without accuracy loss?

Post by coppelia »

Forget about the particle velocities (since you won't emulate the wind produced by the quadcopter). Simply compute the 4 thrust forces that are generated by the 4 propellers. As previously stated, the simplest model would be a cylinder that has a script attached. The script will compute and apply, in each simulation step, 4 forces representing the quadcopter thrust forces. You'll have to use sim.addForce.

Cheers

Post Reply