Erster Commit

This commit is contained in:
Robert Schoblick 2018-10-24 14:18:19 +02:00
commit 625bb3cb7e
6 changed files with 774 additions and 0 deletions

173
Programmierung_Arduino.ino Normal file
View File

@ -0,0 +1,173 @@
//Define sensors and servos
#include <Servo.h> //Includes servo library
Servo finger1, finger2, finger3, finger4, finger5;
int servoPin1 = 5; //gelb
int servoPin2 = 6; //gruen
int servoPin3 = 9; //blau
int servoPin4 = 10; //weiss
int servoPin5 = 3; //braun
int flexPin1 = A0; //Daumen (braun)
int flexPin2 = A1; //Zeigefinger (gelb)
int flexPin3 = A2; //Mittelfinger (gruen)
int flexPin4 = A3; //Ringfinger (blau)
int flexPin5 = A4; //kleiner Finger (weiss)
//A5 = NC
void setup()
{
Serial.begin(9600);
//Attach the servo objects to their respective pins
//Daumen (Sensor: braun, Servo: gelb)
finger1.attach(servoPin1);
//Zeigefinger (Sensor: gelb, Servo: gruen)
finger2.attach(servoPin2);
//Mittelfinger (Sensor: gruen, Servo: blau)
finger3.attach(servoPin3);
//Ringfinger (Sensor: blau, Servo: weiss)
finger4.attach(servoPin4);
//kleiner Finger (Sensor: weiss, Servo: braun)
finger5.attach(servoPin5);
/* set each servo pin to output; I'm not acutally sure if this is
even necessary, but I did just in case it is */
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2, OUTPUT);
pinMode(servoPin3, OUTPUT);
pinMode(servoPin4, OUTPUT);
pinMode(servoPin5, OUTPUT);
//Set each flex sensor pin to input: this is necessary
pinMode(flexPin1, INPUT);
pinMode(flexPin2, INPUT);
pinMode(flexPin3, INPUT);
pinMode(flexPin4, INPUT);
pinMode(flexPin5, INPUT);
}
int winkel = 145;
// Parameter der Sensoren
int daumen = 600;
int zfinger = 400;
int mfinger = 750;
int rfinger = 700;
int klfinger = 500;
void loop()
{
/* delay (80);*/
//Defines analog input variables
//Auslesen der Sensor-Widerstände
int flex1 = analogRead(flexPin1);
int flex2 = analogRead(flexPin2);
int flex3 = analogRead(flexPin3);
int flex4 = analogRead(flexPin4);
int flex5 = analogRead(flexPin5);
/* Defines "pos" variables as being proportional to the flex inputs.
The 400 to 700 value range seemed adequate for my sensors, but you can change
yours accordingly. */
//Daumen
/* int pos1 = map(flex1, 649, 650, 0, 1023);
pos1 = constrain(pos1, 0, 145); */
int pos1;
if (flex1 < daumen)
{
pos1 = 0;
}
else
{
pos1 = winkel;
}
//Zeigefinger
/* int pos2 = map(flex2, 449, 450, 0, 1023);
pos2 = constrain(pos2, 0, 145); */
int pos2;
if (flex2 < zfinger)
{
pos2 = 0;
}
else
{
pos2 = winkel;
}
//Mittelfinger
/* int pos3 = map(flex3, 949, 950, 0, 1023);
pos3 = constrain(pos3, 0, 145);*/
int pos3;
if (flex3 < mfinger)
{
pos3 = 0;
}
else
{
pos3 = winkel;
}
//Ringfinger
/* int pos4 = map(flex4, 599, 600, 0, 1023);
pos4 = constrain(pos4, 0, 145);*/
int pos4;
if (flex4 < rfinger)
{
pos4 = 0;
}
else
{
pos4 = winkel;
}
//kleiner Finger
/* int pos5 = map(flex5, 599, 600, 0, 1023);
pos5 = constrain(pos5, 0, 145); */
int pos5;
if (flex5 < klfinger)
{
pos5 = 0;
}
else
{
pos5 = winkel;
}
// Kontrollausgabe der Werte über Serial-Monitor
Serial.print(" Daumen ");
Serial.print(pos1);
Serial.print(" - ");
Serial.print(flex1);
Serial.print("*** Zeigefinger ");
Serial.print(pos2);
Serial.print(" - ");
Serial.print(flex2);
Serial.print("*** Mittelfinger ");
Serial.print(pos3);
Serial.print(" - ");
Serial.print(flex3);
Serial.print("*** Ringfinger ");
Serial.print(pos4);
Serial.print(" - ");
Serial.print(flex4);
Serial.print("*** kleiner Finger ");
Serial.print(pos5);
Serial.print(" - ");
Serial.print(flex5);
Serial.print("\n");
//Tells servos to move by the amount specified in the "pos" variables
finger1.write(pos1);
finger2.write(pos2);
finger3.write(pos3);
finger4.write(pos4);
finger5.write(pos5); //kleiner Finger (Sensor: weiss)
}

