Products for USB Sensing and Control
It is currently Thu May 23, 2013 11:49 am

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Servo not moving
PostPosted: Thu Oct 21, 2010 3:44 pm 
Offline
Phidgetsian

Joined: Thu Oct 14, 2010 2:07 pm
Posts: 7
Hi there.
I seem to be having trouble getting my servo motor to move.
I have been trying the advanced servo and normal servo with no luck.
I am doing a robotics course at school and the teacher sent me home with a webcam mounted on a pivoting platform controlled by a HITEC HS322HD servo motor connected to an AdvancedServo board (1061) on the 0th pins.
I am programming them in Python on Ubuntu Linux, and I am very sure all the libraries are installed.

The AdvancedServo-simple.py test script ran smoothly, reporting that it was moving the position of the servo, but I did not see any physical results.
I have tried moving the placement of the wires over the pins, though that has not changed anything either.

Any help would be appreciated.


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Fri Oct 22, 2010 9:07 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Do you have the power supply plugged into the 1061 board? Have you set enabled to true for the servo in your sourcecode?

-Patrick


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Thu Oct 28, 2010 7:55 am 
Offline
Phidgetsian

Joined: Thu Oct 14, 2010 2:07 pm
Posts: 7
According to the AdvancedServo documentation, there is no function such as "setEnabled" or "enabled". The source in AdvancedServo-simple.py does in fact call setEngaged for the 0th port, as I would want it to.
Despite this, the servo is not moving.


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Thu Oct 28, 2010 9:50 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Is the servo plugged in the right way? Are you sure the board is plugged into it's 12v power supply?

-Patrick


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Fri Oct 29, 2010 10:03 am 
Offline
Phidgetsian

Joined: Thu Oct 14, 2010 2:07 pm
Posts: 7
Yes it is certainly plugged into the power supply which is in turn plugged into an AC power outlet.


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Fri Oct 29, 2010 10:28 am 
Offline
Phidget Mastermind

Joined: Wed Mar 28, 2007 11:50 am
Posts: 184
Here is a modified version of the AdvancedServo Python example that should take the motor to its extreme positions at a faster rate. The values that were being used were very slight and may not be very visible when moving the platform.

If this still doesn't function, if you have a windows based PC you can test on, try installing the Phidgets libraries on there and run the test application from the Phidget Control Panel.

One thing to look at would be the value for the current to that motor index.

Code:
#!/usr/bin/env python

"""Copyright 2010 Phidgets Inc.
This work is licensed under the Creative Commons Attribution 2.5 Canada License.
To view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
"""

__author__ = 'Adam Stelmack'
__version__ = '2.1.7'
__date__ = 'May 17 2010'

"""
This is a very simple example of the AdvancedServo's capabilities.  Please study the Python API manual as well as the AdvancedServo product
manual to get a better idea as to the full capabilities of this device.
"""

#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, CurrentChangeEventArgs, PositionChangeEventArgs, VelocityChangeEventArgs
from Phidgets.Devices.AdvancedServo import AdvancedServo
from Phidgets.Devices.Servo import ServoTypes

#Create an advancedServo object
try:
    advancedServo = AdvancedServo()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)

#stack to keep current values in
currentList = [0,0,0,0,0,0,0,0]
velocityList = [0,0,0,0,0,0,0,0]

#Information Display Function
def DisplayDeviceInfo():
    print("|------------|----------------------------------|--------------|------------|")
    print("|- Attached -|-              Type              -|- Serial No. -|-  Version -|")
    print("|------------|----------------------------------|--------------|------------|")
    print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (advancedServo.isAttached(), advancedServo.getDeviceName(), advancedServo.getSerialNum(), advancedServo.getDeviceVersion()))
    print("|------------|----------------------------------|--------------|------------|")
    print("Number of motors: %i" % (advancedServo.getMotorCount()))

#Event Handler Callback Functions
def Attached(e):
    attached = e.device
    print("Servo %i Attached!" % (attached.getSerialNum()))

def Detached(e):
    detached = e.device
    print("Servo %i Detached!" % (detached.getSerialNum()))

