Showing posts with label Lucrez. Show all posts
Showing posts with label Lucrez. Show all posts

Wednesday, May 21, 2014

Braț robotic #4 (final)

Proiectul a ajuns la final. Au fost câteva săptămâni intense, pentru care mă bucur cu adevărat. La sesiunea de comunicări a obținut locul 2 și a energizat și audiența. Lucruri bune.

Inițial proiectul includea un senzor de culoare care să citească culoarea obiectului preluat de robot. Pentru că senzorul pe care îl aveam era problematic, am decis să includ din nou elementul uman în ecuație, și am înlocuit senzorul cu o tastatură.

De asemenea, am trecut de la IDE-ul Arduino, la Atmel Studio 6.1 cu pluginul de Arduino. Mi-a oferit câteva funcții în plus, ca cea de autocompletare, sau utilizarea mai multor fișiere sursă în paralel.


Mai sus puteți vizualiza un clip care exemplifică funcționalitatea robotului. 

Codul este mai jos:

#include <Servo.h> 
#include <interrupt.h>
#include "Keypad/Keypad.h" 

Servo hand, wrist, elbow, shoulder, waist;  // create servo object to control a servo a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 
int key = 12; // joystick variables
int automatic, manual;
boolean keyFlag = false;
volatile int hor, vert;
int waistPos = 90, shoulderPos = 90, elbowPos = 90, wristPos = 90, handPos = 90; 


//keypad
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 7, 13, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {16, 17, 18, 19}; //connect to the column pinouts of the keypad

Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char customKey;
void setup() 
{ 
  // attaches the servos on pins 
  hand.attach(3);
  wrist.attach(11);
  elbow.attach(6);
  shoulder.attach(9);
  waist.attach(10);  

  //joystick pins
  pinMode(key, INPUT);
  pinMode(A0, INPUT); //horizontal movement
  pinMode(A1, INPUT); //vertical movement
  
  //automatic/manual pins
  pinMode(2, INPUT); //automatic
  pinMode(4, INPUT); //manual

  Serial.begin(9600);
   
  pinMode(12, INPUT);
  digitalWrite(12, HIGH); //pull-up
  
  homePos(); //get robot to start position
} 

void getBack()
{
 while(waistPos > 90)
{
  waist.write(waistPos--);
delay(30);
}
 while(wristPos > 90)
{
wrist.write(wristPos--);
delay(30);
}
 while(elbowPos > 90)
{
elbow.write(elbowPos--);
  delay(30);
}
 while(shoulderPos > 90)
{
shoulder.write(shoulderPos--);
     delay(30);
}

}
void getToLoad() //gets load to sensor
{
  waist.write(130);
  hand.write(140);
  
  for (wristPos; wristPos < 135; wristPos++)
  { 
   wrist.write(wristPos);              // tell servo to go to position in variable 'pos' 
   delay(30);   
  }

  for (shoulderPos; shoulderPos < 140; shoulderPos++)
  {
 shoulder.write(shoulderPos);              // tell servo to go to position in variable 'pos'
 delay(30);
  }
  
  for (elbowPos; elbowPos < 115; elbowPos++)
  {
 elbow.write(elbowPos);              // tell servo to go to position in variable 'pos'
 delay(30);
  }
   
  delay(30);
  getLoad();
  
  for (wristPos; wristPos > 125; wristPos--)
  {
 wrist.write(wristPos);              // tell servo to go to position in variable 'pos'
 delay(30);
  }
}

void receiveLoad() //opens and closes hand/claw
{
 hand.write(120);
 delay(1000);
 hand.write(50);
 delay(1000);
}

void getLoad()
{
 hand.write(50);
 delay(1000);
}

void runAutomatic()
{
Serial.println("automatic");
 getToLoad();
 delay(1000);
 getLoad();
 getBack();
 checkCommand();
}

void homePos() //gets to start position
{
  elbow.write(90);
  shoulder.write(90);
  wrist.write(90);
}

void runManual()
{
  hor = analogRead(A0);            // reads the value of the potentiometer (value between 0 and 1023) 
  vert = analogRead(A1);
  hor = map(hor, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  vert = map(vert, 0, 1023, 0, 179);
  
  waist.write(179 - hor);          // sets the servo position according to the scaled value 
  delay(15);
  
  elbow.write(vert);
  shoulder.write(vert);
  wrist.write(vert);
  
  int keyState = digitalRead(key);

  if(keyState == LOW && keyFlag == true)
  {
    receiveLoad();
  }
  keyFlag = !keyFlag;
  Serial.println(pos);
}

void checkCommand()
{
   customKey = customKeypad.getKey();

   while(customKey == '0')
{
Serial.println("no command");
customKey = customKeypad.getKey();
}
   if (customKey == '1')
   {
  Serial.print(customKey);
  Serial.println(" out");
 
  for (wristPos; wristPos < 179; wristPos++)
  {
  wrist.write(wristPos);              // tell servo to go to position in variable 'pos'
  delay(30);
  }
  for (waistPos; waistPos < 179; waistPos++)
  {
  waist.write(waistPos);              // tell servo to go to position in variable 'pos'
  delay(30);
  }
  receiveLoad();
  getBack();
   }
   
   if (customKey == '2')
   {
  Serial.print(customKey);
  Serial.println(" in");
  shoulder.write(130);
  for (shoulderPos; shoulderPos < 160; shoulderPos++)
  {
   shoulder.write(shoulderPos);              // tell servo to go to position in variable 'pos'
delay(30);
  }     
  Serial.println(waistPos);
  for (waistPos ; waistPos > 85; waistPos--)
  {
  waist.write(waistPos);              // tell servo to go to position in variable 'pos'
  delay(30);
  }
    
  receiveLoad();
  getBack();
   }

}

void loop() 
{ 
  int keyOn = digitalRead(key);

  automatic = digitalRead(2);  
  manual = digitalRead(4);
  
  
  if(manual) //manual
  {
    runManual();
getBack();
  }
  
  if(!manual && (keyOn == LOW))//automatic
  {
    runAutomatic();   
  }
 } 

All is well :)

