Start a new topic

Control the simulation with predefined code

Hi, I am trying to control the simulation with predefined code.

 

For example, one script will start the simulation and try to move the vehicle with certain engine speed/ direction. After 5 seconds, the vehicle position and speed will be saved and the simulation will be closed.

 

After that, the script will start another simulation with different speed/ direction combinations.

 

Shortly, we want to do some trial and error for the automated control of a vehicle.

I don't know how to implement that.

 

Regards-

Dipu Kabir


Hi,


in Vortex Studio, we made python scripting available for our application API. You can see an example in the tutorials, e.g. PyMechanismViewer.


if you base your script on that example, you'll be able to:

- create a setup file in the editor containing a dynamics engine (physics) and a graphics module (to see your vehicle running)

- load you content using ''application.getSimulationFileManager().loadObject()"

- instead of calling "application.run()", use "while application.update():"

- in the update loop, you can change inputs of your mechanism to make it moving, wait some time, gather outputs to verify that values are in the proper range...


You could also use the unittest module of python so that you can run several automated tests on the same vehicle as a batch.


Let me know if this is useful for you,


Regards,


Marc


2 people like this

Thank you for the suggestion. Your suggestion has solved most of my problem. 

The command  "application.update()" is working properly. 

I am building test cases with timed updates with the following code-

image


However, I am facing difficulties in saving the position of the vehicle. Variables like "Local Transform" or "World Transform" are probably containing multiple values- (x,y,z) and angles. Therefore, while saving them using the file-write or file-dump, only a portion of initials are saved. Is there any convenient way to save (x,y,z) values. The situation is illustrated with the following picture.

image




Thanking you,

Dipu Kabir

Hi,


I tried to print a VxTransform and it is actually not implemented so you would have to call for example getTranslation() and axis(int i) to get Vector3 values.


However, we actually use Matrix44 in general so you also should use it as input or output. 

Matrix44 is also used as transform of our main objects. 

Matrix44 is printed correctly in python, e.g.

 

>>> import VxSim
>>> trans = VxSim.VxTransform()
>>> print trans
<VxSim.VxTransform; proxy of <Swig Object of type 'Vx::VxTransform *' at 0x000000000292FCC0> >
>>> mat = VxSim.Matrix44()
>>> print mat
[[1 0 0 0]
 [0 1 0 0]
 [0 0 1 0]
 [0 0 0 1]]



Regarding your application script, we generally use the frame number which is more stable that the time:

while(app.update()):
    frame = app.getFrame()
    if (frame == ):
         do something...

 Regards,


Marc.




1 person likes this

Hi,

Thank you for suggestions.

 

Both 'trans' and 'mat' are showing the object description.

 

However, 'getTranslation' is working properly.

Say, I can print the position from following code-segment.

 

position = VxSim.getTranslation(mechanism.outputWorldTransform.value)

print(position)

 

Thanking you-

Dipu Kabir

Login to post a comment