Accueil » Projet Bras robotique : Partie 5

Projet Bras robotique : Partie 5

Programmation de la partie bras robot

La partie bras robot est constituée d’une carte arduino Méga 2500, un module Bluetooth HC-05, des LEDs de clignotements (rouge, bleu et orange) et quatre servomoteurs. Le programme arduino est présenté dans l’annexe 2 de ce rapport Le montage électronique est le suivant :

Montage électronique de la partie bras robot
* FST BENI MELLAL
* Cycle ingénieur filière génie électrique, option : électrotechnique et électronique industrielle
* code réalisé par : MALKI MOHAMED-YASSINE
* PROJET : conception et réalisation d'un bras robotisé
*
* CODE bras robot ==
*/
#include <Servo.h>
Servo myservo, myservo2, myservo3, myservo4;
int a,Val1, Val2, Val3,Val4;
int c,m,n,p;
volatile boolean changed = false;
////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// fonction d'interruption ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
void doContact() {
 changed = ~changed;
 delay(300);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// configuration des paramètres initiaux ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
 myservo2.attach(8);
 myservo3.attach(7);
 myservo4.attach(6);
 pinMode(52, OUTPUT);
 pinMode(53, OUTPUT);
 pinMode(51, OUTPUT);
 attachInterrupt(0, doContact, FALLING);
 Serial.begin(38400); // Default communication rate of the Bluetooth module
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// la fonction loop ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop(){
if ( changed ) {
 Serial.print("aaa");
 Serial.print(1);
 joystick();
}
Serial.print("aaa");
 Serial.print(0);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// la fonction joystick ///////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void joystick(){
 Serial.setTimeout(10000);
while (Serial.available() > 0){
    c=Serial.read();
if (c=='a'){
a = Serial.parseInt();}
m=Serial.read();
if (m=='b'){
Val1 = Serial.parseInt();
Val2 = Serial.parseInt();
}
p=Serial.read();
if (p=='d'){
Val3 = Serial.parseInt();}
n=Serial.read();
if (n=='e'){
Val4 = Serial.parseInt();}

a= constrain(a,0,1);
Val1 = constrain(Val1,3,181);
Val2 = constrain(Val2,3,181);
Val3 = constrain(Val3,3,181);
Val4 = constrain(Val4,0,1);
}
int pos1 = 0;
int pos2 = 0;
int pos3 = 0;
int posmain = 0;
//-----------------------------rotation--------------------------------
 //----------------------moteur 1-------------------------------
 if (Val1>100) {
 if (pos1 < 181) {
      }
 }
 if (Val1<55) {
 if (pos1 >= 0) {
 pos1 -= 10;
 }
 }
 //--------------------moteur 2----------------------------------------------
 if (Val2>100) {
 if (pos2 < 181) {
 pos2 += 5;
 }
 }
 if (Val2<55) {
 if (pos2 >= 0) {
 pos2 -= 10;
 }
 }
 //--------------------moteur 3----------------------------------------------
 if (Val3>100) {
 if (pos3 < 181) {
 pos3 += 5;
 }
 }
 if (Val3<55) {
 if (pos3 >= 0) {
 pos3 -= 10;
 }
 }
 //---------------------fermer ou ouvrir la main---------------------------------------
    if (a==1) {
 posmain = 10;
 }
 if (a==0) {
 posmain = 170;
 }
myservo.write(pos1);
 myservo2.write(pos2);
 myservo3.write(pos3);
 myservo4.write(posmain);
 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// mode robot manipulateur ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 void mode1(){
 int i;
 /*//////////////////////////////////////////////////////////////////////////
 posiotion de depart
 //////////////////////////////////////////////////////////////////////////*/
 myservo.write(90); delay(700);
 myservo2.write(90);
 myservo3.write(110);
 myservo4.write(0);
 delay(500);
 for (i = 0; i <= 6; i++) {
 digitalWrite(52, HIGH);
 delay(300);
 digitalWrite(52, LOW);
 delay(300);
 }// bras est dans la position initiale 
     /*//////////////////////////////////////////////////////////////////////////
 Attaquez l’objet
 //////////////////////////////////////////////////////////////////////////*/
 //-----------------------------------------
 Serial.print(2);
 for (i = 90; i <= 180; i++) {
 myservo.write(i); delay(30);
 }delay(700);
 myservo2.write(30);delay(700);
 myservo3.write(140); delay(1000);
 myservo4.write(130);
//objet attraper
 /*//////////////////////////////////////////////////////////////////////////
 position final
 //////////////////////////////////////////////////////////////////////////*/
 //------------------------------------------
 for (i = 30; i <= 90; i++) {
 myservo2.write(i); delay(30);
 }
 myservo3.write(160);
 for (i = 0; i <= 6; i++) {
 digitalWrite(53, HIGH);
 delay(300);
 digitalWrite(53, LOW);
 delay(300);
 }
 //------------------------------------------
     i=180;
while(i){
myservo.write(i); delay(30);i--;
}
 myservo2.write(20);delay(700);
 myservo3.write(110);
 myservo4.write(0);
 delay(500);
myservo2.write(90);
for (i = 0; i <= 6; i++) {
 digitalWrite(51, HIGH);
 delay(300);
 digitalWrite(51, LOW);
 delay(300);
 }}

Laisser un commentaire