How to convert PhidgetAdvancedServo positions to pulse width

Supporting Visual Studio on Windows
dogulas
Fresh meat
Posts: 3
Joined: Tue Sep 06, 2011 4:11 pm
Contact:

How to convert PhidgetAdvancedServo positions to pulse width

Postby dogulas » Tue Sep 06, 2011 4:28 pm

How do I use the PhidgetAdvancedServo 8-Motor device with continuously rotating servos?

In particular I am interfacing two of the servo ports with Parallax HB-25 motor controllers. I had this working once from MSRS and I lost the code. Now I'm trying to get there from CSharp. The Parallax product is supposed to interface with any servo controller and take PWM signals just like a servo. Their documentation states:

"...you may send the HB-25 pulses every 20 ms just
like a servo and it will function the same."

"There is a hold-off time of 5 ms where the HB-25 will ignore incoming pulses. As a result, the unit should
not be refreshed more frequently than about 5.25 ms + pulse time. Pulse time can be anywhere from
0.8 ms to 2.2 ms. If the HB-25 receives a pulse outside of this range, it will temporarily shut off the
motor until it receives a valid pulse."

"Pulse Input: 1.0 ms Full Reverse, 1.5 ms Neutral (Off), 2.0 ms Full Forward"

How do I translate Phidget positions into pulse widths?

Thanks,
dogulas
Thanks,
dogulas

erik
King of the Lab
Posts: 476
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: How to convert PhidgetAdvancedServo positions to pulse w

Postby erik » Wed Sep 07, 2011 8:29 am

You can set the individual servo's Type Property to RAW_us_MODE which allows you to set the "position" in terms microseconds. The valid range for is between 0 and 2750us, but depending on the servo, there might not be any movement at the very ends of that range (0.8 to 2.2ms in your case).

Code: Select all

advServo.servos[0].Type = ServoServo.ServoType.RAW_us_MODE;


You can verify this in the AdvancedServo-full example when you change the Type to RAW_us_MODE.

dogulas
Fresh meat
Posts: 3
Joined: Tue Sep 06, 2011 4:11 pm
Contact:

Re: How to convert PhidgetAdvancedServo positions to pulse w

Postby dogulas » Wed Sep 07, 2011 10:50 am

erik et. al.,

Thanks for your response. This sounds exactly like what I needed. However, I'm running into another problem when I implement this. When I try to set the type in this code:

leftWheel = phidgetServo.servos[0];
rightWheel = phidgetServo.servos[1];

leftWheel.Type = ServoServo.ServoType.RAW_us_MODE;
rightWheel.Type = ServoServo.ServoType.RAW_us_MODE;

There is no syntax error in VS2010 and it compiles cleanly, but then I run it on my robot and when it gets to the line where I set the type I get the following error message:

Error: System.EntryPointNotFoundException: Unable to find an entry point named 'CPhidgetAdvancedServo_setServoType' in DLL 'phidget21.dll'.
at Phidgets.Phidget21Imports.CPhidgetAdvancedServo_setServoType(IntPtr phidA, Int32 Index, Int32 newVal)
at Phidgets.AdvancedServoServo.set_Type(ServoType value)

I keep the DLL in the same directory with the executable and copy them together.

Any ideas?
Thanks,
dogulas

User avatar
Patrick
Lead Developer
Posts: 3078
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: How to convert PhidgetAdvancedServo positions to pulse w

Postby Patrick » Wed Sep 07, 2011 1:37 pm

Sounds like you have an old phidget21.dll, from before the servo type function was added.

Make sure you don't have multiple libraries installed. If you have run the phidget21 installer, the your program should use the .NET library from the GAC and the phidget21.dll from windows\system32, but might pick up any local copies as well.

-Patrick

dogulas
Fresh meat
Posts: 3
Joined: Tue Sep 06, 2011 4:11 pm
Contact:

Re: How to convert PhidgetAdvancedServo positions to pulse w

Postby dogulas » Fri Sep 09, 2011 6:24 am

Patrick,

Thank you thank you.

You were right. I am building the app on a development box which doesn't have the phidget, and running it on my robot which doesn't have VS. I forgot that the robot had a prior life with a MSRDS application and in those days I had installed phidget21.

I Uninstalled and reinstalled the newer one and all problem went away. Thanks again.
Thanks,
dogulas


Return to “C#.NET”

Who is online

Users browsing this forum: No registered users and 1 guest