def Error(e):
    source = e.device
    print("Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))

def CurrentChanged(e):
    global currentList
    currentList[e.index] = e.current

def PositionChanged(e):
    source = e.device
    print("AdvancedServo %i: Motor %i Position: %f - Velocity: %f - Current: %f" % (source.getSerialNum(), e.index, e.position, velocityList[e.index], currentList[e.index]))
    if advancedServo.getStopped(e.index) == True:
        print("Motor %i Stopped" % (e.index))

def VelocityChanged(e):
    global velocityList
    velocityList[e.index] = e.velocity

#Main Program Code

#set up our event handlers
try:
    advancedServo.setOnAttachHandler(Attached)
    advancedServo.setOnDetachHandler(Detached)
    advancedServo.setOnErrorhandler(Error)
    advancedServo.setOnCurrentChangeHandler(CurrentChanged)
    advancedServo.setOnPositionChangeHandler(PositionChanged)
    advancedServo.setOnVelocityChangeHandler(VelocityChanged)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Opening phidget object....")

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

print("Waiting for attach....")

try:
    advancedServo.waitForAttach(10000)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        advancedServo.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    DisplayDeviceInfo()

try:
    print("Setting the servo type for motor 0 to HITEC_HS322HD")
    advancedServo.setServoType(0, ServoTypes.PHIDGET_SERVO_HITEC_HS322HD)
    #Setting custom servo parameters example - 600us-2000us == 120 degrees, velocity max 1500
    #advancedServo.setServoParameters(0, 600, 2000, 120, 1500)
    print("Speed Ramping state: %s" % advancedServo.getSpeedRampingOn(0))
    print("Stopped state: %s" % advancedServo.getStopped(0))
    print("Engaged state: %s" % advancedServo.getEngaged(0))
   
    print("Working with motor 0 only...")
   
    print("Adjust Acceleration to maximum: %f" % advancedServo.getAccelerationMax(0))
    advancedServo.setAcceleration(0, advancedServo.getAccelerationMax(0))
    sleep(2)
   
    print("Adjust Velocity Limit to maximum: %f" % advancedServo.getVelocityMax(0))
    advancedServo.setVelocityLimit(0, advancedServo.getVelocityMax(0))
    sleep(2)
   
    print("Engage the motor...")
    advancedServo.setEngaged(0, True)
    sleep(2)
   
    print("Engaged state: %s" % advancedServo.getEngaged(0))
   
    print("Move to position positionMin...")
    advancedServo.setPosition(0, advancedServo.getPositionMin(0))
    sleep(5)
   
    print("Move to position PositionMax...")
    advancedServo.setPosition(0, advancedServo.getPositionMax(0))
    sleep(5)
   
    print("Adjust Acceleration to 50...")
    advancedServo.setAcceleration(0, 50.00)
    sleep(2)
   
    print("Adjust Velocity Limit to 50...")
    advancedServo.setVelocityLimit(0, 50.00)
    sleep(2)
   
    print("Move to position PositionMin...")
    advancedServo.setPosition(0, advancedServo.getPositionMin(0))
    sleep(5)
   
    print("Disengage the motor...")
    advancedServo.setEngaged(0, False)
    sleep(2)
   
    print("Engaged state: %s" % advancedServo.getEngaged(0))
   
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        advancedServo.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)

print("Press Enter to quit....")

chr = sys.stdin.read(1)

print("Closing...")

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

print("Done.")
exit(0)


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Tue Nov 02, 2010 3:08 pm 
Offline
Phidgetsian

Joined: Thu Oct 14, 2010 2:07 pm
Posts: 7
I have tried running the code you posted, as well as the example AdvancedServo-simple.py code under both Windows and Linux now and neither seem to be causing the servo to move.

Again, the pins are aligned with the correct wires on the 0th pins, the power source is fully connected, the USB input is securely placed in its socket and the USB 2.0 port on my computer, the code is verifying that the servo is connected, but there is still no movement upon execution of the setPosition() function.


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Tue Nov 02, 2010 4:14 pm 
Offline
Phidget Mastermind

Joined: Wed Mar 28, 2007 11:50 am
Posts: 184
Are you able to test it on a windows based PC using the Phidgets Control Panel?


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Thu Nov 04, 2010 8:42 am 
Offline
Phidgetsian