161
Roboterhand-kopie.ino Normal file
View File

@ -0,0 +1,161 @@
//Define sensors and servos
// servo.h instanziert Servo-Objekte und konfiguriert Ausgänge als PWM (bis zu 2ms Duty-Cycle bei 50Hz)
#include <Servo.h> //Includes servo library
Servo finger1, finger2, finger3, finger4, finger5;
int servoPin1 = 5; //gelb
int servoPin2 = 6; //gruen
int servoPin3 = 9; //blau
int servoPin4 = 10; //weiss
int servoPin5 = 3; //braun
int flexPin1 = A0; //Daumen (braun)
int flexPin2 = A1; //Zeigefinger (gelb)
int flexPin3 = A2; //Mittelfinger (gruen)
int flexPin4 = A3; //Ringfinger (blau)
int flexPin5 = A4; //kleiner Finger (weiss)
//A5 = NC
void setup()
{
Serial.begin(9600);
//Attach the servo objects to their respective pins
//Daumen (Sensor: braun, Servo: gelb)
finger1.attach(servoPin1);
//Zeigefinger (Sensor: gelb, Servo: gruen)
finger2.attach(servoPin2);
//Mittelfinger (Sensor: gruen, Servo: blau)
finger3.attach(servoPin3);
//Ringfinger (Sensor: blau, Servo: weiss)
finger4.attach(servoPin4);
//kleiner Finger (Sensor: weiss, Servo: braun)
finger5.attach(servoPin5);
/* Servo-Kontakte als Ausgang */
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2, OUTPUT);
pinMode(servoPin3, OUTPUT);
pinMode(servoPin4, OUTPUT);
pinMode(servoPin5, OUTPUT);
//Sensor-kontakte al EINGANG
pinMode(flexPin1, INPUT);
pinMode(flexPin2, INPUT);
pinMode(flexPin3, INPUT);
pinMode(flexPin4, INPUT);
pinMode(flexPin5, INPUT);
}
int winkel_0 = -10; // Winkel bei grossen Sensorwerten
int winkel_1 =150; // Winkel bei kleinen Sensorwerten
// Parameter der Sensoren
int daumen = 600; // sensor: Violett/Grau-1
int zfinger = 600; // Sensor: Blau/Grün
int mfinger = 600; // Sensor: Rot/Braun
int rfinger = 600; // Sensor: Violett/Grau-2
int klfinger = 600; // Sensor: Orange/Gelb
void loop()
{
// bei Bedarf: Entschleunigung der Durchläufe mit Delay in Millisekunden
/* delay (80);*/
//Auslesen der Sensor-Widerstände
int flex1 = analogRead(flexPin1);
int flex2 = analogRead(flexPin2);
int flex3 = analogRead(flexPin3);
int flex4 = analogRead(flexPin4);
int flex5 = analogRead(flexPin5);
//Daumen
int pos1;
if (flex1 < daumen)
{
pos1 = winkel_0;
}
else
{
pos1 = winkel_1;
}
//Zeigefinger
int pos2;
if (flex2 < zfinger)
{
pos2 = winkel_0;
}
else
{
pos2 = winkel_1;
}
//Mittelfinger
int pos3;
if (flex3 < mfinger)
{
pos3 = winkel_0;
}
else
{
pos3 = winkel_1;
}
//Ringfinger
int pos4;
if (flex4 < rfinger)
{
pos4 = winkel_0;
}
else
{
pos4 = winkel_1;
}
//kleiner Finger
int pos5;
if (flex5 < klfinger)
{
pos5 = winkel_0;
}
else
{
pos5 = winkel_1;
}
// Kontrollausgabe der Werte über Serial-Monitor
Serial.print(" Daumen ");
Serial.print(pos1);
Serial.print(" - ");
Serial.print(flex1);
Serial.print("*** Zeigefinger ");
Serial.print(pos2);
Serial.print(" - ");
Serial.print(flex2);
Serial.print("*** Mittelfinger ");
Serial.print(pos3);
Serial.print(" - ");
Serial.print(flex3);
Serial.print("*** Ringfinger ");
Serial.print(pos4);
Serial.print(" - ");
Serial.print(flex4);
Serial.print("*** kleiner Finger ");
Serial.print(pos5);
Serial.print(" - ");
Serial.print(flex5);
Serial.print("\n");
//Tells servos to move by the amount specified in the "pos" variables
finger1.write(pos1); //Daumen
finger2.write(pos2); //Zeigefinger
finger3.write(pos3); //Mittelfinger
finger4.write(pos4); //Ringfinger
finger5.write(pos5); //kleiner Finger (Sensor: weiss)
}

