ROBOTIC ARM

Odpovědět
lukas700602
Příspěvky: 22
Registrován: 10 úno 2019, 22:17
Reputation: 0

ROBOTIC ARM

Příspěvek od lukas700602 » 13 dub 2019, 22:00

Zdravím , prednedávnom som začal pracovať na robotickej ruke , ale neviem si rady s počítaním stlačení tlačidla na joysticku.

Kód: Vybrat vše

if(digitalRead(button1) == LOW){
    button1Presses++;
    switch(button1Presses){
      case 1:
        servo1PosSaves[0] = xValue1Angle;
        servo2PosSaves[0] = yValue1Angle;
        servo3PosSaves[0] = xValue2Angle;
        servo4PosSaves[0] = yValue2Angle;
        Serial.println("Pos 1 Saved");
        break;
      case 2:
        servo1PosSaves[1] = xValue1Angle;
        servo2PosSaves[1] = yValue1Angle;
        servo3PosSaves[1] = xValue2Angle;
        servo4PosSaves[1] = yValue2Angle;
        Serial.println("Pos 2 Saved");
        break;
      case 3:
        servo1PosSaves[2] = xValue1Angle;
        servo2PosSaves[2] = yValue1Angle;
        servo3PosSaves[2] = xValue2Angle;
        servo4PosSaves[2] = yValue2Angle;
        Serial.println("Pos 3 Saved");
        break;
      case 4:
        servo1PosSaves[3] = xValue1Angle;
        servo2PosSaves[3] = yValue1Angle;
        servo3PosSaves[3] = xValue2Angle;
        servo4PosSaves[3] = yValue2Angle;
        Serial.println("Pos 4 Saved");
        break;
      case 5:
        servo1PosSaves[4] = xValue1Angle;
        servo2PosSaves[4] = yValue1Angle;
        servo3PosSaves[4] = xValue2Angle;
        servo4PosSaves[4] = yValue2Angle;
        Serial.println("Pos 5 Saved");
        break;
  }
takto to vyzerá , neviem v čom je problém.




A následne takto vyzerá celý program:

Kód: Vybrat vše

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;



//analog
const int XPin1 = A0;
const int YPin1 = A1;
const int XPin2 = A2;
const int YPin2 = A3;
const int button1 = 8; //Buttons
const int button2 = 7;


int button1Presses = 0;

boolean button2Pressed = false;

int x1Value = analogRead(XPin1);                
int y1Value = analogRead(YPin1);
int x2Value = analogRead(XPin2);
int y2Value = analogRead(YPin2);

int servo1PosSaves[] = {1,1,1,1,1}; 
int servo2PosSaves[] = {1,1,1,1,1};
int servo3PosSaves[] = {1,1,1,1,1};
int servo4PosSaves[] = {1,1,1,1,1};

void setup() {
  servo1.attach(3);
  servo2.attach(5,80,160);
  servo3.attach(10,0,90);
  servo4.attach(9);

  pinMode(button1,INPUT_PULLUP);
  pinMode(button2,INPUT_PULLUP);
 
 
  
  Serial.begin(9600);
}




void loop() {
  int xValue1 = analogRead(XPin1);
  int xValue1Angle = map(xValue1, 0, 1023, 0, 180);
  int yValue1 = analogRead(YPin1);
  int yValue1Angle = map(yValue1, 0, 1023, 80, 160);
  int xValue2 = analogRead(XPin2);
  int xValue2Angle = map(xValue2, 0, 1023, 0, 90);
  int yValue2 = analogRead(YPin2);
  int yValue2Angle = map(yValue2, 0, 1023, 0, 90);
  
  
  
  servo1.write(xValue1Angle);
  servo2.write(yValue1Angle);
  servo3.write(xValue2Angle);
  servo4.write(yValue2Angle);

  if(digitalRead(button1) == LOW){
    button1Presses++;
    switch(button1Presses){
      case 1:
        servo1PosSaves[0] = xValue1Angle;
        servo2PosSaves[0] = yValue1Angle;
        servo3PosSaves[0] = xValue2Angle;
        servo4PosSaves[0] = yValue2Angle;
        Serial.println("Pos 1 Saved");
        break;
      case 2:
        servo1PosSaves[1] = xValue1Angle;
        servo2PosSaves[1] = yValue1Angle;
        servo3PosSaves[1] = xValue2Angle;
        servo4PosSaves[1] = yValue2Angle;
        Serial.println("Pos 2 Saved");
        break;
      case 3:
        servo1PosSaves[2] = xValue1Angle;
        servo2PosSaves[2] = yValue1Angle;
        servo3PosSaves[2] = xValue2Angle;
        servo4PosSaves[2] = yValue2Angle;
        Serial.println("Pos 3 Saved");
        break;
      case 4:
        servo1PosSaves[3] = xValue1Angle;
        servo2PosSaves[3] = yValue1Angle;
        servo3PosSaves[3] = xValue2Angle;
        servo4PosSaves[3] = yValue2Angle;
        Serial.println("Pos 4 Saved");
        break;
      case 5:
        servo1PosSaves[4] = xValue1Angle;
        servo2PosSaves[4] = yValue1Angle;
        servo3PosSaves[4] = xValue2Angle;
        servo4PosSaves[4] = yValue2Angle;
        Serial.println("Pos 5 Saved");
        break;
  }
 }
  if(digitalRead(button2) == LOW){
    button2Pressed = true;
  }

  if(button2Pressed){
    for(int i = 0; i < 5; i++){
      servo1.write(servo1PosSaves[i]);
      servo2.write(servo2PosSaves[i]);
      servo3.write(servo3PosSaves[i]);
      servo4.write(servo4PosSaves[i]);
      Serial.println(" Uhly Joysticku: ");
      Serial.println(servo1PosSaves[i]);
      Serial.println(servo2PosSaves[i]);
      Serial.println(servo3PosSaves[i]);
      Serial.println(servo4PosSaves[i]);
      delay(1050);
      break;
    }  
  }
}

lukas700602
Příspěvky: 22
Registrován: 10 úno 2019, 22:17
Reputation: 0

Re: ROBOTIC ARM

Příspěvek od lukas700602 » 13 dub 2019, 22:20

Dobre zapamätávanie pozicie som vyriešil a takisto aj počítanie stlačení , ale naskytol sa tu taký problém , že si zapamätá iba poslednú pozíciu :lol:

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Google [Bot] a 0 hostů