New to Python new to Programming

Comments & issues
Post Reply
Baso
Fresh meat
Posts: 3
Joined: Wed Feb 10, 2021 5:56 am
Contact:

New to Python new to Programming

Post by Baso »

Hi all

I am a complete novice to programming any suggestions or websites i can visit to learn the basics of Python programming.
I am trying to control the speed of a motor so it can be easily controlled by a dial to part of an experimental set up to create nano bubbles.
I have bought ..
DCM4100_0 - 42DMW61 NEMA17 Gearless Brushless Motor
1
HUB0000_0 - VINT Hub Phidget

HIN1101_0 - Dial Phidget

DCC1100_0 - Brushless DC Motor Phidget

So i have all the gear but no idea!!
In at the deep end is the best way? :lol:
Thanks again for any help you can give.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: New to Python new to Programming

Post by mparadis »

Start by going to the product page for each of your Phidgets and reading the "User Guide" tab (HUB0000, HIN1101, and DCC1100).

By the end of those guides, you should be able to individually test each device in the Phidget Control Panel and see them working.

The next step would be to get some Python sample code for each device, and individually test those. Go to the Python page in our documentation to get it set up. Then, go to the "Code Samples" tab on the HIN1101 and DCC1100 product pages and download the Python sample code for each (you don't need a sample for the HUB0000 since you're just using it as an interface to control the other two devices).

Once you get the code samples working, you're ready to start making changes to them. You can read our Phidget Programming Basics guide to get an idea of how Phidgets work with Python.

Generally, here's how I'd write the program you're describing:

- Start with the HIN1101's encoder example
- Add code in the "main" function that declares and opens a BLDC object, similar to how it's done in the DCC1100's example code
- Make the BLDC object available inside the "onPositionChange" event as described in the "Referencing Other Phidgets from Events" section of this page.
- Add code in the "onPositionChange" function that sets the target velocity of the BLDC motor based on either the total position or the position change of the HIN1101's encoder. (For total position, you'll have to create a variable to keep track of the position as the position change events come in)
- Don't forget to use "print" statements to put helpful information on the screen, such as the current motor velocity whenever the dial is turned. This will help you debug and tweak the program to your specifications.

As for general programming guides for python, I have no specific recommendations, but there's lots of resources out there since python is one of the most widely used languages. I know this seems overwhelming but feel free to ask us questions if you get stuck along the way.
Baso
Fresh meat
Posts: 3
Joined: Wed Feb 10, 2021 5:56 am
Contact:

Re: New to Python new to Programming

Post by Baso »

Hello

Thanks for your reply i shall get to work on this on Monday, i am a mechanical engineeer steping into this world so it is a little overwelming so thankyou for your help.
I was thinking of not using the speed controller and just controling the RPM of the motor in a programme is this something that is easy to do?
So just typing in a Rpm and the motor turns?
Thanks again.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: New to Python new to Programming

Post by mparadis »

Controlling RPM is actually more complicated than controlling speed in terms of the default unit of velocity for a motor because it requires an extra calculation and knowledge of the motor's position.

The default units used in controlling the velocity of a brushless DC motor using the DCC1100 is duty cycle. Duty cycle varies from -1.0 (full speed reverse) to 1.0 (full speed forward). This is the default for brushless controllers because it's essentially the amount of power being supplied to the motor.

In order to determine the motor's current RPM, you need to know the position of the motor. You can get this using the getPosition function, but the units will be in commutations measured from the BLDC motor's hall effect sensors. In order to convert into degrees, you need to know how many commutations are in a single rotation. In the case of the DCM4100, it's and 8-pole motor with three phases, which means 24 unique positions in one rotation. So if you divide the number you get from getPosition by 24, you'll get the number of rotations. Combine this with a timer function in your program, and you can calculate the RPM.
Baso
Fresh meat
Posts: 3
Joined: Wed Feb 10, 2021 5:56 am
Contact:

Re: New to Python new to Programming

Post by Baso »

Hi Again

I think i am falling at the first hurdle here what am i doing wrong?
Ive installed all the python modules but it is saying it can find them.
Thanks.
Attachments
Screenshot 2021-02-15 123251.png
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: New to Python new to Programming

Post by mparadis »

Is example.py in the same directory where you installed the Phidgets python modules? You should be able to see a "Phidget22" folder in the same directory example.py is in.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 29 guests