export coord to robot

This commit is contained in:
Kseninia Mikhaylova 2024-12-13 09:27:19 +03:00
parent 1ede0084f0
commit cf2b7fe493
3 changed files with 38 additions and 17 deletions

View File

@ -35,7 +35,12 @@ class Command(QWidget):
self.layout.addWidget(self.updButton) self.layout.addWidget(self.updButton)
self.chgButton = QPushButton("Изменить тип") self.chgButton = QPushButton("Изменить тип")
self.chgButton.clicked.connect(lambda: self.changeType('calc' if self.command_type() == 'base' else 'base')) cur_types = ["base", "calc", "pallette"]
self.chgButton.clicked.connect(
lambda: self.changeType(
cur_types[(cur_types.index(self.command_type()) + 1) % len(cur_types)]
)
)
self.layout.addWidget(self.chgButton) self.layout.addWidget(self.chgButton)
def paintEvent(self, event): def paintEvent(self, event):

View File

@ -68,8 +68,8 @@ class MainContentComponent(QWidget):
self.informerPanel, self.informerPanel,
# self.filenamePanel, # self.filenamePanel,
# self.imitatorPanel, # self.imitatorPanel,
# self.commandPanel,
self.palletizingPanel, self.palletizingPanel,
self.commandPanel,
], ],
color=(169, 169, 169), color=(169, 169, 169),
) )

View File

@ -173,11 +173,12 @@ class SocketRobotArm:
self.set_text(text=f"Старт одиночного цикла") self.set_text(text=f"Старт одиночного цикла")
time.sleep(0.5) time.sleep(0.5)
commands = ( if self.command_type == "base":
self.steps_from_file() commands = self.steps_from_file()
if self.command_type == "base" if self.command_type == "calc":
else self.convert_point_to_free() commands = self.convert_point_to_free()
) if self.command_type == "pallette":
commands = self.get_palletizing_json()
with open(f"log/{self.command_type}.json", "w") as myfile: with open(f"log/{self.command_type}.json", "w") as myfile:
myfile.write(json.dumps(commands)) myfile.write(json.dumps(commands))
@ -205,13 +206,22 @@ class SocketRobotArm:
position[1] += 0.02 position[1] += 0.02
json_res = []
for pos in [conv, position]: for pos in [conv, position]:
jointPoses = self.convert_to_joint_base( jointPoses = self.convert_to_joint_base(
pos, pos,
np.radians([0, 0, -90]), np.radians([0, 0, -90]),
) )
json_res.append(
self.prepare_data.make_step(
"free", np.degrees(jointPoses), [0, 0, 0, 0, 0, 0]
)
)
self.motionFund(jointPoses) self.motionFund(jointPoses)
time.sleep(2) time.sleep(2)
with open(f"data/palletizing.json", "w") as myfile:
myfile.write(json.dumps(json_res))
end_effector_state = p.getLinkState(self.body_id, self.num_joints - 1) end_effector_state = p.getLinkState(self.body_id, self.num_joints - 1)
end_effector_pos = end_effector_state[0] # Позиция наконечника end_effector_pos = end_effector_state[0] # Позиция наконечника
@ -227,14 +237,15 @@ class SocketRobotArm:
# Создаём констрейнт для прикрепления # Создаём констрейнт для прикрепления
constraint_id = p.createConstraint( constraint_id = p.createConstraint(
parentBodyUniqueId=self.body_id, # Идентификатор робота parentBodyUniqueId=self.body_id, # Идентификатор робота
parentLinkIndex=self.num_joints - 1, # Индекс последнего звена (наконечника) parentLinkIndex=self.num_joints
- 1, # Индекс последнего звена (наконечника)
childBodyUniqueId=box_id, # Идентификатор коробки childBodyUniqueId=box_id, # Идентификатор коробки
childLinkIndex=-1, # -1 означает базовую ссылку объекта childLinkIndex=-1, # -1 означает базовую ссылку объекта
jointType=p.JOINT_FIXED, # Фиксированный констрейнт jointType=p.JOINT_FIXED, # Фиксированный констрейнт
jointAxis=[0, 0, 0], # Без вращательной оси jointAxis=[0, 0, 0], # Без вращательной оси
parentFramePosition=parentFramePosition, # Позиция относительно робота parentFramePosition=parentFramePosition, # Позиция относительно робота
childFramePosition=[1, 1, 1], # Позиция объекта (относительно себя) childFramePosition=[1, 1, 1], # Позиция объекта (относительно себя)
parentFrameOrientation=parentFrameOrientation # Ориентация относительно робота parentFrameOrientation=parentFrameOrientation, # Ориентация относительно робота
) )
def set_text(self, text): def set_text(self, text):
@ -316,6 +327,11 @@ class SocketRobotArm:
jointPoses = [np.radians(float(point[f"m{i}"])) for i in range(6)] jointPoses = [np.radians(float(point[f"m{i}"])) for i in range(6)]
self.motionFund(jointPoses) self.motionFund(jointPoses)
def get_palletizing_json(self):
with open(f"data/palletizing.json", "r") as fp:
data = json.load(fp)
return data
def convert_point_to_free(self): def convert_point_to_free(self):
points = self.steps_from_file() points = self.steps_from_file()
res = [] res = []