Hi there @cyclicalobsessive,
Q) So verifying: .volt() is thread-save but egpg.get_voltage_battery() is not?
EasyGoPiGo3.volt
method is thread-safe when the constructor of the EasyGoPiGo3
class is passed the use_mutex = True
parameter. Every other method that’s not explicitly defined in the EasyGoPiGo3
class is not thread-safe - so that means all the inherited methods from the GoPiGo3
class cannot be set to be thread-safe.
Therefore, since get_voltage_battery
is an inherited method from the GoPiGo3
class, it cannot be set to be thread-safe - not without external intervention such as creating another class to account for all inherited methods.
Q) Verifying: egpg.get_voltage_5v() is not thread-safe?
It’s the same story as the one for get_voltage_battery
method.
Q) The init_servo() does not have a use_mutex parm. Are the servo methods thread-safe?
When instantiating an EasyGoPiGo3
class and you pass the use_mutex
parameter, you are already setting the thread-safe-profile for all callable methods belonging to the EasyGoPiGo3
- excluding the inherited methods. That includes the EasyGoPiGo3.init_servo
method.
Q) If I want to use the underlying GoPiGo3 methods, do I have to create a MyThreadSafeEasyGoPiGo3(EasyGoPiGo3) class and overload the desired GoPiGo3 class methods? Will that work?
Pretty much yeah. I would suggest you read a sort of a 101 crash course on object programming in Python that can introduce you to this in just a few hours.
Q) I never have to call any kind of egpg.exit() and ds.exit() before ending a program?
Generally, I make sure the robot stops by calling the EasyGoPiGo3.stop
method and then I exit the program. More often than not, you are only looking after what the robot actually does, in physical terms.
Q) When I see the I2C issue, do I have to shutdown and restart, or is there a sequence of calls or console commands that I can issue to clean-start the GoPiGo3 board? (Rebooting RPi is not enough.)
Use a try/except/finally construct to avoid problems. Say you place this on your distance sensor. When it fails, you just re-instantiate the sensor and move on with the execution of your script. Though the distance sensor or any other sensor shouldn’t fail that easily. You can always experiment with the "AD1"
and "AD2"
ports of the GoPiGo3. They are generally more stable than its counterparts - that’s because the GoPiGo3 implements its own I2C protocol which is more stable than the Raspberry Pi’s one.
If there are any more questions, please feel free to leave a message here or just start another thread.
Thank you!