Ultraborg calibration fails
Forums:
Hi, I'm running my Ultraborg off of a Raspberry Pi 3 B+. Things worked fine until I recently did a bit of rewiring. Now the Ultraborg code fails due to a divide by zero because the min and max read values of the servo positions always return same value (e.g., 3000). E.g., line 672 of Ultraborg.py: (self.PWM_MAX_1 - self.PWM_MIN_1) ends up being zero.
I'm using two servos, connected to #1 and #2. When I try to use the desktop Ultraborg Tuning GUI to set the min/max and center for each, the value returned for each servo in any position is usually 3000 (or sometimes 3180 or 3194 for servo #1).
By this I mean that I'm able to successfully rotate the servo to its minimum, center and maximum positions (the servo correctly moves to the desired position) but the stored value is always 3000 (or 3180 or 3194) for all three values. Resetting to default values sets them to 2000, Unset and 4000, but then trying to set them I again always end up with the same value (3000 or 3194).
I've just reinstalled the software but the result is the same.
When I run the ubTuningGui.py from the command line I think I may have found a clue: on line 267 there seems to be a TypeError:
File "./ubTuningGui.py", line 267, in poll self.lblServo1['text'] = '%d' % (servo1) TypeError: %d format: a number is required, not NoneType
I have no idea why this is happening now, and wasn't before. This doesn't seem to be related to my wiring changes, and I've not changed the installation of Python or anything. The Raspbian OS on this robot is stable (apart from doing regular updates).
piborg
Thu, 06/11/2020 - 17:09
Permalink
Problems reading values
It sounds like the script is not waiting long enough before reading back values from the UltraBorg. We have seen this happen sometimes after updating Raspbian.
If this is the case you can adjust the
UltraBorg.py
script so it waits a bit longer. Open the script in a text editor and look for theRawRead
function (around line 250). In the function there is a sleep call:Remove one of the zeros to increase the delay:
This should fix the
NoneType
issue with the tuning GUI. After that you will probably need to set the minimum and maximum servo positions again to get things working normally.furusato
Fri, 06/12/2020 - 10:26
Permalink
Your suggestion led to the actual problem
Hi, your suggestion was correct though things didn't exactly work out as was expected. I took a zero off of the delay with unfortunately no effect. I kept at this until the value was actually 0.1 before the ubTuningGui.py worked properly. I then tried an intermediate values of 0.05, which worked.
This long delay obviously makes the ubTuningGui rather halting in its response but will at least store the correct min/max/default values, so I' was back to functional again with my own code, but still curious as to what might be causing this.
I then looked at my wiring again. The Ultraborg was connected to the I2C bus using a wiring harness about 20cm long. On a lark I tried connecting it directly through a Pimoroni Breakout Garden slot to the Pi, which allowed me to go back to the original 0.000001 delay value.
So it looks like this problem was due to signal strength loss over a relatively long (20cm) wiring harness. I find this an interesting bit of information, and I'll watch for any other I2C irregulaties for other devices connected at the end of that harness, something I hadn't seen before with, e.g., other I2C (e.g., Breakout Garden) modules themselves have so far always worked at the end of that harness.
Thanks for the help!