robotics company robot company  

Go Back   Trossen Robotics Community > TRC Data Center > Demos, Example Code, Widgets

Home Submit File What's New What's Popular Search

GDI+ Phidgets Servo Control GUI and C# .NET
Old 08-16-2008 08:53 PM
Semicton
Semicton is offline
Banned
 
Views: 1,856
Replies: 2
GDI+ Phidgets Servo Control GUI and C# .NET
My first upload. This is a user drawn GDI+ control for a Phidgets servo written in C#. The control is intended to replace the standard track bar control that most people use to control their own phidget servos via a GUI. Over time, I created many versions of this control. A few versions of this control directly controlled a phidget servo on a phidgetservo board within the user control itself. Over time, I finally realized it would be best to simply create the control as a graphical user interface that can be dragged onto a windows form, and allow the programmer to write their own code to actually move the Phidget servo. This solution uses a hacked up subscriber pattern to do just that.

I've also noticed people new to phidgets, or programming, want to move a phidget smoothly, and create a sequence of moves for playback as soon as possible. Can you blame them? This is supposed to be fun! Purchasing a phidget and have it sit on your desk for days before you get something up and running can be a bit dissapointing. So, I have provided a form with the user control and, included (One possible solution of many.) a an example with full source code to move a phidgets servo and record it's positions for playback right away almost straight out of the box.

Screenshot



Here is one of a few videos I've made using the control: http://www.youtube.com/watch?v=8wpU8_Gln2c


Minimum Requirements:
  • Visual Studio 2008 C#
  • .NET Framwork 3.5
  • The Latest Phidgets21.dll

Suggested Requirements:
  • Phidgets 4 Servo controller board. (I assume it will work with a single phidgets servo controller board.)
  • 8/8/8/8 Phidgets interface kit
  • 1 phidgets sensor

The Minimum Requirements will allow you to move the servo GUI around with your mouse. You will not be able to recorde or replay servo sequences with only the minimum requirements.

*NOTE* This solution will work with a single port Phidgets servo board or a four port Phidgets servo board. No other Phidgets hardware is required.
If you want to create a sequence of servo movements for your actual phidget board and servo playback, you will require a phidget servo board that can be purchased here on TrossenRobotics.

A Phidgets interface kit 8/8/8/8 and a sensor installed on index [0] is required only if you specify a sensor threshold.
If you own a Phidgets interface kit, you can hook up a sensor at index [0] and this example code will stop recorded servo movement during recorded playback only, and continue to the next position if the sensor value is met. Sensor threshold values will not stop manual servo movement via the mouse. If you supply a sensor threshold but do not have a phidgets 8/8/8/8 interface kit with a sensor hooked up at index [0], the program will fail becuase of lack of error handling. If you do not have a Phidgets Interface 8/8/8/8, Do not enter a sensor threshold value.

*NOTE* I have commented out all code referencing the Microsoft speechlib.dll to make it easier to get the solution running. Uncomment these lines as you like.
This visual Studio .NET 2008 solution also uses a (Optional) speech library from Microsoft called Speechlib.dll. I have included this Speechlib.dll in this solution. You may also download the Microsoft speechlib.dll at Microsoft's website.


This Visual Studio .NET 2008 solution requires the Phidgets21.dll. I have included this Phidgets21.dll in the solution. You may also use The phidgets MSI file that can be downloaded here: http://www.phidgets.com/downloads.php?os_id=1.

If you encounter errors when first running this solution. The first thing to do should be to verifty the reference paths to the two .dlls mentioned above.


I've compressed this solution into a single zip file. You can not run this solution within the zip file. Please unzip it to a location on your hard. This solution has already been compiled. You may run the released version by executing the file located at bin\Release\Phidgets Studio.exe. If you are using Visual Studio.NET 2008 please execute and run the Phidgets Studio.sln or Phidgets Studio.csproj file located in the unzipped root directory to view the source code and or recompile it for your self. If you do not have Visual Studio.NET 2008 installed, you can open any .cs file with a standared text editor to view the code.

This solution contains two red circles that can be dragged around the servo GUI with your mouse when the [left shift] or [left alt] buttons are pressed and held while clicking your right mouse button. The position of these red circles define the minimum and maximum positions of your servo. You will also notice that to move the servo you may click anywhere between the two red circles to move the servo. The actual movement of your servo is delayed as a safety precuation to keep you from stripping out any servos. If you press your mouse button on the servo arm and drag it, The servo will move with the same small delay but also will stop for a moment as you drag. This allows for very small precise movements.

