Problem with save_configuration() using python

I am testing with 3.5 version board.

I tested it with Odrivetool and it’s clear.

Odrivetool is 0.5.2.post0.

There was a problem during the test for control in python.

The problem occurs in save_configuration().

So I tested it in console mode as below.

The test results were the same error for both python 3.9 and 3.8.

– test log –

Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import odrive
odrv0 = odrive.find_any()
odrv0.save_configuration()
Traceback (most recent call last):
File “”, line 1, in
File “D:\SVN\rbiotech\Mobility\motion\source\pythonProject1\venv\Lib\site-packages\odrive\pyfibre\fibre\libfibre.py”, line 582, in call
return run_coroutine_threadsafe(self._libfibre.loop, lambda: self.call(*args))
File “D:\SVN\rbiotech\Mobility\motion\source\pythonProject1\venv\Lib\site-packages\odrive\pyfibre\fibre\libfibre.py”, line 297, in run_coroutine_threadsafe
return future.result()
File “C:\Program Files\Python38\lib\concurrent\futures_base.py”, line 439, in result
return self.__get_result()
File “C:\Program Files\Python38\lib\concurrent\futures_base.py”, line 388, in __get_result
raise self._exception
File “D:\SVN\rbiotech\Mobility\motion\source\pythonProject1\venv\Lib\site-packages\odrive\pyfibre\fibre\libfibre.py”, line 292, in func_async
result = await result
File “D:\SVN\rbiotech\Mobility\motion\source\pythonProject1\venv\Lib\site-packages\odrive\pyfibre\fibre\libfibre.py”, line 549, in async_call
tx_buf, rx_chunk, is_closed = await agen.asend((tx_buf, self._rx_size - len(rx_buf), True))
File “D:\SVN\rbiotech\Mobility\motion\source\pythonProject1\venv\Lib\site-packages\odrive\pyfibre\fibre\libfibre.py”, line 471, in asend
return await self.anext()
File “D:\SVN\rbiotech\Mobility\motion\source\pythonProject1\venv\Lib\site-packages\odrive\pyfibre\fibre\libfibre.py”, line 500, in anext
raise _get_exception(status)
fibre.libfibre.ObjectLostError: the object disappeared

I waited for your help.
But I couldn’t wait too long.

So I analyzed the odrive source.

I found the following solution.

This solution appears to be working well.

I’d like to know if it’s right and if there are any other precautions.

Thank you in advance for your help.

– solution —
import odrive
import fibre.libfibre

odrv0 = odrive.find_any()

try:
odrv0.save_configuration()
except fibre.libfibre.ObjectLostError:
pass # Saving configuration makes the device reboot

print(str(self.odrv0.vbus_voltage))

1 Like

Hmm. You shouldn’t really get a big error like that, it should just say “Oh no! Odrv0 disappeared!”. But your try/catch works.

Yes, that’s right.
This is a big error.
So I asked for help.
What I’ve found is that if you use USB in the Odrive library, it will disappear due to reboot when you save or delete it.
At this time, the library confirmed that related errors occurred because there were no exceptions.
So I handled the exception with try/catch.

After additional reboots, you will need to rerun “odrv0 = drive.found_any()” to locate the USB.

Rebooting ODrive on save or erase is deliberate.

I just realized you’re using a script + find_any() to handle connectivity, not the odrivetool shell. This is correct behavior. See https://github.com/odriverobotics/ODrive/blob/fw-v0.5.3/tools/odrive/__init__.py#L54-L69