135
Roboterhand.ino Normal file
View File

@ -0,0 +1,135 @@
#include <Servo.h>
//Funktion zur Berechnung der Servo-Position
//Offset: nicht benötigter Bereich der Widerstandswerte
//flex: gemesener Widerstandswert
//Maximalwinkel: 150°; Minimalwinkel: -10°
//Rückgabe: Position des Servos
int position(int offset, int flex, int max)
{
int pos;
int div = (max - offset) / 10;
pos = (flex - offset) / div * 16;
if(pos < -10) pos = -30;
else if(pos > 150) pos = 140;
return pos;
}
Servo finger1, finger2, finger3, finger4, finger5;
int servoPin1 = 5; //gelb
int servoPin2 = 6; //gruen
int servoPin3 = 9; //blau
int servoPin4 = 10; //weiss
int servoPin5 = 3; //braun
int flexPin1 = A0; //Daumen (braun)
int flexPin2 = A1; //Zeigefinger (gelb)
int flexPin3 = A2; //Mittelfinger (gruen)
int flexPin4 = A3; //Ringfinger (blau)
int flexPin5 = A4; //kleiner Finger (weiss)
//A5 = Nc
void setup()
{
Serial.begin(9600);
//Die Pins und die entsprechenden Servos zusammenführen
//Daumen (Sensor: braun, Servo: gelb)
finger1.attach(servoPin1);
//Zeigefinger (Sensor: gelb, Servo: gruen)
finger2.attach(servoPin2);
//Mittelfinger (Sensor: gruen, Servo: blau)
finger3.attach(servoPin3);
//Ringfinger (Sensor: blau, Servo: weiss)
finger4.attach(servoPin4);
//kleiner Finger (Sensor: weiss, Servo: braun)
finger5.attach(servoPin5);
//Servo-Kontakte als Ausgang
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2, OUTPUT);
pinMode(servoPin3, OUTPUT);
pinMode(servoPin5, OUTPUT);
pinMode(servoPin4, OUTPUT);
//Sensor-Kontakte als Eingang
pinMode(flexPin1, INPUT);
pinMode(flexPin2, INPUT);
pinMode(flexPin3, INPUT);
pinMode(flexPin5, INPUT);
pinMode(flexPin4, INPUT);
}
void loop()
{
//Auslesen der Sensorwiderstände
int flex1 = analogRead(flexPin1);
int flex2 = analogRead(flexPin2);
int flex3 = analogRead(flexPin3);
int flex4 = analogRead(flexPin4);
int flex5 = analogRead(flexPin5);
//Daumen
int offset1 =100;
int max1 =600;
int pos1 = position(offset1, flex1, max1);
//Zeigefinger
int offset2 = 360;
int max2 = 640;
int pos2 = position(offset2, flex2, max2);
//Mittelfinger
int offset3 = 440;
int max3 = 650;
int pos3 = position(offset3, flex3, max3);
//Ringfinger
int offset4 = 470;
int max4 = 600;
int pos4 = position(offset4, flex4, max4);
//Kleiner Finger
int offset5 = 290;
int max5 = 530;
int pos5 = position(offset5, flex5, max5);
//Kontrollausgabe der Werte über den Serial-Monitor
Serial.print(" Daumen ");
Serial.print(pos1);
Serial.print(" - ");
Serial.print(flex1);
Serial.print("/// Zeigefinger");
Serial.print(pos2);
Serial.print(" - ");
Serial.print(flex2);
Serial.print("/// Mittelfinger");
Serial.print(pos3);
Serial.print(" - ");
Serial.print(flex3);
Serial.print("/// Ringfinger");
Serial.print(pos4);
Serial.print(" - ");
Serial.print(flex4);
Serial.print("/// KleinerFinger");
Serial.print(pos5);
Serial.print(" - ");
Serial.print(flex5);
Serial.print("\n");
//Gib dem Servo anhand von pos an wie weit er sich bewegen muss.
finger1.write(pos1);
finger2.write(pos2);
finger3.write(pos3);
finger4.write(pos4);
finger5.write(pos5);
}

