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ă!
No comments:
Post a Comment