Python Koda araç seçim ekranı nasıl eklenir?

kara2121

Decapat
Katılım
24 Temmuz 2021
Mesajlar
175
Daha fazla  
Sistem Özellikleri
AMD Ryzen 5 5500 // ASUS DUAL GeForce RTX 3060 OC 8GB // XPG Gammix D35 16GB (2×8) 3200MHz CL16 DDR4 Ram // ADATA Legend 750 500GB PCIe NVMe Okuma 3500MB – Yazma 3000MB M.2 SSD // VENTO VG10F RGB ATX Gaming Hyper Pro H3-650 650W 80+ Bronze Kasa
Cinsiyet
Erkek
Meslek
Öğrenci
Okulda takım olarak drone ve kara aracı tasarlıyoruz. Ben drone verilerini anlık olarak güncelleyen bir arayüz oluşturdum fakat buraya araç seçim sekmesi eklemem gerek. Nasıl ekleyebilirim?

Python:
from tkinter import *
from pymavlink import mavutil.
import datetime.
from PIL import Image, ImageTk.

address = 'udpin:localhost:14550'
# address = '/dev/ttyACM0'
# address = '/dev/ttyTHS1:115200'

vehicle = mavutil.mavlink_connection(address, baud=57600, autoreconnect=True)
vehicle.wait_heartbeat()
print('Bağlantı Başarılı')

root = Tk()
root.geometry("1280x720")
root.configure(bg = "#ffffff")

canvas = Canvas(
 root,
 bg = "#ffffff",
 height = 1080,
 width = 1920,
 bd = 0,
 highlightthickness = 0,
 relief = "ridge")
canvas.place(x = 0, y = 0)

background_img = PhotoImage(file = f"/home/kara/Templates/kara/background.png")
background = canvas.create_image(
 640.0, 370.0,
 image=background_img)

battery_label = Label(root, text="Batarya Yüzdesi: -", font=("Arial", 25), background='#D9D9D9')
battery_label.place(x=40, y=57)

lat_lng_label = Label(root, text="LAT: -\nLNG: -", font=("Arial", 25),background='#D9D9D9')
lat_lng_label.place(x=1252, y=57, anchor=NE)

altitude_label = Label(root, text="LNG: -", font=("Arial", 25), background='#D9D9D9')
altitude_label.place(x=1242, y=140, anchor=NE)

mode_label = Label(root, text="Uçuş Modu: -", font=("Arial", 25),background='#D9D9D9')
mode_label.place(x=25, y=665)

speed_label = Label(root, text="Hız: -", font=("Arial", 25),background='#D9D9D9')
speed_label.place(x=60, y=133)

pitch_label = Label(root, text="Pitch: -", font=("Arial", 25),background='#D9D9D9')
pitch_label.place(x=72, y=463)

roll_label = Label(root, text="Roll: -", font=("Arial", 25), background='#D9D9D9')
roll_label.place(x=75, y=393)

yaw_label = Label(root, text="Yaw: -", font=("Arial", 25), background='#D9D9D9')
yaw_label.place(x=1169, y=394, anchor=NE)

def update_info():
 msg = vehicle.recv_match(type='BATTERY_STATUS', blocking=True)
 battery_label.config(text=f'Batarya Yüzdesi: %{msg.battery_remaining}')

 msg2 = vehicle.recv_match(type='SIMSTATE', blocking=True)
 lat_lng_label.config(text=f'LAT: {msg2.lat}')

 msg4 = vehicle.recv_match(type='SIMSTATE', blocking=True)
 altitude_label.config(text=f'LNG: {msg4.lng}')

 msg3 = vehicle.recv_match(type='HEARTBEAT', blocking=True)
 mode = mavutil.mode_string_v10(msg3)
 mode_label.config(text=f'Uçuş Modu: {mode}')

 msg_speed = vehicle.recv_match(type='GPS_RAW_INT', blocking=True)
 speed_label.config(text=f'Hız: {msg_speed.vel} m/s')

 msg5 = vehicle.recv_match(type='AHRS2', blocking=True)
 pitch = str(msg5.pitch)[:4] # İlk 3 haneyi alır.
 pitch_label.config(text=f'Pitch: {pitch}')

 msg6 = vehicle.recv_match(type='AHRS2', blocking=True)
 roll = str(msg6.roll)[:4]
 roll_label.config(text=f'Roll: {pitch}')

 msg7 = vehicle.recv_match(type='AHRS2', blocking=True)
 yaw = str(msg7.yaw)[:3]
 yaw_label.config(text=f'Yaw: {yaw}')

 today = datetime.date.today()
 date_label.config(text=today.strftime('%d-%m-%Y'), background='#D9D9D9', font=('Arial', 25))

 root.after(2000, update_info) # Her 2 saniyede verileri yeniler.