Tuesday, April 1, 2014

Braț robotic #3

Proiectul robotului antropomorf a avansat.

Am construit un shield pentru cele 5 servomotoare, firele prea multe de pe breadboard, si ideea unui proiect final cât mai estetic cereau asta. Am modificat acest design în Eagle care conectează la cinci ieșiri PWM servomotoarele, un buton pentru selectarea modului automat sau manual de funcționare, și alți cinci pini pentru conectarea la joystick. Am îndepărtat din designul original condensatoarele pentru fiecare servo, și am adăugat unul singur paralel cu alimentarea.

Astfel arată shieldul imediat după transferul circuitului.



Astfel arată după lipirea tuturor componentelor.



Iar în acest clip am testat shieldul, folosind un cod de sweep pentru fiecare încheietură.




Curând, Braț robotic #4 !

Monday, February 24, 2014

Braț robotic #2

Am promis că vin cu actualizări despre minirobotul meu.

Primul post trecea în revistă piesele gata sosite de la imprimat și lansa speranța de a-l programa curând. Pentru că nu mai aveam răbdare și voiam să pun repede în aplicare ce doar în gând gândeam...am împrumutat un Arduino de la un coleg, al meu a făcut burn out - și iată! 


Ce vedeți aici e doar primul pas către un super robot..nu se mișcă grozav, daar:
  • știe stânga-dreapta, sau altfel spus, pot manevra yaw-ul
  • înainte-înapoi, adică rotații pe axa Ox, sau pitch..
  • prin apăsarea joystick-ului end-efectorul realizează o mișcare de strângere
Ce plănuiesc:
  • să realizez un PCB dedicat pentru a programa direct microcontrollerul, cu socket special pentru fiecare servo în parte
  • o bază mai profi decât două bucăți de lemn
  • sper un cod mai eficient
Apropo de cod, iată-l aici:
  #include <Servo.h> 
   
  Servo servo_h;  // create servo object to control horizontal movement
  Servo servo_v;   // create servo object to control horizontal movement
  Servo servo_eff; // create servo object to control the effector
   
  int buttonState = 0;         // variable for reading the pushbutton status
  int v = 1;
  int h = 0;  // analog pin used to connect the potentiometer
  int button = 12;
  int LED = 13;
  int val;    // variable to read the value from the analog pin 
   
  void setup() 
  { 
    pinMode(button, INPUT);
    pinMode(LED, OUTPUT);
    servo_h.attach(9);  // attaches the servo on pin 9 to the servo object 
    servo_v.attach(10);
    servo_eff.attach(11);
  } 
   
  void loop() 
  { 
    val = analogRead(h);            // reads the value of the potentiometer (value between 0 and 1023) 
    val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
    servo_h.write(val);                  // sets the servo position according to the scaled value 
    delay(15);                           // waits for the servo to get there 
    
    val = analogRead(v);            // reads the value of the potentiometer (value between 0 and 1023) 
    val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
    servo_v.write(val);                  // sets the servo position according to the scaled value 
    delay(15);                           // waits for the servo to get there 
    
    int pos = 0;
    buttonState = digitalRead(button);
    if(buttonState != HIGH)
    {
      digitalWrite(LED,HIGH);
      for(pos = 0; pos < 80; pos += 1)  // goes from 0 degrees to 180 degrees 
      {                                  // in steps of 1 degree 
        servo_eff.write(pos);              // tell servo to go to position in variable 'pos' 
        delay(15);                       // waits 15ms for the servo to reach the position 
      } 
      for(pos = 80; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
      {                                
        servo_eff.write(pos);              // tell servo to go to position in variable 'pos' 
        delay(15);                       // waits 15ms for the servo to reach the position 
      } 
       digitalWrite(LED,LOW);
   }
  } 


Am un alt proiect în derulare, de unde voi fura câteva idei despre placa de dezvoltare. Încet, încet prinde formă. Acel joystick grozav din video l-am primit de la http://www.diginesis.com/, am fost cu ei într-un weekend și am pilotat un hexacopter, a fost o experiență grozavă. Cum i-am cunoscut, și ce plănuim împreună cu altă ocazie. Sunt foaarte recunoscător pentru acel joystick :)


Gata! Înghețată!

Saturday, January 18, 2014

Buclă

Vine sesiunea și trebuie să predăm proiectele. Am fost destul de acid în privința unei anumite materii, dar acum că am terminat, împărtășesc cu voi roadele acesteia.

Am sentimente împărțite în legătură cu ce am postat anterior. Nu aș vrea să mai programez ceva asemănător, într-un astfel de mediu, dar ce am făcut este totuși o experiență.

Se pare, până la urmă, că și ce pare neînsemnat, are o oarecare importanță. (acuma, fie sistemul m-a răpus, devin unul de-al lor, fie metodele îmi mai ridică nițel nivelul... rămâne de văzut).

O ascult pe Marta.