I have uploaded this code to some friends online to verify that it does indeed compile and run. Although it has been a few months since I've last worked on it, I was able to hook up my 4 servo Phidgets board and get it running with out any problems. If you have questions or need assistance to get it running with your phidgets board, please send me a message, I would be more than happy to help you get it working for yourself. Also, feel free to post a reply here to this thread with your questions if you can't get it to work. I will be happy to reply and help.

This project is a work in progress. you must expect, and, will find many lines of code that have been commented out. You will also find many lines of white spaces. (for you 'white space Nazis' as my boss likes to call himself.)

This solution should run immediately, but if you want to get creative:
This control can be wired up to 4 servos on one board. After you open the solution you will find a Phidgets Studio Components toolbox group. Within the toolbox group, you will find a Servo control that can be dragged and dropped onto the form. After you drag and drop the servo control onto your form, You will find a properties grouped named Misc. In the properties of the control you can specify the default min, and max positions of the servo. With some additional work, you can also code your own properties to specify an unlimited number of Phidgets servo boards and servos. This is what I will be working on in the next few months.

This project is not meant to be a tutorial on how to use Phidgets. It is nothing more than a bunch of code that I have written driven by pure hobbyist robotic fascination.

Most importantly, I would like to ask anyone who has ideas or knowledge of how to improve the code or architecture of the control and the code that drives it on the form.

This is my contribution to the great robotics community of Trossen Robotics.

Please visit my site: www.husko.net and rate or comment on my youtube channel: http://www.youtube.com/user/huskodotnet

Attached Files
File Type: zip 26431-PhidgetsServoGUI (641.56 KB, 172 views)
Tags: None



Replies to File: GDI+ Phidgets Servo Control GUI and C# .NET
  #1   Report Post  
Old 09-08-2008
Semicton's Avatar
Semicton
Semicton is offline
Banned
 
Join Date: Jul 2006
Location: Grand Rapids, MI
Posts: 68
Semicton
I've fixed a small bug where the first time you start moving the control, the servo and control wants to zip to zero position and then to the intended position. I have squashed the bug and it is now working correctly.

It's been a rainy afternoon here so I finally wired up 5 servos to control my arm. WOW! Talk about initialize spasm's!. The arm nearly flew off my desk. I apologize if anyone else encountered this bug. I have to admit, I tested this with only 1 servo with out linkage and I over looked the obvious.

I've also fixed the missing min and max properties to be rendered as you change the property in the designer.

Anyway, I've updated the down-loadable file.

Thanks,

-Husko

P.S. Make sure you set you sposition and ServoPosition Properties on the servo control before running the project. You may have to start the project at least once to determine the best start position for your servo if you are linking servos together with hardware.
  #2   Report Post  
Old 06-11-2009
nbdeveloper's Avatar
nbdeveloper
nbdeveloper is offline
Transistor
 
Join Date: May 2009
Location: Oregon Coast
Posts: 31
nbdeveloper
Re: GDI+ Phidgets Servo Control GUI and C# .NET

Hey what's crapyprop? There is a public property called crappyprop and the form designer code initializes the int value to zero but it doesn't look like it is used anywhere else in the application. Crazy detail on the GDI stuff. There's a few other goodies in some of the other/support code you've got to. Thanks! I can't wait for the final product.

Are you thinking of building more? (The solution is called Phidgets Studio.) That's an idea I had about a year ago but didn't know enough about Phidgets or robotics to do anything about it. Having toolbox controls really lowers the entry point for developers and allows us to focus on the logic or in this case, the behavior of the robot as opposed to the mechanics (which can still be fun but not so much when you are new).

I've done some server control development too (little/no GDI though...mostly ASP.NET). If you need any help or have any other ideas I'd love to help out.

I've turned your desklamp on 3 times now and. I like DotNetNuke too. You're favicon gives it away. Well, that and "tabid" being in the uri...

For anyone else, here's a link to Semicton's website: http://semicton.com/
__________________
I don't know what I'm doing but I like it. - NB

 


All times are GMT -5. The time now is 04:54 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.