Bläddra i källkod

add first files

Nico 1 år sedan
incheckning
2b2c2728c9
3 ändrade filer med 182 tillägg och 0 borttagningar
  1. 12 0
      Gripper.py
  2. 100 0
      Gripper/Gripper.ino
  3. 70 0
      Gripper_gui_test.py

+ 12 - 0
Gripper.py

@@ -0,0 +1,12 @@
+import serial
+import time
+arduino = serial.Serial(port='COM7', baudrate=9600, timeout=.1)
+def write_read(x):
+    arduino.write(bytes(x, 'utf-8'))
+    time.sleep(0.05)
+    data = arduino.readline()
+    return data
+while True:
+    num = input("Enter a number: ") # Taking input from user
+    value = write_read(num)
+    print(value) # printing the value

+ 100 - 0
Gripper/Gripper.ino

@@ -0,0 +1,100 @@
+#include "Arduino.h"
+#include "AX12A.h"
+
+#define DirectionPin 	(10u)
+#define BaudRate  		(1000000ul)
+#define ID1				(4u)
+
+#include <XYZrobotServo.h>
+
+#ifdef SERIAL_PORT_HARDWARE_OPEN
+#define servoSerial SERIAL_PORT_HARDWARE_OPEN
+#else
+#include <SoftwareSerial.h>
+SoftwareSerial servoSerial(10, 11);
+#endif
+
+int input = 0;
+XYZrobotServo servo1(servoSerial, 2);
+XYZrobotServo servo2(servoSerial, 3);
+
+const uint8_t playtime = 200;
+
+
+int x;
+int val[10] = {0,0,0,0,0};
+int position,lastposition_ax12 = 512;
+int choice;
+
+void ax12(int position){
+  if((position<300) && (position>700)){
+    Serial.print("invalide position. Try again");
+    return;
+  }
+  if(lastposition_ax12<position){
+  for(int i = lastposition_ax12;i<position;i=i+1){
+    ax12a.move(ID1,i);
+    delay(10);
+  }
+  }
+  if(lastposition_ax12>position){
+    for(int i = lastposition_ax12;i>position;i=i-1){
+    ax12a.move(ID1,i);
+    delay(10);
+  }
+  }
+
+  lastposition_ax12 = position;
+}
+
+void a116_1(int position){
+  servo1.setPosition(position, playtime);
+}
+void a116_2(int position){
+  servo2.setPosition(position, playtime);
+}
+
+void setup() {
+  Serial.begin(9600);
+  Serial.setTimeout(1);
+
+  ax12a.begin(BaudRate, DirectionPin, &Serial3);
+  ax12a.setEndless(ID1, OFF);
+
+  servoSerial.begin(115200);
+
+  ax12a.move(ID1,512);
+  servo1.setPosition(512, playtime);
+  servo2.setPosition(512, playtime);
+}
+void loop() {
+ if (Serial.available()){
+   //Serial.print(test);
+   for(int n = 0; n < 10 ; n++){
+    val[n] = Serial.readString().toInt();
+    //Serial.print(x);
+    //Serial.print(n);
+
+   }
+   position = 0 ;
+   for(int i = 2; i < 5;i++){
+     position = position * 10 + val[i];
+   }
+   choice = val[0];
+   Serial.print("Motor: ");
+   Serial.print(choice);
+   Serial.print(" position: ");
+   Serial.print(position);
+  switch(val[0]){
+    case 1:
+    ax12(position);
+    break;
+    case 2:
+    a116_1(position);
+    break;
+    case 3:
+    a116_2(position);
+    break;
+  }
+ }
+}

+ 70 - 0
Gripper_gui_test.py

@@ -0,0 +1,70 @@
+import PySimpleGUI as sg
+
+slider_width = 100
+slider_hight = 40
+button_width = 10
+button_hight = 3
+# GUI-Layout definieren
+#sg.theme('DarkGreen')
+layout = [
+    [sg.Text('Servomotor 1')],
+    [sg.Slider(range=(300, 700), size=(slider_width, slider_hight), default_value=512, orientation='h', key='-SLIDER1-'), sg.Button('Reset', key='-BUTTON1-',size=(button_width,button_hight))],    #enable_events=True,
+    [sg.Text('Servomotor 2')],
+    [sg.Slider(range=(300, 700), size=(slider_width, slider_hight), default_value=512, orientation='h', key='-SLIDER2-'), sg.Button('Reset', key='-BUTTON2-',size=(button_width,button_hight))],     #enable_events=True,
+    [sg.Text('Servomotor 3')],
+    [sg.Slider(range=(300, 700), size=(slider_width, slider_hight), default_value=512, orientation='h', key='-SLIDER3-'), sg.Button('Reset', key='-BUTTON3-',size=(button_width,button_hight))], #enable_events=True,
+    [sg.Text('Motor')],
+    [sg.Slider(range=(300, 700), size=(slider_width, slider_hight), default_value=512, orientation='h', key='-SLIDER4-'), sg.Button('Reset', key='-BUTTON4-',size=(button_width,button_hight))],
+    [sg.Button('OK',size=(button_width,button_hight)),sg.Button('Reset',key='-BUTTON5-',size=(button_width,button_hight))]
+]
+
+# GUI erstellen
+window = sg.Window('Slider GUI', layout,resizable=True,ttk_theme='classic')
+# GUI-Ereignisschleife
+while True:
+    event, values = window.read()       #timeout=20
+    if event == sg.WINDOW_CLOSED:
+        break
+    if event == '-BUTTON1-':
+        print('Button 1 was clicked')
+        window['-SLIDER1-'].update(512)
+        values['-SLIDER1-']=512.0
+    elif event == '-BUTTON2-':
+        print('Button 2 was clicked')
+        window['-SLIDER2-'].update(512)
+        values['-SLIDER2-']=512.0
+    elif event == '-BUTTON3-':
+        print('Button 3 was clicked')
+        window['-SLIDER3-'].update(512)
+        values['-SLIDER3-']=512.0
+    elif event == '-BUTTON4-':
+        print('Button 4 was clicked')
+        window['-SLIDER4-'].update(512)
+        values['-SLIDER4-']=512.0
+    elif event == '-BUTTON5-':
+        print('Button 5 was clicked')
+        window['-SLIDER1-'].update(512)
+        values['-SLIDER1-']=512.0
+        window['-SLIDER2-'].update(512)
+        values['-SLIDER2-']=512.0
+        window['-SLIDER3-'].update(512)
+        values['-SLIDER3-']=512.0
+        window['-SLIDER4-'].update(512)
+        values['-SLIDER4-']=512.0
+    # Werte der Schieberegler abrufen
+    slider1_value = values['-SLIDER1-']
+    slider2_value = values['-SLIDER2-']
+    slider3_value = values['-SLIDER3-']
+    slider4_value = values['-SLIDER4-']
+
+    # Beispiel: Ausgabe der aktuellen Werte der Schieberegler
+    print("Slider 1:", slider1_value)
+    print("Slider 2:", slider2_value)
+    print("Slider 3:", slider3_value)
+    print("Slider 4:", slider4_value)
+
+# GUI schließen
+window.close()
+
+
+