142
fingerspiel.ino Normal file
View File

@ -0,0 +1,142 @@
//PWM-Duty-Cycle:
// 0Grad = 0,55 ms
// 5Grad = 0,6 ms
// 10Grad = 0,65 ms
// 15Grad = 0,7 ms
// 20Grad = 0,75 ms
// 25Grad = 0,8 ms
// 30Grad = 0,85 ms
// 35Grad = 0,9 ms
// 40 Grad = 0,95 ms
// 45 grad = 1,00 ms
// 50 Grad = 1,05 ms
// 55 Grad = 1,10 ms
// 60 Grad = 1,15 ms
// 65 Grad = 1,20 ms
// 70 Grad = 1,25 ms
// 75 Grad = 1,30 ms
// 80 Grad = 1,35 ms
// 85 Grad = 1,40 ms
// 90 Grad = 1,45 ms
// 180 Grad = 2,35ms
//Define sensors and servos
// servo.h instanziert Servo-Objekte und konfiguriert Ausgänge als PWM (bis zu 2ms Duty-Cycle bei 50Hz)
#include <Servo.h> //Includes servo library
Servo finger1, finger2, finger3, finger4, finger5;
int servoPin1 = 5; //gelb, kleiner Finger
int servoPin2 = 6; //gruen, Ringfinger
int servoPin3 = 9; //blau. Mittelfinger
int servoPin4 = 10; //weiss, Zeigefinger
int servoPin5 = 3; //braun, Daumen
int flexPin1 = A0; //Daumen (braun)
int flexPin2 = A1; //Zeigefinger (gelb)
int flexPin3 = A2; //Mittelfinger (gruen)
int flexPin4 = A3; //Ringfinger (blau)
int flexPin5 = A4; //kleiner Finger (weiss)
//A5 = NC
void setup()
{
Serial.begin(9600);
//Attach the servo objects to their respective pins
//Daumen (Sensor: braun, Servo: gelb)
finger1.attach(servoPin1);
//Zeigefinger (Sensor: gelb, Servo: gruen)
finger2.attach(servoPin2);
//Mittelfinger (Sensor: gruen, Servo: blau)
finger3.attach(servoPin3);
//Ringfinger (Sensor: blau, Servo: weiss)
finger4.attach(servoPin4);
//kleiner Finger (Sensor: weiss, Servo: braun)
finger5.attach(servoPin5);
/* Servo-Kontakte als Ausgang */
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2, OUTPUT);
pinMode(servoPin3, OUTPUT);
pinMode(servoPin4, OUTPUT);
pinMode(servoPin5, OUTPUT);
}
int winkel_1 = 145; // Winkel bei kleinen Sensorwerten
int winkel_2 =5; // Winkel bei grossen Sensorwerten
int speed1 = 800;
void loop()
{
int pos1;
int pos2;
int pos3;
int pos4;
int pos5;
pos1 = winkel_2;
finger1.write(pos1); //Daumen
delay (speed1);
pos2 = winkel_2;
finger2.write(pos2); //Zeigefinger
delay (speed1);
pos3 = winkel_2;
finger3.write(pos3); //Mittelfinger
delay (speed1);
pos4 = winkel_2;
finger4.write(pos4); //Ringfinger
delay (speed1);
pos5 = winkel_2;
finger5.write(pos5); //kleiner Finger (Sensor: weiss)
delay (speed1);
pos1 = winkel_1;
finger1.write(pos1); //Daumen
delay (speed1);
pos2 = winkel_1;
finger2.write(pos2); //Zeigefinger
delay (speed1);
pos3 = winkel_1;
finger3.write(pos3); //Mittelfinger
delay (speed1);
pos4 = winkel_1;
finger4.write(pos4); //Ringfinger
delay (speed1);
pos5 = winkel_1;
finger5.write(pos5); //kleiner Finger (Sensor: weiss)
delay (speed1);
// Kontrollausgabe der Werte über Serial-Monitor
/* Serial.print(" Daumen ");
Serial.print(pos1);
Serial.print(" - ");
Serial.print(flex1);
Serial.print("*** Zeigefinger ");
Serial.print(pos2);
Serial.print(" - ");
Serial.print(flex2);
Serial.print("*** Mittelfinger ");
Serial.print(pos3);
Serial.print(" - ");
Serial.print(flex3);
Serial.print("*** Ringfinger ");
Serial.print(pos4);
Serial.print(" - ");
Serial.print(flex4);
Serial.print("*** kleiner Finger ");
Serial.print(pos5);
Serial.print(" - ");
Serial.print(flex5);
Serial.print("\n");
*/
}

