need help to start with stepper motor control 1062

Supporting 2.7 and 3.2+
J12
Phidgetsian
Posts: 5
Joined: Tue Mar 20, 2012 7:10 am
Contact:

need help to start with stepper motor control 1062

Postby J12 » Tue Mar 20, 2012 7:20 am

Hello,
I try to use a 1062 stepper motor controller but as i never use python before i have some troubles. ( I am using python 3.2.2)
With the phidget control panel it works very well. The motor move.
But when i try the sample code it doesn't work and i don't find why.

I have extracted the “Phidgets” directory from the Python Module into the lib\site-packages\ directory. Then in the IDLE i wrote this :

#Basic imports
from ctypes import *
import sys
from time import sleep
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, InputChangeEventArgs, CurrentChangeEventArgs, StepperPositionChangeEventArgs, VelocityChangeEventArgs
from Phidgets.Devices.Stepper import Stepper

There is no error.
Then i wrote this :

#Create a stepper object
try:
stepper = Stepper()
except RuntimeError as e:
print("Runtime Exception: %s" % e.details)
print("Exiting....")
exit(1)

It don't work. I have this error message :

Traceback (most recent call last):
File "<pyshell#8>", line 2, in <module>
stepper = Stepper()
NameError: name 'Stepper' is not defined

Can you help me ?

Thank you,

Julien

J12
Phidgetsian
Posts: 5
Joined: Tue Mar 20, 2012 7:10 am
Contact:

Re: need help to start with stepper motor control 1062

Postby J12 » Thu Mar 22, 2012 2:41 pm

I try, i try but it doesn't work.

Now, when i try to use the sample code i have this :

Opening phidget object....
Waiting for attach....
Stepper 92042 Attached!|------------|----------------------------------|--------------|------------|

Stepper 92042: Motor 0 -- Velocity: 0.000000|- Attached -|- Type -|- Serial No. -|- Version -|

Stepper 92042: Motor 1 -- Velocity: 0.000000|------------|----------------------------------|--------------|------------|

Stepper 92042: Motor 2 -- Velocity: 0.000000|- True -|- Phidget Unipolar Stepper Controller 4-motor -|- 92042 -|- 101 -|

Stepper 92042: Motor 3 -- Velocity: 0.000000|------------|----------------------------------|--------------|------------|

Number of Motors: 4
Set the current position as start position...
Set the motor as engaged...
Stepper 92042: Motor 0 -- Position: 0.000000
The motor will run until it reaches the set goal position...
Phidget Exception 4: Invalid argument passed to function.
Exiting....
Traceback (most recent call last):
File "C:\Users\Julien\Desktop\Stepper-simple.py", line 141, in <module>
exit(1)
File "C:\Python32\lib\site.py", line 362, in __call__
raise SystemExit(code)
SystemExit: 1

As i am newbie in python, i don't find what "Phidget Exception 4: Invalid argument passed to function." refers to, and what to do to solve the probleme...

Julien

mjskier
Phidgetly
Posts: 24
Joined: Mon Feb 13, 2012 10:31 pm
Contact:

Re: need help to start with stepper motor control 1062

Postby mjskier » Thu Mar 22, 2012 3:49 pm

J12 wrote:As i am newbie in python, i don't find what "Phidget Exception 4: Invalid argument passed to function." refers to, and what to do to solve the probleme...


This isn't really a python error. This is an error from phidgets21 library that you get when you set velocity or acceleration to a value that is too large or too small.
You need to find out what the minimum and maximum values you can set for acceleration and velocity. The example python program probably shows you how to do it (the Ruby example does)

J12
Phidgetsian
Posts: 5
Joined: Tue Mar 20, 2012 7:10 am
Contact:

Re: need help to start with stepper motor control 1062

Postby J12 » Fri Mar 23, 2012 4:39 am

Thank you for your hlep !

Ok, i think i am starting to understand.

The problem comes from one ot these lines :

stepper.setAcceleration(0, 87543)
stepper.setVelocityLimit(0, 6200)
stepper.setCurrentLimit(0, 0.26)

I want to move the motor number zero so the first number is ok. I have to find wich value are correct instead of 87543,6200 and 0.26.

I think i can find them for exemple with stepper.getAcceleration...
I tried ti add this to the code :

try:
stepper.getAccelerationMax(0)

except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)

But it doesn't show me the the acceleration max and the programme goes on until the error.

Julien

J12
Phidgetsian
Posts: 5
Joined: Tue Mar 20, 2012 7:10 am
Contact:

Re: need help to start with stepper motor control 1062

Postby J12 » Fri Mar 23, 2012 6:11 am

I tried to supress these lines in the code sample :
stepper.setAcceleration(0, 87543)
stepper.setVelocityLimit(0, 6200)
stepper.setCurrentLimit(0, 0.26)

Now, the motor moves.

But at the end of the programme this line make an error :
chr = sys.stdin.read(1)

Definitly not easy to understand for me...

Julien

mjskier
Phidgetly
Posts: 24
Joined: Mon Feb 13, 2012 10:31 pm
Contact:

Re: need help to start with stepper motor control 1062

Postby mjskier » Fri Mar 23, 2012 7:03 am

Looks like somebody has run into the same error before:
http://www.phidgets.com/phorum/viewtopic.php?f=26&t=5278

J12
Phidgetsian
Posts: 5
Joined: Tue Mar 20, 2012 7:10 am
Contact:

Re: need help to start with stepper motor control 1062

Postby J12 » Fri Mar 23, 2012 1:32 pm

Yes !

This link is very helpfull.
Now all is working fine for me.

Thank you.

Julien :D


Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests