【PyChrono's API】Can I record video of the simulation? save IMU data to CSV?

113 views
Skip to first unread message

Shunya

unread,
Jun 16, 2023, 4:28:16 PM6/16/23
to ProjectChrono
Dear all,
I hava two questions about PyChrono's API.
Q1:Is it possible to record video of the simulation using PyChrono's API?
Q2: Is it possible to save IMU data to CSV using PyChrono's API?

Background of questions:
I am making the vehicle runnning model in PyChrono, referring to "demo_MBS_tracks.cpp".
I would like to save the data from IMU to CSV in order to check the running status.
And I would like to save the video of the nehicle running in the simulation.

Best regards,

Nevindu Batagoda

unread,
Jun 16, 2023, 5:24:35 PM6/16/23
to ProjectChrono
Hello Shunya,

For Q2, I don't believe there is a direct API call to do this but what you can do is, 
  1. Push a data access filter for the IMU (either for the accelerometer, gyro, or magnetometer) after constructing it. Ex:   acc.PushFilter(sens.ChFilterAccelAccess())
  2. Then during the simulation loop, access the IMU data and publish them into a CSV file. Here is an example of accessing and printing accelerometer data,
 while (ch_time < end_time):

        # Access the sensor data
        acc_data = acc.GetMostRecentAccelBuffer()
        # Check data is present
        # If so, print out the max value
        if acc_data.HasData():
            print("Accelerometer:",acc_data.GetAccelData().shape,"max:",np.max(acc_data.GetAccelData()))


Let me know if there's anything else.

Best,
Nevindu M. Batagoda

Luning Bakke

unread,
Jun 16, 2023, 5:38:08 PM6/16/23
to ProjectChrono

For Q1, there's an API, WriteImageToFile(filename) ,  for taking a snapshot of the irrlicht visualization at each rendering frame, then you can stitch together the pictures to make a video.

 

vis.BeginScene()

vis.Render()

vis.EndScene()

 

if (steps % render_steps == 0):

        filename = 'img_'+ str(render_frame).zfill(4) +'.jpg'

        vis.WriteImageToFile(filename)

        render_frame += 1

 

Thank you,

Luning

Shunya

unread,
Jun 19, 2023, 5:15:20 PM6/19/23
to ProjectChrono
Thanks both of you!
I would like to ask an additional question.

About Q1:
I entered the code you gave me, but only the first render was saved.
I saved the code to an image, and I need some advice.

About Q2:
I would like the acceleration for each calculation step to be added in csv during the simulation.
In the current code (image), only the latest acceleration is saved in csv.
This question is far from PyChrono, but I would like to get some advice on how to implement it.

Best regards,
Shunya

スクリーンショット 2023-06-19 161104.png

2023年6月16日金曜日 16:38:08 UTC-5 lfa...@wisc.edu:

Luning Bakke

unread,
Jun 20, 2023, 2:42:29 PM6/20/23
to ProjectChrono
Hello Shunya,

I took a look at these two lines,
render_step_size = 1.0 / 100
render_steps = math.ceil((1.0 / render_step_size) / step_size)
the render_steps will be ceil(100/step_size), which means an image is written every (100/step_size) time steps.

You probably want to do something like,

render_steps = math.ceil((render_step_size) / step_size)

Thank you,
Luning

Shunya

unread,
Jun 20, 2023, 2:55:26 PM6/20/23
to ProjectChrono
Dear Luning,
I could fix the Q1.
Thank you!

Best regards,
Shunya

2023年6月20日火曜日 13:42:29 UTC-5 lfa...@wisc.edu:
Reply all
Reply to author
Forward
0 new messages