91
grundstellung.ino Normal file
View File

@ -0,0 +1,91 @@
//PWM-Duty-Cycle:
// 0Grad = 0,55 ms
// 5Grad = 0,6 ms
// 10Grad = 0,65 ms
// 15Grad = 0,7 ms
// 20Grad = 0,75 ms
// 25Grad = 0,8 ms
// 30Grad = 0,85 ms
// 35Grad = 0,9 ms
// 40 Grad = 0,95 ms
// 45 grad = 1,00 ms
// 50 Grad = 1,05 ms
// 55 Grad = 1,10 ms
// 60 Grad = 1,15 ms
// 65 Grad = 1,20 ms
// 70 Grad = 1,25 ms
// 75 Grad = 1,30 ms
// 80 Grad = 1,35 ms
// 85 Grad = 1,40 ms
// 90 Grad = 1,45 ms
// 180 Grad = 2,35ms
//Define sensors and servos
// servo.h instanziert Servo-Objekte und konfiguriert Ausgänge als PWM (bis zu 2ms Duty-Cycle bei 50Hz)
#include <Servo.h> //Includes servo library
Servo finger1, finger2, finger3, finger4, finger5;
/* Servo-Kontakte als Ausgang */
int servoPin1 = 5; //gelb
int servoPin2 = 6; //gruen
int servoPin3 = 9; //blau
int servoPin4 = 10; //weiss
int servoPin5 = 3; //braun
int flexPin1 = A0; //Daumen (braun)
int flexPin2 = A1; //Zeigefinger (gelb)
int flexPin3 = A2; //Mittelfinger (gruen)
int flexPin4 = A3; //Ringfinger (blau)
int flexPin5 = A4; //kleiner Finger (weiss)
//A5 = NC
void setup()
{
Serial.begin(9600);
//Attach the servo objects to their respective pins
//Daumen (Sensor: braun, Servo: gelb)
finger1.attach(servoPin1);
//Zeigefinger (Sensor: gelb, Servo: gruen)
finger2.attach(servoPin2);
//Mittelfinger (Sensor: gruen, Servo: blau)
finger3.attach(servoPin3);
//Ringfinger (Sensor: blau, Servo: weiss)
finger4.attach(servoPin4);
//kleiner Finger (Sensor: weiss, Servo: braun)
finger5.attach(servoPin5);
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2, OUTPUT);
pinMode(servoPin3, OUTPUT);
pinMode(servoPin4, OUTPUT);
pinMode(servoPin5, OUTPUT);
int winkel_0 = 10; // Winkel bei kleinen Sensorwerten
int pos1 = winkel_0;
int pos2 = winkel_0;
int pos3 = winkel_0;
int pos4 = winkel_0;
int pos5 = winkel_0;
//Tells servos to move by the amount specified in the "pos" variables
finger1.write(pos1); //Daumen
finger2.write(pos2); //Zeigefinger
finger3.write(pos3); //Mittelfinger
finger4.write(pos4); //Ringfinger
finger5.write(pos5); //kleiner Finger (Sensor: weiss)
}