def arm_disarm():
 vehicle.arducopter_arm()
 armed_label.config(text="Arm Durumu Değiştirildi", font=('Arial', 25))

arm_disarm_button = Button(root, text="Arm/Disarm", command=arm_disarm, background='#D9D9D9')
arm_disarm_button.place(x=30, y=593)

armed_label = Label(root, text="Armed/Disarmed: -", font=("Arial", 25), background='#D9D9D9')
armed_label.place(x=150, y=590)

date_label = Label(root, text="", font=("Arial", 20),background='white')
date_label.place(x=1230, y=664, anchor=NE)

update_info()
root.mainloop()
 
Okulda takım olarak drone ve kara aracı tasarlıyoruz. Ben drone verilerini anlık olarak güncelleyen bir arayüz oluşturdum fakat buraya araç seçim sekmesi eklemem gerek. Nasıl ekleyebilirim?

Python:
from tkinter import *
from pymavlink import mavutil.
import datetime.
from PIL import Image, ImageTk.

address = 'udpin:localhost:14550'
# address = '/dev/ttyACM0'
# address = '/dev/ttyTHS1:115200'

vehicle = mavutil.mavlink_connection(address, baud=57600, autoreconnect=True)
vehicle.wait_heartbeat()
print('Bağlantı Başarılı')

root = Tk()
root.geometry("1280x720")
root.configure(bg = "#ffffff")

canvas = Canvas(
 root,
 bg = "#ffffff",
 height = 1080,
 width = 1920,
 bd = 0,
 highlightthickness = 0,
 relief = "ridge")
canvas.place(x = 0, y = 0)

background_img = PhotoImage(file = f"/home/kara/Templates/kara/background.png")
background = canvas.create_image(
 640.0, 370.0,
 image=background_img)

battery_label = Label(root, text="Batarya Yüzdesi: -", font=("Arial", 25), background='#D9D9D9')
battery_label.place(x=40, y=57)

lat_lng_label = Label(root, text="LAT: -\nLNG: -", font=("Arial", 25),background='#D9D9D9')
lat_lng_label.place(x=1252, y=57, anchor=NE)

altitude_label = Label(root, text="LNG: -", font=("Arial", 25), background='#D9D9D9')
altitude_label.place(x=1242, y=140, anchor=NE)

mode_label = Label(root, text="Uçuş Modu: -", font=("Arial", 25),background='#D9D9D9')
mode_label.place(x=25, y=665)

speed_label = Label(root, text="Hız: -", font=("Arial", 25),background='#D9D9D9')
speed_label.place(x=60, y=133)

pitch_label = Label(root, text="Pitch: -", font=("Arial", 25),background='#D9D9D9')
pitch_label.place(x=72, y=463)

roll_label = Label(root, text="Roll: -", font=("Arial", 25), background='#D9D9D9')
roll_label.place(x=75, y=393)

yaw_label = Label(root, text="Yaw: -", font=("Arial", 25), background='#D9D9D9')
yaw_label.place(x=1169, y=394, anchor=NE)