Joined: Thu Oct 14, 2010 2:07 pm
Posts: 7
Yes, I have been playing around with the UI for a while to no avail.
Despite my changing the Velocity with the slider, the "Actual Velocity" value remains 0. When I change the Target Position slider, the "Actual Position" value changes to that value immediately but the servo does not actually move.
I've tried changing values around with "Engaged" set to true (the checkbox) and with it set to false. No luck.


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Thu Nov 04, 2010 10:46 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Well it may be a bad board, or a bad power supply, or a bad servo. You should probably contact the seller and arrange for a warranty replacement. If you bought directly from phidgets.com, contact support@phidgets.com.

-Patrick


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Mon Dec 13, 2010 7:28 am 
Offline
Phidgetsian

Joined: Thu Oct 14, 2010 2:07 pm
Posts: 7
I recently got the servos to move (a few weeks ago), and was controlling them with sliders from WxWidgets.
Currently, I am trying to use pygame to control the motors via keyboard input, but for some reason I get an error when I call AdvancedServo.setPosition().
Here's the code:

Code:
import sys
from ctypes import *

import pygame
from pygame.locals import *
from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
from Phidgets.Events.Events import *
from Phidgets.Devices.AdvancedServo import AdvancedServo
from Phidgets.Devices.Servo import ServoTypes

servo = AdvancedServo()
print("Please connect servo now")
servo.openPhidget()
try:
    servo.waitForAttach(10000)
except PhidgetException as e:
    print(e.details)
    print("It is likely that this program needs higher permissions to run.")
    servo.closePhidget()
    exit(1)
   
for i in xrange(2):
    try: servo.setServoType(i, ServoTypes.PHIDGET_SERVO_HITEC_HS322HD)
    except PhidgetException as e:
        print(e.details)
        print("ERROR1")
        exit(1)
    try: servo.setAcceleration(i, servo.getAccelerationMax(i))
    except PhidgetException as e:
        print(e.details)
        print("ERROR2")
        exit(1)
        #try: servo.setVelocityLimit(i, servo.getVelocityMax(i))
        #except PhidgetException as e:
         #   print(e.details)
          #  print("ERROR3")
           # exit(1)
    try: servo.setEngaged(i, True)
    except PhidgetException as e:
        print(e.details)
        print("ERROR4")
        exit(1)
    try: servo.setPosition(i, servo.getPositionMin(i))
    except PhidgetException as e:
        print(e.details)
        print("ERROR5")
        exit(1)

pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption('Pygame Caption')
pygame.mouse.set_visible(0)

done = False
y_val = servo.getPosition(1)
x_val = servo.getPosition(0)
while not done:
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_w:
                y_val = servo.getPosition(1) + 5.0
            if event.key == K_s:
                y_val = servo.getPosition(1) - 5.0
            if event.key == K_a:
                x_val = servo.getPosition(0) - 5.0
            if event.key == K_d:
                x_val = servo.getPosition(0) + 5.0
            if event.key == K_ESCAPE:
                done = True
            servo.setPosition(0, y_val)
            servo.setPosition(1, x_val)

for i in xrange(2):
        servo.setEngaged(i, False)
servo.closePhidget()


By the looks of it, there should not be a problem since I am calling set position with a self value (servo), an index (0 for x, 1 for y), and a float(double) value, x/y_val which is initialised with getPosition().

Why is the servo.setPosition() function telling me I am providing improper input?
*note that I didn't use any handlers in my working version using wxWidgets, because I didn't care to write so much boilerplate and it worked fine nonetheless


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Mon Dec 13, 2010 12:51 pm 
Offline
Phidget Mastermind

Joined: Wed Mar 28, 2007 11:50 am
Posts: 184
Do you test the value of getPosition when you first poll it? I would be curious to see what value it is returning. I cannot see anything wrong with you code at first glance, but I will take a look and try a few things out.


Top
 Profile Send private message  
 
 Post subject: Re: Servo not moving
PostPosted: Mon Dec 13, 2010 3:27 pm 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Two issues.

1. GetPosition doesn't return that last value passed to setPosition. It returns the last position value returned from the controller. This means that getPosition will always be a little bit behind setPosition. Also, with acceleration, the position returned by getPosition will change as the servo is moving to it's final position. Also, right after calling setEngaged to true, calling getPosition may throw an exception for a few ms, until the engaged is finished.

2. If you set the servo to it's minimum position and then set it to that position-5, you'll get the invalid arg exception because you tried to set the position to positionMin-5, which is invalid.

-Patrick


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group