72
servotest.ino Normal file
View File

@ -0,0 +1,72 @@
//PWM-Duty-Cycle:
// 0Grad = 0,55 ms
// 5Grad = 0,6 ms
// 10Grad = 0,65 ms
// 15Grad = 0,7 ms
// 20Grad = 0,75 ms
// 25Grad = 0,8 ms
// 30Grad = 0,85 ms
// 35Grad = 0,9 ms
// 40 Grad = 0,95 ms
// 45 grad = 1,00 ms
// 50 Grad = 1,05 ms
// 55 Grad = 1,10 ms
// 60 Grad = 1,15 ms
// 65 Grad = 1,20 ms
// 70 Grad = 1,25 ms
// 75 Grad = 1,30 ms
// 80 Grad = 1,35 ms
// 85 Grad = 1,40 ms
// 90 Grad = 1,45 ms
// 180 Grad = 2,35ms
//Define sensors and servos
// servo.h instanziert Servo-Objekte und konfiguriert Ausgänge als PWM (bis zu 2ms Duty-Cycle bei 50Hz)
#include <Servo.h> //Includes servo library
Servo motor1;
int servoPin1 = 3; //gelb
int winkel_1 = 180; // Winkel bei grossen Sensorwerten
int winkel_0 = 0; // Winkel bei kleinen Sensorwerten
int speed1 = 10;
void setup()
{
Serial.begin(9600);
//Attach the servo objects to their respective pins
//Daumen (Sensor: braun, Servo: gelb)
motor1.attach(servoPin1);
/* Servo-Kontakte als Ausgang */
pinMode(servoPin1, OUTPUT);
}
void loop()
{
//Motor
int pos;
for(pos=winkel_0; pos<winkel_1; pos++) {
Serial.print("Winkel: ");
Serial.print(pos);
Serial.print("\n");
motor1.write(pos);
delay(speed1);
}
for(pos=winkel_1; pos>winkel_0; pos--) {
Serial.print("Winkel: ");
Serial.print(pos);
Serial.print("\n");
motor1.write(pos);
delay(speed1);
}
}