Export data to CSV file

Hi,

I can’t find any option to export or capture data like vel_estimate? any ideas how to do it ?

Adrian.

There is no option that I know of right now, but…

Launch ODrive tool then paste these functions into the interpreter:

 # Convert to nested list structure for CSV output (outputs as rows instead of columns)
 def convert_list_for_csv(input_list):
     return list(map(lambda element: [element], input_list))

# Output a given list to a CSV file
def write_output_to_file(input_list, file_name):
    output = convert_list_for_csv(input_list)

    with open(file_name, "w", newline='') as csv_file:
        writer = csv.writer(csv_file, delimiter=',')
        writer.writerows(output)
    print("Output written to", file_name)

Now when you sample your data (using odrivetool), just save it to a list:

# Move and record velocity estimate
from time import sleep
velocity_list = []
def move_and_log(position):
    odrv0.axis0.controller.input_pos(position)
    # trajectory_done requires using the motion planner but you could use a different conditional
    # such as vel_estimate > x or elapsed time
    while not odrv0.axis0.controller.trajectory_done:
        velocity_list.append(odrv0.axis0.encoder.vel_estimate)
        sleep(0.01) # Need to prevent overloading the ODrive's communication interface. Increase / decrease as needed

Hope this helps

2 Likes