def update_info():
 msg = vehicle.recv_match(type='BATTERY_STATUS', blocking=True)
 battery_label.config(text=f'Batarya Yüzdesi: %{msg.battery_remaining}')

 msg2 = vehicle.recv_match(type='SIMSTATE', blocking=True)
 lat_lng_label.config(text=f'LAT: {msg2.lat}')

 msg4 = vehicle.recv_match(type='SIMSTATE', blocking=True)
 altitude_label.config(text=f'LNG: {msg4.lng}')

 msg3 = vehicle.recv_match(type='HEARTBEAT', blocking=True)
 mode = mavutil.mode_string_v10(msg3)
 mode_label.config(text=f'Uçuş Modu: {mode}')

 msg_speed = vehicle.recv_match(type='GPS_RAW_INT', blocking=True)
 speed_label.config(text=f'Hız: {msg_speed.vel} m/s')

 msg5 = vehicle.recv_match(type='AHRS2', blocking=True)
 pitch = str(msg5.pitch)[:4] # İlk 3 haneyi alır.
 pitch_label.config(text=f'Pitch: {pitch}')

 msg6 = vehicle.recv_match(type='AHRS2', blocking=True)
 roll = str(msg6.roll)[:4]
 roll_label.config(text=f'Roll: {pitch}')

 msg7 = vehicle.recv_match(type='AHRS2', blocking=True)
 yaw = str(msg7.yaw)[:3]
 yaw_label.config(text=f'Yaw: {yaw}')

 today = datetime.date.today()
 date_label.config(text=today.strftime('%d-%m-%Y'), background='#D9D9D9', font=('Arial', 25))

 root.after(2000, update_info) # Her 2 saniyede verileri yeniler.

def arm_disarm():
 vehicle.arducopter_arm()
 armed_label.config(text="Arm Durumu Değiştirildi", font=('Arial', 25))

arm_disarm_button = Button(root, text="Arm/Disarm", command=arm_disarm, background='#D9D9D9')
arm_disarm_button.place(x=30, y=593)

armed_label = Label(root, text="Armed/Disarmed: -", font=("Arial", 25), background='#D9D9D9')
armed_label.place(x=150, y=590)

date_label = Label(root, text="", font=("Arial", 20),background='white')
date_label.place(x=1230, y=664, anchor=NE)

update_info()
root.mainloop()

Seçilebilecek araçların listesini oluşturun. Ardından, bu liste üzerinden bir optionmenu oluşturarak bu Widget'ı arayüzünüze yerleştirin.
Kullanıcı bir araç seçtiğinde, bu seçimi kaydeden bir callback fonksiyon tanımlayın. Bu fonksiyon, seçilen aracı global bir değişkene kaydedebilir.

Kod konusunda yardıma ihtiyacınız olursa eğer size yardımcı olmaya çalışırım.
 
Okulda takım olarak drone ve kara aracı tasarlıyoruz. Ben drone verilerini anlık olarak güncelleyen bir arayüz oluşturdum fakat buraya araç seçim sekmesi eklemem gerek. Nasıl ekleyebilirim?

Python:
from tkinter import *
from pymavlink import mavutil.
import datetime.
from PIL import Image, ImageTk.

address = 'udpin:localhost:14550'
# address = '/dev/ttyACM0'
# address = '/dev/ttyTHS1:115200'

vehicle = mavutil.mavlink_connection(address, baud=57600, autoreconnect=True)
vehicle.wait_heartbeat()
print('Bağlantı Başarılı')

root = Tk()
root.geometry("1280x720")
root.configure(bg = "#ffffff")

canvas = Canvas(
 root,
 bg = "#ffffff",
 height = 1080,
 width = 1920,
 bd = 0,
 highlightthickness = 0,
 relief = "ridge")
canvas.place(x = 0, y = 0)

background_img = PhotoImage(file = f"/home/kara/Templates/kara/background.png")
background = canvas.create_image(
 640.0, 370.0,
 image=background_img)

