Showing posts with label Robotic. Show all posts
Showing posts with label Robotic. Show all posts

Monday, August 8, 2016

How To Make Your Own Robot Controlled With C#, Followed By A WebCam.

How To Make Your Own Robot Controlled With C#, Followed By A WebCam. 

Hello my dears followers, Like it is mentionned in the article title. Today i m going to demonstrate how we could make an intelligent robot, Controlled by your own C# application made in Visual Studio 2012, Followed by a WebCam.





To Make a full project like this one you have many choices to choose. 
The Hard part of this project is done using an Atmega 328p like a principal MCU. You could use any other MCU, For exemple A PIC like PIC16F877 is able also to replace the Atmega328p.
We know that the principal MCU based on the Arduino UNO is ATmega328 so You Could also use Arduino to get the robot working.

ATmega 328p pins 



   
Those Kind of project based essentially an serial communication. so you have just to use a MCU able to support UART.
There is a step in my project based in PWM so the MCU used have to support PWM also.
And for those how dont know what that means UART and PWM they have just to take a look here:

I choosed directly the ATmega 328p because this one is easier in programming and cheap in price. 
R�sultat de recherche d'images pour "atmega328"
ATmega 328p


The robot move in 4 directions using a 4 simple DC motors, and those motors are controlled by 2 L293D.
The camera is just placed in the first servomotor. and this one is place in other one to get sure that the position where the camera is putted could  cover every point. 
R�sultat de recherche d'images pour "servo motor web cam"
Placing the WebCam

I showed in this article programming ATmega like an Arduino how to program an ATmega32p like programming a simple arduino. this solution is used today also and this is the full program placed in the MCU memory to make the robot moving.



/*  Control and follow your robot using c# application and webcam 
* Project done by : Aymen Lachkhem
* Aymenlachkem@gmail.com
* Blog site : letselectronic.blogspot.com
*/

#include <Servo.h>
Servo myservo1;
Servo myservo2;
void setup() {
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A3,LOW);
digitalWrite(A4,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
myservo1.attach(9);
myservo2.attach(10);
int i1 = 0;
int i2 = 90;
myservo1.write(i1);
myservo2.write(i2);
}

