PDA

View Full Version : One problem after another!



bidi
01-30-2007, 05:38 PM
I've been trying to get a simple program going to control a servo motor I have, but have had issues with the first 2 steps. Granted the first one was due to ignorance, and this 2nd one is probably the same thing. Anyway, I've written this code:

#include <stdio.h>
#include <phidget21.h>

int main (int argc, char* argv[])
{
int result;
int numServos;
CPhidgetServoHandle Servo = 0;

// Open any PhidgetServo non-exclisively
if ( CPhidgetServo_create (&Servo) )
{
printf ("Unable to find a PhidgetServo.\n");
return 1;
}

// Verify the number of servos
CPhidgetServo_getNumMotors (Servo, &numServos);
printf ("%i Servos.\n", numServos);

// Set position of servo 0 to 90 degrees
if ( CPhidgetServo_setMotorPosition (Servo, 0, 90.0) )
{
printf ("Unable to set motor position.\n");
return 1;
}

CPhidget_close (Servo);
CPhidget_delete (Servo);
return 0;
}And get this output:

0 Servos.
Unable to set motor position.This is on a 1001 PhidgetServo version 3.0 controller with the libphidget21 library. Whenever I plug the controller into the USB port it's recognized and loads the appropriate driver, "phidgetservo".

If you didn't catch my first post this is on a Linux computer with GCC 4.1.2 and kernel version 2.6.18.

Thanks

Alex
01-31-2007, 10:04 AM
Forgive my ignorance, but is this C or C++?

I am not all that familiar with whatever version of C you are using, but the first thing that comes to mind given my experience using Phidgets in other languages is that it doesn't look like you are calling the open method on the servo. Have you looked through the C API Manual?

http://www.phidgets.com/documentation/C_API_Manual_Phidget21.pdf

Your printf call,


printf ("%i Servos.\n", numServos);

is returning "0 Servos", so that tells me that the servo controller was never opened and recognized within the programming environment.

This is from page 4 on the C API Manual:


CPhidget_open (CPhidgetHandle, int SerialNumber);
Attempts to locate a Phidget matching your requirements on the local computer.
The CPhidgetHandle should be a valid handle previously allocated by CPhidget(device)_create. Before
calling CPhidget_open, we recommend registering the event handlers your application will use.
SerialNumber specifies the desired serial number, allowing the call to open a specific Phidget.
Specifying -1 for the serial number will cause it to open the first available device.
Open is pervasive. What this means is that you can call open on a device before it is plugged in, and
keep the device opened across device dis- and re-connections.
Open is Asynchronous. What this means is that open will return immediately – before the device being
opened is actually available. What this means is that you need to either poll CPhidget_getDeviceStatus
for an attached status, or handle the attach event, in order to wait for the device to become available
before trying to use it.

bidi
01-31-2007, 11:40 AM
I am not all that familiar with whatever version of C you are using, but the first thing that comes to mind given my experience using Phidgets in other languages is that it doesn't look like you are calling the open method on the servo. Have you looked through the C API Manual?
It's regular C!

Yes I did, and I actually realized I wasn't using the _open command. Once I saw that I inserted the _open function into the program but whenever I try to run it I get a series of errors:

PHIDGET21: unable to open active device in findactivedevices: 1
I then reverted to the example in page 3 of the C_API_Manual, with the same results. It never seems to be able to open the device.

I think I e-mailed you about this as I didn't think I was going to get any response here, is your e-mail alexw@phidgetsusa.com?

Alex
01-31-2007, 11:52 AM
Thanks, I was wondering:D I know a little C++, and I know that C++ syntax varies slightly between versions, but that didn't look like any C++ I've seen. I'm hoping to learn the basics of C someday soon because I have some ideas for some of our products that I think will be of great interest to others.

Anyways, could you paste your newest code so I can better diagnose what's going on?



I think I e-mailed you about this as I didn't think I was going to get any response here, is your e-mail alexw@phidgetsusa.com?I still get those emails, but my actual address is listed in our contacts page:

alexw@trossenrobotics.com

Sometimes questions can't get answered right away, and patience is always greatly appreciated:)

bidi
01-31-2007, 12:43 PM
The code is pretty much exactly what on page 3 of the API manual, only modified for the Servo controller:

#include <phidget21.h>


