Shared Phidgets Simple Example Controlling A Servo

Toolkits.SharedPhidgetsSimpleExampleControllingAServo History

Hide minor edits - Show changes to output

Added lines 38-39:
'''Preparation:''' Install the Shared Phidgets toolkit on all client machines, run the Connector software, and attach at least one servo motor to one of the client computers.
Changed lines 50-52 from:
->Attach:sp3-example-2b.png
to:
->Attach:sp3-example-servo-2b.png
Changed line 11 from:
* how to create a SharedPhidgets servo object,
to:
* how to create a Shared Phidgets servo object,
Changed lines 50-52 from:
to:
->Attach:sp3-example-2b.png
Changed lines 36-37 from:
!!Step-by-step instruction
to:
!!Step-by-step Instructions
Changed lines 39-40 from:
->Attach:SP-exampleservo-1.png
to:
->Attach:sp3-example-1.png
Changed lines 42-46 from:
->Attach:SP-helloworld-2.png


The windows form for the appliance control will open:
to:
->Attach:sp3-example-2.png

The windows form for the appliance control will now be opened:
->Attach:sp3-example-3.png
Changed lines 48-53 from:


3) Drag a SharedPhidget Servo component on your form.
->Attach:SP-exampleservo-2.png
to:
->Attach:sp3-example-4.png


3) Drag a SharedPhidget Servo component on the appliance form.
->Attach:sp3-example-servo-1.png
Changed lines 55-56 from:
->Attach:SP-exampleservo-4.png
to:
->Attach:sp3-example-servo-2.png
Changed lines 58-59 from:
->Attach:SP-exampleservo-5.png
to:
->Attach:sp3-example-servo-3.png
Changed lines 61-62 from:
->Attach:SP-exampleservo-6.png
to:
->Attach:sp3-example-servo-4.png
Changed lines 64-65 from:
->Attach:SP-exampleservo-7.png
to:
->Attach:sp3-example-servo-5.png
Changed lines 85-86 from:
->Attach:SP-helloworld-5.png
to:
->Attach:sp3-example-servo-6.png
Added lines 1-96:
[[Toolkits.SharedPhidgets3 | << Back to the SharedPhidgets 3 page]]
\\
\\

\\

>>greenbox<<

'+'''What you will learn in this tutorial:'''+'

* how to create a SharedPhidgets servo object,
* how to assign a specific serial number,
* how to use the servo skin to control a servo and
* how to control the servo from your source code.

>><<

\\

(:table border=1 cellpadding=17 cellspacing=0 align=centre bgcolor=#eeeeee :)
(:cell:) [+ '''Download source: ''' [[(Attach:)SharedPhidgetsExamples.zip]] +] \\
The zip file contains the program code of all the Shared Phidgets programming examples. The source code of this example can be found in the 'ServoExample' project.
(:tableend:)

!!Overview

%rframe thumb% Attach:Servo.jpg"The Phidget Servo" | [-The Phidget Servo-]
# Create a new Shared Phidgets appliance with the template in VisualStudio.NET
# Create a servo object
# Create a servo skin and connect it to the servo object
# Controlling the servo object from the code directly (with 2 buttons on the form)
# '''Finished!''' Compile the application and test the control of the servo motor!

\\

!!Step-by-step instruction

1) Open VisualStudio.NET 2005, click ''New Project'', select a new C# Windows application, enter a name for the project, and confirm the dialog.
->Attach:SP-exampleservo-1.png

2) Doubleclick the 'ApplianceForm.cs' file in the project explorer on the right side of the screen:
->Attach:SP-helloworld-2.png


The windows form for the appliance control will open:

It is possible to change the appliance name, as well as the default address for the connection to the shared dictionary by changing properties of the main form:



3) Drag a SharedPhidget Servo component on your form.
->Attach:SP-exampleservo-2.png

It is possible to change the serial number of the servo. If you have only one servo at your infrastructure, you don't need to add the serial number because the component will then connect to the only hardware device of this type that it will find.
->Attach:SP-exampleservo-4.png

4) Create a skin object for the servo:
->Attach:SP-exampleservo-5.png

Change the servo object of the ServoSkin to the object of the created servo, here this is servo1
->Attach:SP-exampleservo-6.png

5) Create two additional buttons on the form, and change their Text property to "180 degrees" and "0 degrees".
->Attach:SP-exampleservo-7.png

Double click on the buttons, and add the following code to the button click handler:\\
for the 180-degree-button:
(:source lang=csharp tabwidth=2 :) [=
private void button1_Click(object sender, System.EventArgs e)
{
this.servo1.Motors[0].Position = 180;
}
=]

for the 0-degree-button:
(:source lang=csharp tabwidth=2 :) [=
private void button2_Click(object sender, System.EventArgs e)
{
this.servo1.Motors[0].Position = 0;
}
=]


6) Compile the application:
->Attach:SP-helloworld-5.png

\\

>>greenbox<<
'+'''Finished!'''+'

It is now possible to use the graphical interface skin to control the servo, and to use the buttons to set the position of the servo to a particular position. From here, this simple application can now be modified and enhanced with additional functionality. You can add more servo objects if needed, but remember to specify the serial number for each of the servos.
>><<

\\