void loop() {
blinker();
Serial.begin(9600);
if (Serial.available() > 0) {
char a = Serial.read();
if ( a == '1'){robot_left(); }
if ( a == '2'){robot_up();}
if ( a == '3'){robot_right();}
if ( a == '4'){robot_down();}
if ( a == '5'){camera2_down();}
if ( a == '6'){camera1_up();}
if ( a == '7'){camera2_up();}
if ( a == '8'){camera1_down();}
}}
void blinker()
{
digitalWrite(A3,HIGH);
digitalWrite(A4,LOW);
delay(100);
digitalWrite(A3,LOW);
digitalWrite(A4,HIGH);
delay(100);
}
void robot_left()
{
digitalWrite(A1,HIGH);
digitalWrite(A0,LOW);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
void robot_up()
{
digitalWrite(A1,HIGH);
digitalWrite(A0,LOW);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
void robot_right()
{
digitalWrite(A0,HIGH);
digitalWrite(A1,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
void robot_down()
{
digitalWrite(A0,HIGH);
digitalWrite(A1,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(7,HIGH);
digitalWrite(6,LOW);
}

void camera2_down()
{
int i3 = myservo2.read();
myservo2.write(i3 - 1);
}
void camera2_up()
{
int i4 = myservo2.read();
myservo2.write(i4 + 1);
}
void camera1_down()
{
int i5 = myservo1.read();
myservo1.write(i5 - 1);
}
void camera1_up()
{
int i6 = myservo1.read();
myservo1.write(i6 + 1);
}



   


This is The Complet Circuit that you have to draw.

Full Circuit




The Hard part of the project is just done so let's talk about the soft part.
We have here to build an Application based in serial communication able to connect directly the robot.
There is many solution to do this, for exemple Labview is one of the best interfacing system also Visual Basic or C#.
I  used C# to do this. A simple application in one only panel with a serial communication platform.
Many Buttons to control the robot and the camera.







How The Application Work ?

This is simple, We have just to add a serial platform to the app. This one will always ask for the port com and the baud rate. Since the moment your choose your serial parametres the fonctionnemnet of buttons starts. 
Every button you will click will send a code to the MCU and exactly like this that's working.

R�sultat de recherche d'images pour "serial communication"



How the WebCam Works ?

In fact, there is a direct library you have to add to your visual studio named AFroge.net Direct Download. After adding this one to your visual studio you have to add this two reference to your project.






The rest is easy, you have just to give the application the permission to look for webcam devices plug in your computer, starts showing what she see, Capture button to save directly the view.

This is the full program written with C# in Visual Studio 2012.

/* Robot controlled by C# , Follewed by a Webcam
Letselectronic.blogspot.com
aymenlachkem@gmail.com
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Video.DirectShow;
using System.IO.Ports;
using System.Diagnostics;


namespace Camera_Project_Lachkhem
{
public partial class Form1 : Form
{
VideoCaptureDevice capture;

public Form1()
{
InitializeComponent();
getAvailablePorts();


FilterInfoCollection info = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (info != null)
{
capture = new VideoCaptureDevice(info[0].MonikerString);
capture.NewFrame += (s, e) => pictureBox1.Image = (Bitmap)e.Frame.Clone();
capture.Start();
}
}
void getAvailablePorts()
{
string[] Ports = SerialPort.GetPortNames();
portcom.Items.AddRange(Ports);
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image.Save("snapchot.png", System.Drawing.Imaging.ImageFormat.Png);
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (capture != null && capture.IsRunning)
{
capture.SignalToStop();
capture = null;

}

}

private void button2_Click(object sender, EventArgs e)
{
Close();
}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{

}

private void label5_Click(object sender, EventArgs e)
{

}

private void connecter_Click(object sender, EventArgs e)
{
{
try
{
if (portcom.Text == "" || baudrate.Text == "")
{
textbox1.Text = "Please select port setting ? ";
}
else
{

serialPort1.PortName = portcom.Text;
serialPort1.BaudRate = Convert.ToInt32(baudrate.Text);
progressBar1.Value = 100;
textbox1.Text = "Connected";


}
}
catch (UnauthorizedAccessException)
{
baudrate.Text = "Unauthorized Access";
}
}
}

private void button3_Click(object sender, EventArgs e)
{
serialPort1.Close();
progressBar1.Value = 0;
}

private void Contact_Me_Click(object sender, EventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo("iexplore.exe", "http://https://letselectronic.blogspot.com/p/blog-page.html/");
Process.Start(startInfo);
}

private void Visit_My_Blog_Click(object sender, EventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo("iexplore.exe", "http://https://letselectronic.blogspot.com/p/blog-page.html/");
Process.Start(startInfo);
}

private void button12_Click(object sender, EventArgs e)
{
var myLines = new List<string>();

myLines.Add("Hello, This Windows application give their Users the ability to control serially or with wirless communication a Robot Followed By a WebCam.");
myLines.Add("- The MCU used is The high-performance Atmel 8-bit AVR RISC-based microcontroller ATmega 328 ");
myLines.Add("- The Control Application was made in Visual Studio 2012, written using C# ");


myLines.Add("----------------------------------------- Blog: Letselectronic.blogspot.com ----------------------------------------------------------------------");
myLines.Add("----------------------------------------- Contact: Aymenlachkem@gmail.com ------------------------------------------------------------------");

textBox2.Lines = myLines.ToArray();
}

private void button7_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("1");
serialPort1.Close();
}

private void button5_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("2");
serialPort1.Close();
}

private void button8_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("3");
serialPort1.Close();
}

private void button6_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("4");
serialPort1.Close();
}

private void button11_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("6");
serialPort1.Close();
}

private void button4_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("5");
serialPort1.Close();
}

private void button9_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("7");
serialPort1.Close();
}

private void button10_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("8");
serialPort1.Close();
}

private void turn_on_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("9");
serialPort1.Close();
}

private void turn_off_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("a");
serialPort1.Close();
}
}
}







Built your application, Get your file.exe and the Setup. Like always this is a video for more details.

I have all files of this project collected in compressed directory so just contact me to have your free files.



                                                                 See you Soon AYMEN LACHKHEM

   





Tuesday, March 22, 2016

Kinect Arduino Robot

Bonjour, Comme il est indiqu� au titre de cette article je vais aujourd'hui illustrer les �tapes � suivre pour r�aliser un robot, un syst�me manipul� en g�n�rale guid� et command� par ce qu'on appelle Kinect.



Commen�ons tout d'abord par d�finir Kinect pour ceux qui les connaissent pas encore:
R�sultat de recherche d'images pour "kinect game"
Il s�agit en faite d�une cam�ra bas�e  sur des techniques d�interaction d�velopp�es par la soci�t� PrimeSense, nomm�e avant par le nom de code du projet, � Project Natal �, Elle est bas�e sur un p�riph�rique d�entr�e branch� avec la console Xbox 360 qui permet d�interagir par une certaine commande vocale, reconnaissance de mouvement et d�image.
R�sultat de recherche d'images pour "kinect"
On peut ainsi jouer sur des jeux sp�cialement d�velopp�s pour le projet, donc sans aucune manette ni p�riph�rique autre que son propre corps. Cette d�tection de mouvements sans p�riph�riques �tait d�j� pr�sente dans l�EyeToy de Sony.Ce vid�o vous montrerez comment �a fonctionne le kinect
Le 21 octobre 2010, Microsoft d�voile la premi�re publicit� officielle de son nouveau p�riph�rique, montrant � quel point la firme vise le grand public. Le g�ant de l'informatique a confirm� d�penser plus de 500 millions de dollars en marketing pour s'assurer de toucher au maximum la population.
Initialement hostile au portage du Kinect sur les PC, la soci�t� Microsoft a finalement chang� d'avis et a introduit Kinect pour Windows au 1er f�vrier 2012. Pour un prix sensiblement sup�rieur, cette version pour PC inclut de nouvelles fonctionnalit�s (par exemple le capteur a �t� repens� pour fonctionner � partir d�une distance de 50 cm. Kinect pour Windows inclut un kit de d�veloppement afin de permettre aux d�veloppeurs de cr�er leurs propres applications.
Revenons maintenant au caract�ristiques principales de cette cam�ra si d�velopp�e :
  • Capteur :
    • Lentilles d�tectant la couleur et la profondeur
    • Micro � reconnaissance vocale
    • Capteur motoris� pour suivre les d�placements
  • Champ de vision :
    • Champ de vision horizontal : 57 degr�s
    • Champ de vision vertical : 43 degr�s
    • Marge de d�placement du capteur : � 27 degr�s
    • Port�e du capteur : 1,2 m � 3,5 m (� partir de 50 cm pour la version Kinect for Windows)
  • Flux de donn�es :
    • 320 � 240 en couleur 16 bits � 30 images par seconde
    • 640 � 480 en couleur 32 bits � 30 images par seconde
    • Audio 16 bits � 16 kHz
  • Syst�me de reconnaissance physique :
    • Jusqu�� 6 personnes et 2 joueurs actifs (4 joueurs actifs avec le SDK 1.0)
    • 20 articulations par squelette
    • Application des mouvements des joueurs sur leurs avatars Xbox Live
  • Audio :
    • Chat vocal Xbox Live et chat vocal dans les jeux (n�cessite un compte Xbox Live Gold)
    • Suppression de l��cho
    • Reconnaissance vocale multilingue (pour les fran�ais, cette fonction est disponible depuis le 06 d�cembre 2011 via une M�J de la Xbox ).


L'objectif de notre projet c'est de savoir relier ce kinect avec une prototype Electronique compos�e d'une carte Arduino uno simple et 4 servomoteurs de fa�on savoir traiter l'information revenante de ce kinect et la traduire en mouvement instantan�, intelligent et direct.

Pour ceci on eu besoin de r�aliser une interface graphique sur processing (Download here) de but a faire afficher la squelette d��tre humain capt�e par kinect, d'autre plan de capt� les articulations logiques des ces organes (bras, �paules,main,....)

Comme premier plan on a arriv� a faire traduire les informations prises par kinect en 4 Angles principales (Epaule et coude droites Angles et Epaule et coude gauche angles).
Le programme processing est si dessous:



// Kinect Robot Processing Program

import SimpleOpenNI.*;
SimpleOpenNI kinect;
import processing.serial.*;
Serial port;
void setup() {
size(640, 480);
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
kinect.enableUser();
kinect.setMirror(true);
println(Serial.list());
String portName = Serial.list()[0];
port = new Serial(this, portName, 9600);

}
void draw() {
kinect.update();
PImage depth = kinect.depthImage();
image(depth, 0, 0);
IntVector userList = new IntVector();
kinect.getUsers(userList);
if (userList.size() > 0) {
int userId = userList.get(0);
if ( kinect.isTrackingSkeleton(userId)) {drawSkeleton(userId);

// get the positions of the three joints of our arm
PVector rightHand = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_RIGHT_HAND,
rightHand);
PVector rightElbow = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_RIGHT_ELBOW,
rightElbow);
PVector rightShoulder = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_RIGHT_SHOULDER,
rightShoulder);
// we need right hip to orient the shoulder angle
PVector rightHip = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_RIGHT_HIP,
rightHip);
// reduce our joint vectors to two dimensions
PVector rightHand2D = new PVector(rightHand.x, rightHand.y);
PVector rightElbow2D = new PVector(rightElbow.x, rightElbow.y);
PVector rightShoulder2D = new PVector(rightShoulder.x,
rightShoulder.y);
PVector rightHip2D = new PVector(rightHip.x, rightHip.y);
// calculate the axes against which we want to measure our angles
PVector torsoOrientation =
PVector.sub(rightShoulder2D, rightHip2D);
PVector upperArmOrientation =
PVector.sub(rightElbow2D, rightShoulder2D);
// calculate the angles between our joints
float shoulderAngle = angleOf(rightElbow2D,
rightShoulder2D,
torsoOrientation);
float elbowAngle = angleOf(rightHand2D,
rightElbow2D,
upperArmOrientation);
// show the angles on the screen for debugging
fill(255,0,0);
scale(3);
text("R shoulder: " + int(shoulderAngle) + "\n" +
" elbow: " + int(elbowAngle), 20, 20);
print(int(elbowAngle));
print(": elbow angle");
print(int(shoulderAngle));
println(": shoulder angle");


//////////////////////////////////////////////////////////////////////////////////////////////
PVector leftHand = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_LEFT_HAND,
leftHand);/////////////
PVector leftElbow = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_LEFT_ELBOW,
leftElbow);
PVector leftShoulder = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_LEFT_SHOULDER,
leftShoulder);
// we need right hip to orient the shoulder angle
PVector leftHip = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_LEFT_HIP,
leftHip);
// reduce our joint vectors to two dimensions
PVector leftHand2D = new PVector(leftHand.x, leftHand.y);
PVector leftElbow2D = new PVector(leftElbow.x, leftElbow.y);
PVector leftShoulder2D = new PVector(leftShoulder.x,
leftShoulder.y);
PVector leftHip2D = new PVector(leftHip.x, leftHip.y);
// calculate the axes against which we want to measure our angles
PVector torsoOrientation1 =
PVector.sub(leftShoulder2D, leftHip2D);
PVector upperArmOrientation1 =
PVector.sub(leftElbow2D, leftShoulder2D);
// calculate the angles between our joints
float shoulderAngle1 = angleOf(leftElbow2D,
leftShoulder2D,
torsoOrientation1);
float elbowAngle1 = angleOf(leftHand2D,
leftElbow2D,
upperArmOrientation1);
// show the angles on the screen for debugging
fill(255,0,0);
scale(1);
text("L shoulder: " + int(shoulderAngle1) + "\n" +
" elbow: " + int(elbowAngle1), 120, 20);
print(int(elbowAngle));
print(": elbow angle");
print(int(shoulderAngle));
println(": shoulder angle");
print(int(elbowAngle1));
print(": elbow angle");
print(int(shoulderAngle1));
println(": shoulder angle");
//println(int(shoulderAngle));

byte out[] = new byte[4];
out[0] = byte(int(shoulderAngle));
out[1] = byte(int(elbowAngle));
out[2] = byte(int(shoulderAngle1));
out[3] = byte(int(elbowAngle1));
port.write(out);
}
}


}
float angleOf(PVector one, PVector two, PVector axis) {
PVector limb = PVector.sub(two, one);
return degrees(PVector.angleBetween(limb, axis));
}
// user-tracking callbacks!
void onNewUser(SimpleOpenNI curContext, int userId) {
println("onNewUser - userId: " + userId);
println("\tstart tracking skeleton");

curContext.startTrackingSkeleton(userId);
}
void drawSkeleton(int userId) {
stroke(0);
strokeWeight(5);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_LEFT_HIP);
noStroke();
fill(100,200, 0);
// drawJoint(userId, SimpleOpenNI.SKEL_HEAD);
// drawJoint(userId, SimpleOpenNI.SKEL_NECK);
// drawJoint(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER);
// drawJoint(userId, SimpleOpenNI.SKEL_LEFT_ELBOW);
// drawJoint(userId, SimpleOpenNI.SKEL_NECK);
// drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER);
// drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW);
// drawJoint(userId, SimpleOpenNI.SKEL_TORSO);
// drawJoint(userId, SimpleOpenNI.SKEL_LEFT_HIP);
// drawJoint(userId, SimpleOpenNI.SKEL_LEFT_KNEE);
// drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_HIP);
// drawJoint(userId, SimpleOpenNI.SKEL_LEFT_FOOT);
// drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_KNEE);
// drawJoint(userId, SimpleOpenNI.SKEL_LEFT_HIP);
// drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_FOOT);
// drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_HAND);
// drawJoint(userId, SimpleOpenNI.SKEL_LEFT_HAND);
}
void onLostUser(SimpleOpenNI curContext, int userId)
{
println("onLostUser - userId: " + userId);
}
void onVisibleUser(SimpleOpenNI curContext, int userId)
{
// println("ongle 1" , o);

}

   
L'autre phase c'�tait savoir manipuler ces angles traduites par Processing en mouvement instantan� de 4 servomoteurs (deux bras manipulateurs), Tout simplement en utilisant Arduino et en reliant les 4 servomoteurs en 4 sorties PWM d'arduino de fa�on suivante: 


// Kinect Robot Arduino Program 

#include <Servo.h>
// declare both servos

Servo shoulder;
Servo elbow;
// setup the array of servo positions 2
int nextServo = 0;
int servoAngles[] = {0,0};
void setup() {
// attach servos to their pins 3
shoulder.attach(9);
elbow.attach(10);
Serial.begin(9600);
}
void loop() {
if(Serial.available()){
int servoAngle = Serial.read();
servoAngles[nextServo] = servoAngle;
nextServo++;
if(nextServo > 1){
nextServo = 0;
}
shoulder.write(servoAngles[0]);
elbow.write(servoAngles[1]);
}
}
   

Comme �a se voit au bout du programme, le serial a r�alis� cette tache de lire les angles et la biblioth�que servo.h d'arduino les traduites en mouvement instantan�es.

Voila votre vid�o d�monstratif de fonctionnement:




  
http://letselectronic.blogspot.com/
Done by Houssem and Aymen 

benham.houssem@gmail.com 
aymenlachkem@gmail.com