battery_label = Label(root, text="Batarya Yüzdesi: -", font=("Arial", 25), background='#D9D9D9')
battery_label.place(x=40, y=57)

lat_lng_label = Label(root, text="LAT: -\nLNG: -", font=("Arial", 25),background='#D9D9D9')
lat_lng_label.place(x=1252, y=57, anchor=NE)

altitude_label = Label(root, text="LNG: -", font=("Arial", 25), background='#D9D9D9')
altitude_label.place(x=1242, y=140, anchor=NE)

mode_label = Label(root, text="Uçuş Modu: -", font=("Arial", 25),background='#D9D9D9')
mode_label.place(x=25, y=665)

speed_label = Label(root, text="Hız: -", font=("Arial", 25),background='#D9D9D9')
speed_label.place(x=60, y=133)

pitch_label = Label(root, text="Pitch: -", font=("Arial", 25),background='#D9D9D9')
pitch_label.place(x=72, y=463)

roll_label = Label(root, text="Roll: -", font=("Arial", 25), background='#D9D9D9')
roll_label.place(x=75, y=393)

yaw_label = Label(root, text="Yaw: -", font=("Arial", 25), background='#D9D9D9')
yaw_label.place(x=1169, y=394, anchor=NE)

def update_info():
 msg = vehicle.recv_match(type='BATTERY_STATUS', blocking=True)
 battery_label.config(text=f'Batarya Yüzdesi: %{msg.battery_remaining}')

 msg2 = vehicle.recv_match(type='SIMSTATE', blocking=True)
 lat_lng_label.config(text=f'LAT: {msg2.lat}')

 msg4 = vehicle.recv_match(type='SIMSTATE', blocking=True)
 altitude_label.config(text=f'LNG: {msg4.lng}')

 msg3 = vehicle.recv_match(type='HEARTBEAT', blocking=True)
 mode = mavutil.mode_string_v10(msg3)
 mode_label.config(text=f'Uçuş Modu: {mode}')

 msg_speed = vehicle.recv_match(type='GPS_RAW_INT', blocking=True)
 speed_label.config(text=f'Hız: {msg_speed.vel} m/s')

 msg5 = vehicle.recv_match(type='AHRS2', blocking=True)
 pitch = str(msg5.pitch)[:4] # İlk 3 haneyi alır.
 pitch_label.config(text=f'Pitch: {pitch}')

 msg6 = vehicle.recv_match(type='AHRS2', blocking=True)
 roll = str(msg6.roll)[:4]
 roll_label.config(text=f'Roll: {pitch}')

 msg7 = vehicle.recv_match(type='AHRS2', blocking=True)
 yaw = str(msg7.yaw)[:3]
 yaw_label.config(text=f'Yaw: {yaw}')

 today = datetime.date.today()
 date_label.config(text=today.strftime('%d-%m-%Y'), background='#D9D9D9', font=('Arial', 25))

 root.after(2000, update_info) # Her 2 saniyede verileri yeniler.

def arm_disarm():
 vehicle.arducopter_arm()
 armed_label.config(text="Arm Durumu Değiştirildi", font=('Arial', 25))

arm_disarm_button = Button(root, text="Arm/Disarm", command=arm_disarm, background='#D9D9D9')
arm_disarm_button.place(x=30, y=593)

armed_label = Label(root, text="Armed/Disarmed: -", font=("Arial", 25), background='#D9D9D9')
armed_label.place(x=150, y=590)

date_label = Label(root, text="", font=("Arial", 20),background='white')
date_label.place(x=1230, y=664, anchor=NE)

update_info()
root.mainloop()
İlk önce bomboş bir pencere lazım sana. Daha sonra o pencereye 2 buton ekle; Drone ve Kara Aracı diye. Drone basılınca drone = True olsun daha sonra if drone == True: yazıp bu verileri if içine alın ve en sona else yazıp drone değişkenini False yapın. Aynı işlemleri kara aracınız için de yapın. Olmazsa daha zor başka yolları deneriz.
 

Geri
Yukarı