diff --git a/.idea/copilot/chatSessions/00000000000.xd b/.idea/copilot/chatSessions/00000000000.xd
deleted file mode 100644
index 1ed455a..0000000
Binary files a/.idea/copilot/chatSessions/00000000000.xd and /dev/null differ
diff --git a/.idea/copilot/chatSessions/blobs/version b/.idea/copilot/chatSessions/blobs/version
deleted file mode 100644
index 720d64f..0000000
Binary files a/.idea/copilot/chatSessions/blobs/version and /dev/null differ
diff --git a/.idea/graduation_design.iml b/.idea/graduation_design.iml
index 2b7133e..e8b04d0 100644
--- a/.idea/graduation_design.iml
+++ b/.idea/graduation_design.iml
@@ -5,7 +5,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..247cf65
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 81cb2bb..d65f9a8 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,31 +4,69 @@
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -44,23 +82,25 @@
- {
+ "keyToString": {
+ "Python.App.executor": "Run",
+ "Python.FRRobot.executor": "Run",
+ "Python.ObjectClassify.executor": "Run",
+ "Python.control.executor": "Run",
+ "Python.hand_control.executor": "Run",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "last_opened_file_path": "C:/Users/SF/Downloads/PathPlanningVisualizer",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -68,7 +108,7 @@
-
+
@@ -82,7 +122,7 @@
-
+
@@ -93,7 +133,7 @@
-
+
@@ -118,7 +158,21 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -144,7 +198,15 @@
1711895216612
-
+
+
+ 1711951173395
+
+
+
+ 1711951173395
+
+
@@ -153,11 +215,14 @@
-
+
+
-
-
+
+
+
+
\ No newline at end of file
diff --git a/App.py b/App.py
new file mode 100644
index 0000000..62585e6
--- /dev/null
+++ b/App.py
@@ -0,0 +1,140 @@
+import tkinter as tk
+from PIL import Image, ImageTk
+import torch
+from ultralytics import YOLO
+import cv2
+from orbbec_camera.OrbbecCamera import OrbbecCamera
+from robot_control.FRRobot import FRRobot
+
+# 全局变量
+model = YOLO('yolov8n.pt')
+camera = OrbbecCamera('HW', True, image_width=640)
+robot_controller = FRRobot()
+correction_factor = 1
+center_point = 320
+
+
+class App:
+ def __init__(self, window, window_title):
+ self.window = window
+ self.window.title(window_title)
+ self.window.geometry("1280x720") # 设置窗口大小
+
+ # 设置图像帧,并固定大小
+ self.frame = tk.Label(self.window)
+ self.frame.grid(row=0, column=0, columnspan=3, padx=320, pady=20)
+
+ # 设置文本输出区域
+ self.text = tk.Text(self.window, height=10, width=50)
+ self.text.grid(row=3, column=0, columnspan=3, padx=320, pady=20)
+
+ # 控制按钮,居中对齐
+ self.btn_start = tk.Button(self.window, text="Start", command=self.start)
+ self.btn_start.grid(row=4, column=0, sticky="ew", padx=(106, 3))
+
+ self.btn_stop = tk.Button(self.window, text="Stop", command=self.stop)
+ self.btn_stop.grid(row=4, column=2, sticky="ew", padx=(3, 106))
+
+ self.btn_home = tk.Button(self.window, text="Home", command=self.to_home)
+ self.btn_home.grid(row=4, column=1, sticky="ew")
+
+ # 机械臂运动标志位
+ self.is_arm_moving_label = tk.Label(self.window, text="机械臂运动标志位: False", font=("Arial", 12))
+ self.is_arm_moving_label.grid(row=5, column=0, columnspan=1, sticky="ew", pady=10)
+
+ # 抓取动作标志位
+ self.is_catch_moving_label = tk.Label(self.window, text="抓取动作标志位: False", font=("Arial", 12))
+ self.is_catch_moving_label.grid(row=6, column=0, columnspan=1, sticky="ew", pady=10)
+
+ self.running = False
+ self.update_flag() # 初始化定时更新
+
+ self.window.mainloop()
+
+ def log(self, message):
+ self.text.insert(tk.END, message + '\n')
+ self.text.see(tk.END)
+
+ def start(self):
+ self.running = True
+ self.log("启动摄像头...")
+ camera.run()
+ self.to_home()
+ self.process_video_frame()
+
+ def stop(self):
+ self.running = False
+ self.log("停止中...")
+ camera.stop()
+ robot_controller.add_move_command("home")
+ robot_controller.add_move_command("stop")
+
+ def to_home(self):
+ self.log("回到原点...")
+ robot_controller.add_move_command("home")
+
+ def process_video_frame(self):
+ if self.running:
+ color_image = camera.get_color_image()
+ if color_image is not None:
+ self.display_image(color_image)
+ results = model.predict(source=color_image,
+ show=True,
+ conf=0.5,
+ half=True,
+ imgsz=640,
+ verbose=False)
+ self.handle_detection_results(results)
+
+ self.window.after(30, self.process_video_frame)
+
+ def display_image(self, img):
+ img_cv = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+ img_pil = Image.fromarray(img_cv)
+ img_tk = ImageTk.PhotoImage(image=img_pil)
+ self.frame.imgtk = img_tk
+ self.frame.configure(image=img_tk)
+
+ def handle_detection_results(self, results):
+ for r in results:
+ if len(r.boxes.xywh) > 0 and not robot_controller.catch_moving and not robot_controller.is_arm_moving:
+ positions = r.boxes.xywh.tolist()
+ x_pos, y_pos, high, width = positions[0]
+ x_distance = (x_pos - center_point) * correction_factor
+ y_distance = (y_pos - center_point) * correction_factor
+
+ self.log(f"X距离: {x_distance}, Y距离: {y_distance}")
+
+ move_commands = []
+ if abs(x_distance) > 15:
+ move_commands.append(("x", x_distance))
+ if abs(y_distance) > 15:
+ move_commands.append(("y", y_distance))
+
+ if abs(x_distance) < 15 and abs(y_distance) < 15:
+ self.log("到达指定位置")
+ robot_controller.catch_moving = True
+ if camera.get_center_distance() <= 0:
+ self.log("抓取物体距离过近或相机参数错误,无法执行抓取")
+ robot_controller.catch_moving = False
+ continue
+ robot_controller.add_catch_commands(["catch", camera.get_center_distance()])
+ self.log(f"执行抓取命令,深度: {camera.get_center_distance()} mm")
+
+ if move_commands:
+ self.log(f"添加移动指令: {move_commands}")
+ if not robot_controller.is_arm_moving:
+ self.log(f"发送指令: {move_commands}")
+ robot_controller.add_move_command(move_commands)
+
+ def update_flag(self):
+ self.is_arm_moving_label.config(text='机械臂运动标志位: ' + str(robot_controller.is_arm_moving))
+ self.is_catch_moving_label.config(text='抓取动作标志位: ' + str(robot_controller.catch_moving))
+ # 每1000毫秒(1秒)调用一次自身,持续更新标志位
+ self.window.after(500, self.update_flag)
+
+
+# 主运行环境
+if __name__ == '__main__':
+ root = tk.Tk()
+ app = App(root, "Robot Camera Control")
diff --git a/Log/OrbbecSDK.log.txt b/Log/OrbbecSDK.log.txt
new file mode 100644
index 0000000..bcfbe58
Binary files /dev/null and b/Log/OrbbecSDK.log.txt differ
diff --git a/ObjectClassify.py b/abandon_code/ObjectClassify.py
similarity index 79%
rename from ObjectClassify.py
rename to abandon_code/ObjectClassify.py
index 38b9bcb..d64805b 100644
--- a/ObjectClassify.py
+++ b/abandon_code/ObjectClassify.py
@@ -1,11 +1,5 @@
-import asyncio
-import os
-import threading
-
-from time import sleep
-import Robot
import torch
-from torch import tensor
+
from ultralytics import YOLO
import cv2
from orbbec_camera.OrbbecCamera import OrbbecCamera
@@ -28,7 +22,7 @@ def init():
global image_width
# 检测GPU是否存在
if not torch.cuda.is_available():
- print("你忘了打开独显,大聪明")
+ print("独立显卡未启用")
exit(1)
# 输入的视频的宽度
image_width = 640
@@ -38,7 +32,6 @@ def init():
if __name__ == '__main__':
# 初始化
init()
-
# 处理循环
while True:
color_image = camera.get_color_image()
@@ -60,7 +53,9 @@ if __name__ == '__main__':
high = 0
width = 0
for r in results:
- if len(r.boxes.xywh) > 0:
+ print("robot_controller.catch_moving: ", robot_controller.catch_moving)
+ print("robot_controller.is_arm_moving: ", robot_controller.is_arm_moving)
+ if len(r.boxes.xywh) > 0 and robot_controller.catch_moving is False and robot_controller.is_arm_moving is False:
positions = r.boxes.xywh.tolist()
x_pos = positions[0][0]
y_pos = positions[0][1]
@@ -87,8 +82,15 @@ if __name__ == '__main__':
y_dir = 1 if y_distance < 0 else 0
move_commands.append(("y", y_distance))
+ if abs(x_distance) < 15 and abs(y_distance) < 15:
+ print("到达指定位置")
+ robot_controller.catch_moving = True
+ robot_controller.add_catch_commands(["catch", camera.get_center_distance()])
+
if len(move_commands) > 0:
- if not robot_controller.is_action:
+ print("添加移动指令: ", move_commands)
+ if not robot_controller.is_arm_moving:
+ print("发送指令: ", move_commands)
# 添加移动指令
robot_controller.add_move_command(move_commands)
diff --git a/robot_control/control.py b/abandon_code/control.py
similarity index 100%
rename from robot_control/control.py
rename to abandon_code/control.py
diff --git a/robot_control/examples/ConveyorTrack.py b/abandon_code/examples/ConveyorTrack.py
similarity index 100%
rename from robot_control/examples/ConveyorTrack.py
rename to abandon_code/examples/ConveyorTrack.py
diff --git a/robot_control/examples/ConveyorTrackRecord.py b/abandon_code/examples/ConveyorTrackRecord.py
similarity index 100%
rename from robot_control/examples/ConveyorTrackRecord.py
rename to abandon_code/examples/ConveyorTrackRecord.py
diff --git a/robot_control/examples/ConveyorTrackSet.py b/abandon_code/examples/ConveyorTrackSet.py
similarity index 100%
rename from robot_control/examples/ConveyorTrackSet.py
rename to abandon_code/examples/ConveyorTrackSet.py
diff --git a/robot_control/examples/TrajectoryJ_repetition.py b/abandon_code/examples/TrajectoryJ_repetition.py
similarity index 100%
rename from robot_control/examples/TrajectoryJ_repetition.py
rename to abandon_code/examples/TrajectoryJ_repetition.py
diff --git a/robot_control/examples/force_compliance.py b/abandon_code/examples/force_compliance.py
similarity index 100%
rename from robot_control/examples/force_compliance.py
rename to abandon_code/examples/force_compliance.py
diff --git a/robot_control/examples/force_control.py b/abandon_code/examples/force_control.py
similarity index 100%
rename from robot_control/examples/force_control.py
rename to abandon_code/examples/force_control.py
diff --git a/robot_control/examples/force_find_surface_calcenter.py b/abandon_code/examples/force_find_surface_calcenter.py
similarity index 100%
rename from robot_control/examples/force_find_surface_calcenter.py
rename to abandon_code/examples/force_find_surface_calcenter.py
diff --git a/robot_control/examples/force_guard.py b/abandon_code/examples/force_guard.py
similarity index 100%
rename from robot_control/examples/force_guard.py
rename to abandon_code/examples/force_guard.py
diff --git a/robot_control/examples/force_load_identification.py b/abandon_code/examples/force_load_identification.py
similarity index 100%
rename from robot_control/examples/force_load_identification.py
rename to abandon_code/examples/force_load_identification.py
diff --git a/robot_control/examples/force_payload_identify.py b/abandon_code/examples/force_payload_identify.py
similarity index 100%
rename from robot_control/examples/force_payload_identify.py
rename to abandon_code/examples/force_payload_identify.py
diff --git a/robot_control/examples/force_rot_insertion.py b/abandon_code/examples/force_rot_insertion.py
similarity index 100%
rename from robot_control/examples/force_rot_insertion.py
rename to abandon_code/examples/force_rot_insertion.py
diff --git a/robot_control/examples/force_sensor_set.py b/abandon_code/examples/force_sensor_set.py
similarity index 100%
rename from robot_control/examples/force_sensor_set.py
rename to abandon_code/examples/force_sensor_set.py
diff --git a/robot_control/examples/force_spiral_search.py b/abandon_code/examples/force_spiral_search.py
similarity index 100%
rename from robot_control/examples/force_spiral_search.py
rename to abandon_code/examples/force_spiral_search.py
diff --git a/robot_control/examples/froce_line_insertion.py b/abandon_code/examples/froce_line_insertion.py
similarity index 100%
rename from robot_control/examples/froce_line_insertion.py
rename to abandon_code/examples/froce_line_insertion.py
diff --git a/robot_control/examples/getDHcomp.py b/abandon_code/examples/getDHcomp.py
similarity index 100%
rename from robot_control/examples/getDHcomp.py
rename to abandon_code/examples/getDHcomp.py
diff --git a/robot_control/examples/get_robot_data.py b/abandon_code/examples/get_robot_data.py
similarity index 100%
rename from robot_control/examples/get_robot_data.py
rename to abandon_code/examples/get_robot_data.py
diff --git a/robot_control/examples/getversion.py b/abandon_code/examples/getversion.py
similarity index 100%
rename from robot_control/examples/getversion.py
rename to abandon_code/examples/getversion.py
diff --git a/robot_control/examples/io_interface.py b/abandon_code/examples/io_interface.py
similarity index 100%
rename from robot_control/examples/io_interface.py
rename to abandon_code/examples/io_interface.py
diff --git a/robot_control/examples/jog.py b/abandon_code/examples/jog.py
similarity index 100%
rename from robot_control/examples/jog.py
rename to abandon_code/examples/jog.py
diff --git a/robot_control/examples/movec&circle&newspiral.py b/abandon_code/examples/movec&circle&newspiral.py
similarity index 100%
rename from robot_control/examples/movec&circle&newspiral.py
rename to abandon_code/examples/movec&circle&newspiral.py
diff --git a/robot_control/examples/movej&movel&movecart.py b/abandon_code/examples/movej&movel&movecart.py
similarity index 100%
rename from robot_control/examples/movej&movel&movecart.py
rename to abandon_code/examples/movej&movel&movecart.py
diff --git a/robot_control/examples/offset.py b/abandon_code/examples/offset.py
similarity index 100%
rename from robot_control/examples/offset.py
rename to abandon_code/examples/offset.py
diff --git a/robot_control/examples/robot_basic_interface.py b/abandon_code/examples/robot_basic_interface.py
similarity index 100%
rename from robot_control/examples/robot_basic_interface.py
rename to abandon_code/examples/robot_basic_interface.py
diff --git a/robot_control/examples/robot_common_set.py b/abandon_code/examples/robot_common_set.py
similarity index 100%
rename from robot_control/examples/robot_common_set.py
rename to abandon_code/examples/robot_common_set.py
diff --git a/robot_control/examples/robot_external_device.py b/abandon_code/examples/robot_external_device.py
similarity index 100%
rename from robot_control/examples/robot_external_device.py
rename to abandon_code/examples/robot_external_device.py
diff --git a/robot_control/examples/robot_log_interface.py b/abandon_code/examples/robot_log_interface.py
similarity index 100%
rename from robot_control/examples/robot_log_interface.py
rename to abandon_code/examples/robot_log_interface.py
diff --git a/robot_control/examples/robot_lua_test.py b/abandon_code/examples/robot_lua_test.py
similarity index 100%
rename from robot_control/examples/robot_lua_test.py
rename to abandon_code/examples/robot_lua_test.py
diff --git a/robot_control/examples/robot_point_table_download.py b/abandon_code/examples/robot_point_table_download.py
similarity index 100%
rename from robot_control/examples/robot_point_table_download.py
rename to abandon_code/examples/robot_point_table_download.py
diff --git a/robot_control/examples/robot_point_table_switch.py b/abandon_code/examples/robot_point_table_switch.py
similarity index 100%
rename from robot_control/examples/robot_point_table_switch.py
rename to abandon_code/examples/robot_point_table_switch.py
diff --git a/robot_control/examples/robot_point_table_upload.py b/abandon_code/examples/robot_point_table_upload.py
similarity index 100%
rename from robot_control/examples/robot_point_table_upload.py
rename to abandon_code/examples/robot_point_table_upload.py
diff --git a/robot_control/examples/robot_safety_set.py b/abandon_code/examples/robot_safety_set.py
similarity index 100%
rename from robot_control/examples/robot_safety_set.py
rename to abandon_code/examples/robot_safety_set.py
diff --git a/robot_control/examples/robot_updata_lua.py b/abandon_code/examples/robot_updata_lua.py
similarity index 100%
rename from robot_control/examples/robot_updata_lua.py
rename to abandon_code/examples/robot_updata_lua.py
diff --git a/robot_control/examples/servo.py b/abandon_code/examples/servo.py
similarity index 100%
rename from robot_control/examples/servo.py
rename to abandon_code/examples/servo.py
diff --git a/robot_control/examples/spline.py b/abandon_code/examples/spline.py
similarity index 100%
rename from robot_control/examples/spline.py
rename to abandon_code/examples/spline.py
diff --git a/robot_control/examples/tpd_record.py b/abandon_code/examples/tpd_record.py
similarity index 100%
rename from robot_control/examples/tpd_record.py
rename to abandon_code/examples/tpd_record.py
diff --git a/robot_control/examples/tpd_repetition.py b/abandon_code/examples/tpd_repetition.py
similarity index 100%
rename from robot_control/examples/tpd_repetition.py
rename to abandon_code/examples/tpd_repetition.py
diff --git a/robot_control/examples/webapp_program_use_interface.py b/abandon_code/examples/webapp_program_use_interface.py
similarity index 100%
rename from robot_control/examples/webapp_program_use_interface.py
rename to abandon_code/examples/webapp_program_use_interface.py
diff --git a/robot_control/examples/weld.py b/abandon_code/examples/weld.py
similarity index 100%
rename from robot_control/examples/weld.py
rename to abandon_code/examples/weld.py
diff --git a/abandon_code/hand_control.py b/abandon_code/hand_control.py
new file mode 100644
index 0000000..a17363e
--- /dev/null
+++ b/abandon_code/hand_control.py
@@ -0,0 +1,38 @@
+import requests
+
+url = 'http://192.168.3.200/motor'
+
+is_open = False
+
+
+def open_hand():
+ params = {
+ 'direction': 'cw',
+ 'speed': 2000
+ }
+
+ response = requests.get(url, params=params)
+
+ print(response.text) # 打印响应内容
+ print(response.status_code) # 打印响应状态码
+ if response.status_code == 200:
+ flag = True
+
+
+def close_hand():
+ params = {
+ 'direction': 'ccw',
+ 'speed': 2000
+ }
+
+ response = requests.get(url, params=params)
+
+ print(response.text) # 打印响应内容
+ print(response.status_code) # 打印响应状态码
+ if response.status_code == 200:
+ flag = False
+
+
+if __name__ == '__main__':
+ # close_hand()
+ open_hand()
diff --git a/abandon_code/img_process/Log/OrbbecSDK.log.txt b/abandon_code/img_process/Log/OrbbecSDK.log.txt
new file mode 100644
index 0000000..61162b9
Binary files /dev/null and b/abandon_code/img_process/Log/OrbbecSDK.log.txt differ
diff --git a/integration_testing/__init__.py b/integration_testing/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/integration_testing/integration_tests.py b/integration_testing/integration_tests.py
deleted file mode 100644
index e69de29..0000000
diff --git a/robot_control/FRRobot.py b/robot_control/FRRobot.py
index 68abba8..287e402 100644
--- a/robot_control/FRRobot.py
+++ b/robot_control/FRRobot.py
@@ -1,26 +1,35 @@
import queue
import threading
-
+import requests
import Robot
import time
+# todo: 1. 添加软限位
+# todo: 2. 添加回零点功能(完成)
+# todo: 3. 将抓取流程封装成一个函数(完成)
+# todo: 4. 将物品移至指定位置(完成)
+
class FRRobot:
def __init__(self):
+ # 机械臂相关
self.robotCTL = Robot.RPC('192.168.3.102')
- self.is_action = False # 是否正在执行动作
self.speed = 100 # 速度百分比,[0~100]默认20
self.home = [] # 回零点
self.tool = 1 # 工具坐标系编号
self.user = 1 # 工件坐标系编号
# 100% 60mm/s; 50% 30mm/s; 20% 12mm/s
self.velocity = 60 # 速度(mm/s)
+ self.is_arm_moving = False # 是否正在执行动作
# 线程相关
self.command_queue = queue.Queue()
self.listener_thread = threading.Thread(target=self.process_commands)
self.listener_thread.daemon = True # 设置为守护线程,确保主程序退出时线程也会退出
self.listener_thread.start()
+ # 夹爪相关
+ self.is_open = False # 夹爪是否打开
+ self.catch_moving = False # 是否在执行抓取动作
speed_error_code = self.robotCTL.SetSpeed(self.speed)
if speed_error_code != 0:
@@ -30,42 +39,127 @@ class FRRobot:
def add_move_command(self, command):
self.command_queue.put(command)
+ def add_catch_commands(self, command):
+ self.command_queue.put(command)
+
def process_commands(self):
while True:
move_commands = self.command_queue.get()
+ if move_commands is None:
+ continue
+ print("接收到指令: ", move_commands)
+ if move_commands[0] == "catch":
+ self.catch(move_commands[1])
+ continue
+ if move_commands == "home":
+ self.run_script("/fruser/Home.lua")
+ continue
if move_commands == "stop":
self.robotCTL.ImmStopJOG()
- break # 通过发送一个特定的"stop"命令来停止线程
+ break
+ # 停止线程
# axis, distance, direction = move_commands
- print("接收到指令: ", move_commands)
+
+ # 机械臂移动
+ # todo:这地方写的不好,其实不用for,直接和上面一样判断就行
for command in move_commands:
- self.is_action = True
+ self.is_arm_moving = True
axis, distance = command
if axis == "x":
print("x移动距离: ", distance)
- move_time = abs(distance) / self.velocity
direction = 1 if distance > 0 else 0
self.move_x(distance, direction)
- print("x移动时间: ", move_time)
- time.sleep(move_time)
- self.robotCTL.ImmStopJOG()
+
elif axis == "y":
print("y移动距离: ", distance)
- move_time = abs(distance) / self.velocity
direction = 1 if distance < 0 else 0
self.move_y(distance, direction)
- print("y移动时间: ", move_time)
- time.sleep(move_time)
- self.robotCTL.ImmStopJOG()
- self.is_action = False
self.command_queue.task_done()
def move_x(self, distance=30, direction=1):
# direction为0代表负方向,为1代表正方向
- dis = int(distance)
+ move_time = abs(distance) / self.velocity
self.robotCTL.StartJOG(ref=4, nb=1, dir=direction, max_dis=100, vel=20.0, acc=100.0)
+ time.sleep(move_time)
+ print("x移动时间: ", move_time)
+ self.robotCTL.ImmStopJOG()
+ self.is_arm_moving = False
def move_y(self, distance=30, direction=1):
- dis = int(distance)
+ move_time = abs(distance) / self.velocity
self.robotCTL.StartJOG(ref=4, nb=2, dir=direction, max_dis=100, vel=20.0, acc=100.0)
+ time.sleep(move_time)
+ print("y移动时间: ", move_time)
+ self.robotCTL.ImmStopJOG()
+ self.is_arm_moving = False
+
+ def move_z(self, distance=30, direction=1):
+ move_time = (abs(distance - 100)) / self.velocity
+ self.robotCTL.StartJOG(ref=4, nb=3, dir=direction, max_dis=300, vel=20.0, acc=100.0)
+ time.sleep(move_time)
+ self.robotCTL.ImmStopJOG()
+
+ def run_script(self, script_name):
+ self.is_arm_moving = True
+ # 0:自动模式,1:手动模式
+ self.robotCTL.Mode(0)
+ self.robotCTL.ProgramLoad(script_name)
+ self.robotCTL.ProgramRun()
+ while self.robotCTL.GetProgramState() == 2:
+ time.sleep(0.1)
+
+ self.is_arm_moving = False
+ self.robotCTL.Mode(1)
+
+ def catch(self, distance):
+ if not self.is_open:
+ self.catch_moving = True
+ self.open_hand()
+ # 1向上,0向下
+ direction = 1 if distance < 0 else 0
+ self.is_arm_moving = True
+ self.move_z(distance, direction)
+ self.close_hand()
+ # 抬起物品
+ self.move_z(distance, 1)
+ self.run_script("/fruser/home2.lua")
+ time.sleep(0.5)
+ self.open_hand()
+ self.run_script("/fruser/Home.lua")
+ self.close_hand()
+ self.catch_moving = False
+ self.is_arm_moving = False
+
+ # 夹爪控制
+ def open_hand(self):
+ params = {
+ 'direction': 'cw',
+ 'speed': 2000
+ }
+
+ response = requests.get('http://192.168.3.200/motor', params=params)
+
+ print(response.text) # 打印响应内容
+ print(response.status_code) # 打印响应状态码
+ time.sleep(1)
+ if response.status_code == 200:
+ self.is_open = True
+
+ def close_hand(self):
+ params = {
+ 'direction': 'ccw',
+ 'speed': 2000
+ }
+
+ response = requests.get('http://192.168.3.200/motor', params=params)
+
+ print(response.text) # 打印响应内容
+ print(response.status_code) # 打印响应状态码
+ time.sleep(1)
+ if response.status_code == 200:
+ self.is_open = False
+
+# if __name__ == '__main__':
+# robot_controller = FRRobot()
+# robot_controller.run_script("/fruser/home2.lua")