1. 调试了模型预测的输出结果
2. 成功控制机械臂移动
This commit is contained in:
parent
db9e060e6f
commit
dae25cdf47
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
Binary file not shown.
57
.idea/workspace.xml
generated
57
.idea/workspace.xml
generated
@ -4,14 +4,12 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="31e8b3f2-5159-47b8-a798-4b06368c40f5" name="更改" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/saveactions_settings.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||
<list default="true" id="31e8b3f2-5159-47b8-a798-4b06368c40f5" name="更改" comment="调试了模型预测的输出结果">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/copilot/chatSessions/00000000000.xd" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/copilot/chatSessions/00000000000.xd" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/graduation_design.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/graduation_design.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/img_process/ObjectClassify.py" beforeDir="false" afterPath="$PROJECT_DIR$/img_process/ObjectClassify.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/img_process/orbbec_camera/OrbbecCamera.py" beforeDir="false" afterPath="$PROJECT_DIR$/img_process/orbbec_camera/OrbbecCamera.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/robot_control/FRRobot.py" beforeDir="false" afterPath="$PROJECT_DIR$/robot_control/FRRobot.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -33,21 +31,22 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Python.ObjectClassify.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"last_opened_file_path": "F:/Jetbrains/PyCharm Professional",
|
||||
"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": "settings.saveactions",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Python.FRRobot.executor": "Run",
|
||||
"Python.ObjectClassify.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"last_opened_file_path": "F:/Jetbrains/PyCharm Professional",
|
||||
"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": "settings.saveactions",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
@ -66,14 +65,30 @@
|
||||
<workItem from="1711852430019" duration="293000" />
|
||||
<workItem from="1711852735033" duration="1092000" />
|
||||
<workItem from="1711856889730" duration="76000" />
|
||||
<workItem from="1711857077648" duration="10854000" />
|
||||
<workItem from="1711857077648" duration="18301000" />
|
||||
<workItem from="1711885626226" duration="118000" />
|
||||
<workItem from="1711885752611" duration="4246000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="调试了模型预测的输出结果">
|
||||
<option name="closed" value="true" />
|
||||
<created>1711876153617</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1711876153617</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="调试了模型预测的输出结果" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="调试了模型预测的输出结果" />
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/graduation_design$ObjectClassify.coverage" NAME="ObjectClassify 覆盖结果" MODIFIED="1711875775540" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/img_process" />
|
||||
<SUITE FILE_PATH="coverage/graduation_design$FRRobot.coverage" NAME="FRRobot 覆盖结果" MODIFIED="1711894781434" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/robot_control" />
|
||||
<SUITE FILE_PATH="coverage/graduation_design$ObjectClassify.coverage" NAME="ObjectClassify 覆盖结果" MODIFIED="1711894875711" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/img_process" />
|
||||
</component>
|
||||
</project>
|
||||
@ -2,17 +2,20 @@ import asyncio
|
||||
import os
|
||||
|
||||
from time import sleep
|
||||
|
||||
import Robot
|
||||
import torch
|
||||
from torch import tensor
|
||||
from ultralytics import YOLO
|
||||
import cv2
|
||||
from orbbec_camera.OrbbecCamera import OrbbecCamera
|
||||
from robot_control import FRRobot
|
||||
|
||||
# 全局变量
|
||||
model = YOLO('yolov8n.pt')
|
||||
image_width = 640
|
||||
camera = OrbbecCamera('HW', True, image_width=image_width)
|
||||
center_point = 320
|
||||
robot = Robot.RPC('192.168.3.102')
|
||||
|
||||
|
||||
def init():
|
||||
@ -45,15 +48,56 @@ if __name__ == '__main__':
|
||||
half=True,
|
||||
imgsz=image_width,
|
||||
verbose=False,
|
||||
vid_stride=1000)
|
||||
vid_stride=5)
|
||||
print("中心点的深度值: ", camera.get_center_distance(), "mm")
|
||||
x_pos = 0
|
||||
y_pos = 0
|
||||
high = 0
|
||||
width = 0
|
||||
for r in results:
|
||||
if len(r.boxes.xyxy) > 0:
|
||||
positions = r.boxes.xywh.tolist()
|
||||
print("X中心点:", positions[0][0])
|
||||
print("Y中心点:", positions[0][1])
|
||||
print("宽度", positions[0][2])
|
||||
print("高度", positions[0][3])
|
||||
x_pos = positions[0][0]
|
||||
y_pos = positions[0][1]
|
||||
high = positions[0][2]
|
||||
width = positions[0][3]
|
||||
# print("X中心点:", x_pos)
|
||||
# print("Y中心点:", y_pos)
|
||||
# print("宽度", high)
|
||||
# print("高度", width)
|
||||
|
||||
# 计算与中心点的距离
|
||||
x_distance = x_pos - center_point
|
||||
y_distance = y_pos - center_point
|
||||
# print("X距离:", x_distance)
|
||||
# print("Y距离:", y_distance)
|
||||
# 移动方向
|
||||
# dir:0 - 负方向,1 - 正方向;
|
||||
x_dir = 0
|
||||
y_dir = 0
|
||||
# 移动时间
|
||||
x_time = 0
|
||||
y_time = 0
|
||||
# 确定移动方向
|
||||
if abs(x_distance) > 25:
|
||||
x_time = abs(x_distance) / 21
|
||||
if x_distance > 0:
|
||||
x_dir = 1
|
||||
else:
|
||||
x_dir = 0
|
||||
robot.StartJOG(ref=4, nb=1, dir=x_dir, max_dis=30, vel=20.0, acc=100.0)
|
||||
sleep(0.5)
|
||||
robot.ImmStopJOG()
|
||||
|
||||
if abs(y_distance) > 25:
|
||||
y_time = abs(y_distance) / 21
|
||||
if y_distance < 0:
|
||||
y_dir = 1
|
||||
else:
|
||||
y_dir = 0
|
||||
robot.StartJOG(ref=4, nb=2, dir=y_dir, max_dis=30, vel=20.0, acc=100.0)
|
||||
sleep(0.5)
|
||||
robot.ImmStopJOG()
|
||||
|
||||
key = cv2.waitKey(1)
|
||||
if key == ord('q'):
|
||||
|
||||
@ -30,7 +30,7 @@ class OrbbecCamera:
|
||||
self.active = False # 控制捕获循环的标志
|
||||
# 显示设置
|
||||
self.width = image_width # 图像宽度
|
||||
self.fps = 15 # 帧率
|
||||
self.fps = 30 # 帧率
|
||||
|
||||
# 初始化相机设置
|
||||
device_info = self.device.get_device_info() # 获取设备信息
|
||||
|
||||
@ -7,27 +7,49 @@ class FRRobot:
|
||||
def __init__(self):
|
||||
self.robotCTL = Robot.RPC('192.168.3.102')
|
||||
|
||||
self.speed = 20 # 速度百分比,[0~100]默认20
|
||||
self.speed = 100 # 速度百分比,[0~100]默认20
|
||||
self.home = [] # 回零点
|
||||
self.tool = 1 # 工具坐标系编号
|
||||
self.user = 1 # 工件坐标系编号
|
||||
|
||||
# 工具坐标系参数
|
||||
self.t_coord = [0, 0, 170, -180, 0, -45]
|
||||
# self.t_coord = [0, 0, 170, -180, 0, -45]
|
||||
|
||||
speed_error_code = self.robotCTL.SetSpeed(self.speed)
|
||||
if speed_error_code != 0:
|
||||
print("初始化全局速度错误:", speed_error_code)
|
||||
tool_error_code = self.robotCTL.SetToolCoord(1, self.t_coord, 0, 0)
|
||||
if tool_error_code != 0:
|
||||
print("初始化工具坐标系错误:", tool_error_code)
|
||||
# tool_error_code = self.robotCTL.SetToolCoord(1, self.t_coord, 0, 0)
|
||||
# if tool_error_code != 0:
|
||||
# print("初始化工具坐标系错误:", tool_error_code)
|
||||
|
||||
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
robot = FRRobot()
|
||||
# joint_pos1 = [-286, -456, 673, -179, 0, 90]
|
||||
# ret = robot.robotCTL.SplineStart() # 样条运动开始
|
||||
# if ret == 0:
|
||||
# print("样条运动开始:", ret)
|
||||
robot.robotCTL.ImmStopJOG()
|
||||
# # 与机器人控制器建立连接,连接成功返回一个机器人对象
|
||||
#
|
||||
# ret = robot.robotCTL.SplinePTP(joint_pos1, robot.tool, robot.user, vel=2) # 样条运动PTP
|
||||
# #
|
||||
# # ref:0 - 关节点动, 2 - 基坐标系点动, 4 - 工具坐标系点动, 8 - 工件坐标系点动;
|
||||
# # nb:1 - 1
|
||||
# # 关节(x轴),2 - 2
|
||||
# # 关节(y轴),
|
||||
# # 3 - 3 关节(z轴),
|
||||
# # 4 - 4 关节(rx),
|
||||
# # 5 - 5 关节(ry),
|
||||
# # 6 - 6 关节(rz);
|
||||
# # dir:0 - 负方向,1 - 正方向;
|
||||
# # max_dis:单次点动最大角度 / 距离,单位 ° 或mm;
|
||||
# # 默认参数
|
||||
# # vel:速度百分比,[0~100]默认20;
|
||||
# # acc:加速度百分比,[0~100]默认100;
|
||||
# # n = 0
|
||||
# # while n < 5:
|
||||
# # X轴负方向移动
|
||||
# robot.robotCTL.StartJOG(ref=4, nb=1, dir=1, max_dis=300, vel=20.0, acc=100.0)
|
||||
# time.sleep(5)
|
||||
# # Y轴负方向移动
|
||||
# # robot.robotCTL.StartJOG(4, 2, 0, 30, vel=20.0, acc=100.0)
|
||||
# # time.sleep(0.5)
|
||||
# # n += 1
|
||||
# robot.robotCTL.ImmStopJOG()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user