Search code examples
cwebots

Data output from the device


I am working on a project,in which I need to extract data from the device: InertialUnit. I get a single value in real time, but I need data for the first 10 s and in 1 ms increments, or all the data for the entire cycle of the device. Please help me implement this if possible.


Solution

  • Webots controllers are like any other programs, so you can easily get the values of the inertial unit and save them in a file at each step. Here is a very simple example in Python:

    from controller import Robot
    
    robot = Robot()
    
    
    inertial_unit = robot.getInertialUnit('inertial unit')
    inertial_unit.enable(10)
    
    while robot.step(10) != -1:
        values = inertial_unit.getValues()
        with open('values.txt','a') as f:
            f.write('\n'.join(values))