Robotergreifarm

Robotergreifarm :

 

Ziel ist es, einen Roboterarm mit 2 Achsen und einem Greifer zu programmieren und mit 2 Joysticks zu steuern.

 

Material :

 

- Arduino

 
- 2 Joysticks
- 2 Servos

- (selbstgebaute)Vorrichtung als Grundlage  des Robotergreifarms
 

Aufbau(ohne Arm) :

 

Steckplan

 

Bei den Joysticks sind jeweils die pins für den X und den Z Wert(bei einem Joystick) ausgelassen, da die Servos später nur durch den Z Wert gesteuert

Code :

 

Main.ino

 

#include "Joystick.h"
#include "Joystick2.h"

#include "Servo.h"
 
void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  joystick_setup();
  Servo_Setup();
  joystick_setup2();
}
void loop() {
  digitalWrite(13, HIGH);
 
  joystick_loop();
  joystick_loop2();
  joystick_loop3();
  Servo_loop();
 
}
 
 
 

Joystick.h

 

 

int xPin = A0;
int x = 0;
int yPin = A1;
int y = 0;
int btPin = 7;
int z = 0;
int yMap = 0;
void joystick_setup()
{
  pinMode(btPin, INPUT);
  digitalWrite(btPin, HIGH);
  Serial.begin(9600);
}
 

void joystick_loop()
{
 
  Serial.print("\tY: ");
  y = analogRead(yPin);
  yMap = MapY(y);
  Serial.print(y);
 
 
 yMap(analogRead(y), 0, 1025, 0, 180
  delay(50);
}
 
 

Joystick2.h

 

int xPin2 = A2;
int x2 = 0;
int yPin2 = A3;
int y2 = 0;
int btPin2 = 8;
int z2 = 0;
int yMap2 = 0;
void joystick_setup2()
{
  pinMode(btPin2, INPUT);
  digitalWrite(btPin2, HIGH);
  Serial.begin(9600);
}
 

void joystick_loop2()
{
  Serial.print("\tY2: ");
  y2 = analogRead(yPin2);
  yMap2 = MapY(y2);
  Serial.print(y2);
 
  Serial.print("\tZ2: ");
  z2 = digitalRead(btPin2);
  Serial.println(z2);
  yMap2 = (160 - map(analogRead(yPin2), 0, 1024, 0, 160) );
 
  if (z2 < 1 //Der Joystick muss gedrückt gehalten werden, sonst löst es sich wieder
{
   yMap2 = 160;            
 
}
 
 
 
  delay(50);
}
 
 

 

Servo.h

 

 

#include servo.h
Servo servo1;
Servo servo2;

void Servo_Setup() {

  servo1.attach(9);
  servo2.attach(10);
 
}
 
  void Servo_loop() {
  servo1.write(yMap);
  servo2.write(yMap2);
 
}