int main()
{
CPhidgetServoHandle phidgetServo;
CPhidgetServo_create (&phidgetServo);
CPhidget_open (phidgetServo, -1);
CPhidget_waitForAttachment ((CPhidgetHandle)phidgetServo, 0);
CPhidget_close ((CPhidgetHandle)phidgetServo);
CPhidget_delete ((CPhidgetHandle)phidgetServo);

}
And it outputs that error 4 or 5 times a second until I stop the process with [ctrl]+C! If I change the timeout of _waitForAttachment it'll just end the program after that amount of seconds, that is, it wasn't able to find anything attached.

Alex
02-01-2007, 09:36 AM
Do you happen to have a Windows machine that you could test the Servo controller out on, just to make sure that the board itself isn't faulty?

Download and run the Phidget.msi (http://www.phidgets.com/modules.php?op=modload&name=Downloads&file=index&req=getit&lid=27) onto a Windows machine (preferably XP if you can) and this will install all your library files. In "C:\Program Files\Phidgets" run Phidget21Manager.exe. You'll see an icon pop up in your system tray. Double click on it, and in the General tab under Locally Attached Devices, when you plug and unplug the servo controller, you should see it displayed here. When you plug in a device, give it a minute or two so that it can register in the system.

If you do see it displayed, cool. One down, one to go:) Next, we want to be sure that the USB data transfer is ok. On the same Windows machine, download the attached file, rename the extension to .exe and with your Servo Controller attached and the servo plugged into port #0 (or with a power supply connected then the servo can be attached to any port) run the EXE. Do you see the message "PhidgetServo Attached"? If so, move the slider around. Does the servo move?

Let me know how all this goes.


Sorry, I wish I could explain how to do all this on a Linux box, but I don't know Linux at all.

bidi
02-01-2007, 11:22 AM
Do you happen to have a Windows machine that you could test the Servo controller out on, just to make sure that the board itself isn't faulty?

Download and run the Phidget.msi (http://www.phidgets.com/modules.php?op=modload&name=Downloads&file=index&req=getit&lid=27) onto a Windows machine (preferably XP if you can) and this will install all your library files. In "C:\Program Files\Phidgets" run Phidget21Manager.exe. You'll see an icon pop up in your system tray. Double click on it, and in the General tab under Locally Attached Devices, when you plug and unplug the servo controller, you should see it displayed here. When you plug in a device, give it a minute or two so that it can register in the system.
I do Windows installed, I just don't have a C compiler for it that's why I've been programming in Linux. I'm at work right now, so I'll have to do this when I get home later today.


If you do see it displayed, cool. One down, one to go:) Next, we want to be sure that the USB data transfer is ok. On the same Windows machine, download the attached file, rename the extension to .exe and with your Servo Controller attached and the servo plugged into port #0 (or with a power supply connected then the servo can be attached to any port) run the EXE. Do you see the message "PhidgetServo Attached"? If so, move the slider around. Does the servo move?
Which attachment are you talking about? I don't see anything attached to this post, where can I find the file?


Sorry, I wish I could explain how to do all this on a Linux box, but I don't know Linux at all.
That's fine, not a lot of people do. I use it on a daily basis so it's Windows that's strange to me, not to mention the issue with not having a compiler.

bidi
02-01-2007, 05:08 PM
Well, since I didn't know what file you were talking about so I rename Phidget21.msi to Phidget21.exe, but it complains:

Program too big to fit in memory
So anyway, this is where I stand! The test with Phidget21Manager worked, I see the PhidgetServo listed.

Alex
02-01-2007, 06:27 PM
Sorry about that. I just uploaded it now, check out my previous post. However, don't rename the file, just download, extract, then run it with your servo motor controller connected to your Windows machine, with a power supply connected.

You do need to run the Phidget21.msi on a Windows machine as itself, without renaming it. This will install all the necessary library files for Phidgets to be understood in a Windows machine. In my post above, I've added a hyperlink to that download, but here's the direct link:

http://www.phidgets.com/modules.php?op=modload&name=Downloads&file=index&req=getit&lid=27


On a side note, you don't have to worry about a compiler or anything to run this exe. The exe that I sent you is a fully compiled executable VB 6 file, which doesn't need anything other than the Phidget.msi installed.

bidi
02-01-2007, 07:40 PM
Yeah, I got the Phidget21.msi software installed, no problems! The servo-slider program gives the following error:

Component 'MSCOMCTL.OCX' or one of its dependencies not correctly registered: a file is missing or invalid
I'm assuming you created this file using Visual Studios (I can see that from the icon) I wonder if it needs VS installed in order to run it.

bidi
02-01-2007, 08:27 PM
Just as a reminder, I'm running a modified servo. I popped the tab off the 90deg stop and disconnected the potentiometer. I'll need some help on moving it on the different directions after I get pass just getting it to work, just FYI.

Alex
02-02-2007, 09:16 AM
You shouldn't need anything installed. In fact, I just downloaded the same zip on another computer that only has the .NET 2.0 Framework installed and the Phidgets.msi and the program worked fine.

This is an old school VB6 executable. Although a rather archaic language, one of the sheer beauties of VB6 is that you can just copy and paste an .exe directly onto another computer.

DISCLAIMER: The following information is a support topic that is outside of Trossen Robotics. Thus, we cannot be liable for anything that happens to your computer as a result.

Sorry, I have to put that in there.


Anyways, I looked on MajorGeeks, and it looks like MSCOMCTL.OCX is a Windows file that somehow somehow got lost, or is not longer registered on your machine.

Here's the MajorGeeks page on it:
http://www.majorgeeks.com/faqshow.php?id=8

Before you do any of what that page tells you, make sure you go into "C:\WINDOWS\SYSTEM32" and verify if you have the file MSCOMCTL.OCX. If you do, try to register that one first before you go through the steps on MajorGeeks. Registering that file is easy:

START--> RUN and type "REGSVR32 MSCOMCTL.OCX" (No quotes) in the box.

If registering doesn't work and you do have the file, be sure to make a backup copy of the file. If you don't have that file however, then go ahead with the MajorGeeks directions.

bidi
02-02-2007, 11:51 AM
Sounds good! I'll take a look at it once I get home.

I just have one additional question, which actually is a bit off topic. I'm wondering how would I be able to get the modified servo motor I'm using to go clockwise, counter-clockwise and full stop? The documentation for PhidgetServo says that _setMotorPosition accepts a double called newVal and that it's value can be anything from -23 to 231 as the pusle width.

BTW, sorry for some of these questions. I know they might sound trivial, but I've never worked with anything like this. This program I'm writting is for a project of mine, which someone else was in charge of but just kind of bailed out. So I'm having to learn everything about servos in a week.

Alex
02-02-2007, 12:27 PM
Hey Bidi,

No worries about your questions! Many "trivial" questions are exactly what many other community members are looking for:)

Could you create a new thread for this question though? I just don't want to see it get buried so that other community members won't see/find it.

bidi
02-02-2007, 12:55 PM
OK, that didn't work! The program starts up now, but whenever I change the servo's angle on the program it doesn't do anything physically. Is there a way I can test the servo itself? Make sure it's not fried? I'm guessing the black wire is ground, but not sure which one is power, yellow or red. Could I just send a voltage to it in order to test it?

Alex
02-02-2007, 01:02 PM
What port do you have the servo connected to? If you have the servo connected to any other port than #0, then the power supply must be connected. Port #0 is the only port powered by USB.

bidi
02-02-2007, 01:21 PM
It's on port #0, but I also have the power supply connected to it.

Alex
02-02-2007, 01:32 PM
Do you have any non-hacked servos that you can test? I'm wondering if something might have been cut that shouldn't have been during modification.

bidi
02-02-2007, 01:52 PM
No not really, the other motor is also modified but it wouldn't matter since it's at the lab this project is for, about 40 minutes away!

Alex
02-02-2007, 02:16 PM
It sounds to me that it's either a problem with the servo or with the controller.

So, at this point, there are two choices:

A) send the servo controller back in and I can test it

or,

B) purchase and/or find a non-modified servo to test the controller with

bidi
02-02-2007, 02:23 PM
Hmm! I guess I will have to go with option A. How would I go about doing that?

Alex
02-02-2007, 02:32 PM
Sorry, I was just informed that we can't offer option A and that you will need to go with option B. That is, you need to find or purchase a non-modified Servo and go through everything we've discussed and test the controller.

bidi
02-02-2007, 02:39 PM
Ah, that sucks! I wish there was some way I could test the servo itself. We've had a servo fry on us once before, so I wouldn't doubt this is the problem again.