Page 1 of 1
Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Mon Jan 29, 2018 4:06 pm
by greenmax
Hi,
I am working on a setup where I want to turn a stepper motor by 1 degree at a time. For this, I plan to use the following equipment:
Motor:
https://www.phidgets.com/?tier=3&catid= ... prodid=346
Encoder:
https://www.phidgets.com/?tier=3&catid= ... prodid=404
Controller:
https://www.phidgets.com/?tier=3&catid= ... rodid=1029
I plan to drive this using Python27 code. I wanted to conform if this is possible using the Phidgets22 library. Also, are there any sample projects or code templates that I can use.
Thanks
Re: Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Tue Jan 30, 2018 8:43 am
by mparadis
Yes, what you've described is possible with the products you've selected in python. To make the motor rotate one degree at a time, you just have to do a simple calculation:
The 3327 motor has a 1.8 degree step angle, and a 26 103/121 : 1 gearbox. The 1067 measures position in 16th steps, so divide 1.8 by 16. Then divide by the gear ratio, which results in 0.004° per 16th step. This means you'll want to increase position by 239 for every degree you want the motor to move (if you want to be precise when moving multiple degrees, add up multiples of 238.678 and round to the nearest integer)
You can take a look at the
python example "Stepper" to show how to open the stepper object and give a target position.
Re: Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Tue Feb 06, 2018 5:36 pm
by greenmax
Got it. Thank you. I am able to run the system using Python as well.
Now I am trying to implement a closed loop controller using the HKT22 encoder.
What I am not sure is how to stop the stepper motor when the appropriate number of pulses have been received from the encoder. One way would be to use the setCurrentPosition function.
Can you suggest a better way of doing so? Or do you think it is an overkill to use an encoder with this motor.
Thanks
Re: Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Wed Feb 07, 2018 9:23 am
by mparadis
It's completely reasonable to want to use an encoder for closed loop control on a stepper motor; they are not infallible and can sometimes misstep, especially when external forces might momentarily exceed holding torque.
You could implement full PID control like what is described in
this article (although the motor used here is a DC motor, you could do something similar using stepper CONTROL_MODE_RUN and setting a target velocity instead of a duty cycle).
You could alternatively program a simpler control loop that constantly keeps track of how many encoder pulses it should be seeing based on the target you gave it and make necessary corrections. For example, let's say you tell the motor to rotate 180°. From the math mentioned in my previous post, that would mean you should set target position to 42962. Now, the encoder you're using has 300 cycles per revolution. For a 180° rotation, we'd expect to see 150 quadrature cycles (or 600 pulses- some encoder interfaces measure cycles and others measure pulses). Assuming your encoder interface measures pulses, you could wait until your stepper moves to position 42962 and then compare the actual encoder position with the expected encoder position (600). If the actual encoder position ended up being 500, you could tell the stepper to move another 100 worth, which you could convert into degrees and then back into motor position with the same math. If you continue doing this, you should eventually reach a point where the target and actual encoder positions match and the motor can then stop.
Re: Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Wed Oct 03, 2018 5:31 pm
by bernasunifei
Hello,
I'm not being able to set the control mode to run.
Could you please show me a snippet of the code needed to do that?
Thanks!
Re: Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Thu Oct 04, 2018 9:10 am
by mparadis
It depends on what language you're using, but for example in python:
Code: Select all
ch.setControlMode(StepperControlMode.CONTROL_MODE_RUN)
Which you would use after the channel has successfully attached, where ch is the handle for the stepper channel. For other languages you can see what the function and enumeration are named in the
API documentation.
Re: Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Fri Oct 12, 2018 2:42 pm
by bernasunifei
Thanks for your reply.
I am programming in Phyton, so that was a great guess!
However, when I tried to use the code you proposed, I got the following error:
File "Controller_Rev16_dev.py", line 331, in SteeringControl
ch.setControlMode(StepperControlMode.CONTROL_MODE_RUN)
NameError: global name 'StepperControlMode' is not defined
I'm including the following libraries:
from Phidget22.Devices.Stepper import *
from Phidget22.PhidgetException import *
from Phidget22.Phidget import *
from Phidget22.Net import *
Can you identify the problem with the information I'm giving?
Thanks in advance!
Re: Newbie question: Phidgets22 + PhidgetStepper Bipolar
Posted: Fri Oct 12, 2018 3:22 pm
by jdecoux
It seems you will need to import
Code: Select all
from Phidget22.ControlMode import *
and use