UltraBorg and python3
Forums:
First of all - hello everyone. If my post is out of place I do apologise. Please let me explain the issue I am trying to deal with - I have read through the forum topics but it seems they are all a bit old (the most recent is months old) while I have a problem with the UltraBorg.py module and running it on Python3. The issue is with the print function which is used differently in Python3 compared to Python2. The version of UltraBorg.py file which I have managed to download seems to be using the old syntax for print. I can imagine rewriting every single line in the UltraBorg.py module that contains the print statement to make runnable in Python3 but this is not the dreamed start with UltraBord the least to say :) And I am not sure if, after making changes to print and making it work in Python3, something else will not pop up. So, if anyone could tell me if there is a newer version of the UltraBorg.py module that will for sure work in Python3 I would be more than grateful. And next thing - I have looked through the example code but I can't quite figure out how do I handle PWM using UltraBorg board? I have found some examples controlling DC motors but not quite so many examples showing how to control a motor using PWM.
Please advise.
piborg
Sat, 08/21/2021 - 09:19
Permalink
Python 3 and PWM
The first problem is easy to fix, we have a Python 3 version of the
UltraBorg.py
script that is ready to use :)To use this version you will need to change the import statement to
Then you can use it normally.
I think there is a little confusion with the second part. UltraBorg is designed to drive servo motors. For example: MG996R - 180 degree metal gear servo or SG90 - 180 degree micro servo.
Servo motors work by having a fixed power connection (in UltraBorg's case 5V) and providing a PWM signal on another connection to tell the motor where to move to.
The PWM connection is labelled "S = Signal" in this diagram.
The PWM output level for each servo is set using the
UB.SetServoPosition1
toSetServoPosition4
commands. It takes values from-1
to+1
for the position, with0
being in the middle.Since the exact PWM levels needed for each servo is slightly different you will need to set the range of movement using the Tuning GUI. Instructions can be found here: UltraBorg - Tuning.
UltraBorg is not designed to drive DC motors.
mariobros
Sat, 08/21/2021 - 13:59
Permalink
Clarification for the second part of my question.
Thank you very much for your response, it clarifies a lot, especially I am so happy to see that the UltraBorg module is also available in Python3-compatible version :)
Now, to clarify the second part of my question which you referred to as "a bit confusing" :) The thing is that I know that "UltraBorg is not designed to drive DC motors". I am using it for my drone application where the UltraBorg is assumed to be able to control brushless motors through ESC. I saw a mention on the Raspberry PI forum that UltraBorg can be used for this purpose and I believe before I decided to buy the board, I also checked the PiBorg forum and found somewhere a discussion where the comment was saying that controlling brushless motors speed should be doable using UltraBorg. As you surely know, all that ESCs need to control motor speed is PWM signal. Battery is LiPO package so it is not to be connected to UltraBorg anywhere, UltraBorg must only generate the PWM signal. So, in the diagram you included (which I have found some time ago) where you put the servo in my application goes the ESC. All I need is to know which specific functions to use to generate PWM signal. I believe I can figure this out myself after some research but maybe you already know this so it would save me A LOT of time :)
Thank you in advance for any help.
piborg
Sat, 08/21/2021 - 14:46
Permalink
Raw PWM signals
That makes more sense, thanks :)
There are four functions that allow you to directly alter the PWM signal outputs:
UB.CalibrateServoPosition1
toUB.CalibrateServoPosition4
.These functions ignore any calibration settings and directly set the duty cycle for the PWM outputs. The values are from
0
to0xFFFF
(or65535
in decimal) and must be given as integers (typeint
).For example this snippet sets each output to a different duty cycle.
The PWM frequency is hard-coded into the UltraBorg and cannot be changed.
For your usage I would also recommend setting the limits so that the UltraBorg starts with all four outputs as low as possible on power up. This can be done with the following code:
The values are saved to the UltraBorg so they will take effect without needing to be set each time.
mariobros
Sat, 08/28/2021 - 14:42
Permalink
Hello. Just to update all
Hello. Just to update all potentially interested - indeed, the UltraBorg board very smoothly controlls brushless motors in my quadcopter project. Since Raspberry Pi has only 2 dedicated PWM outputs, for those wanting control more than 2 motors - this board will do the job.
Once again thank you very much for all help provided. If I have any other questions I will come back but for now this thread can be closed :)
Best
M.
mariobros
Sat, 08/21/2021 - 15:53
Permalink
Bless you :)
Wow! You really made my day :) I don't know how to thank you for this but I am really grateful :) I will try to integrate your examples with my code and we'll see what happens ;) So far integration of the UltraBorg board with Raspberry PI was flawless, the module appears under 36 address along with my Altimu module. The UB.Init() worked without any problem, no errors returned so I believe the other functions will work, too :)
Once again, thank you very much ;)