exp
This commit is contained in:
parent
cf2b7fe493
commit
b94d7ab1e5
|
@ -201,6 +201,7 @@ class SocketRobotArm:
|
||||||
threading.Thread(target=self.imitate_func, daemon=True).start()
|
threading.Thread(target=self.imitate_func, daemon=True).start()
|
||||||
|
|
||||||
def palletizing(self, position, box_id):
|
def palletizing(self, position, box_id):
|
||||||
|
pos = position[:]
|
||||||
conv = position[:]
|
conv = position[:]
|
||||||
conv[1] += 0.4
|
conv[1] += 0.4
|
||||||
|
|
||||||
|
@ -211,6 +212,7 @@ class SocketRobotArm:
|
||||||
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, 0]),
|
||||||
np.radians([0, 0, -90]),
|
np.radians([0, 0, -90]),
|
||||||
)
|
)
|
||||||
json_res.append(
|
json_res.append(
|
||||||
|
@ -223,29 +225,31 @@ class SocketRobotArm:
|
||||||
with open(f"data/palletizing.json", "w") as myfile:
|
with open(f"data/palletizing.json", "w") as myfile:
|
||||||
myfile.write(json.dumps(json_res))
|
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, computeForwardKinematics=True
|
||||||
|
)
|
||||||
end_effector_pos = end_effector_state[0] # Позиция наконечника
|
end_effector_pos = end_effector_state[0] # Позиция наконечника
|
||||||
end_effector_orn = end_effector_state[1] # Ориентация наконечника
|
end_effector_orn = end_effector_state[1] # Ориентация наконечника
|
||||||
|
|
||||||
# Позиция стенки (или коробки), к которой мы прикрепляем наконечник
|
|
||||||
object_pos, object_orn = p.getBasePositionAndOrientation(box_id)
|
object_pos, object_orn = p.getBasePositionAndOrientation(box_id)
|
||||||
|
|
||||||
# Определяем смещение, которое будет применено для фиксации позиции (без вращения)
|
# Используем ориентацию объекта (коробки) как ориентацию родителя
|
||||||
parentFramePosition = [position[i] - end_effector_pos[i] for i in range(3)]
|
parentFrameOrientation = object_orn
|
||||||
parentFrameOrientation = end_effector_orn # Ориентация робота (наконечника)
|
|
||||||
|
# # Определяем смещение для фиксации позиции (без вращения)
|
||||||
|
parentFramePosition = [pos[i] - end_effector_pos[i] for i in range(3)]
|
||||||
|
|
||||||
# Создаём констрейнт для прикрепления
|
# Создаём констрейнт для прикрепления
|
||||||
constraint_id = p.createConstraint(
|
constraint_id = p.createConstraint(
|
||||||
parentBodyUniqueId=self.body_id, # Идентификатор робота
|
parentBodyUniqueId=self.body_id,
|
||||||
parentLinkIndex=self.num_joints
|
parentLinkIndex=self.num_joints - 1,
|
||||||
- 1, # Индекс последнего звена (наконечника)
|
childBodyUniqueId=box_id,
|
||||||
childBodyUniqueId=box_id, # Идентификатор коробки
|
childLinkIndex=-1,
|
||||||
childLinkIndex=-1, # -1 означает базовую ссылку объекта
|
jointType=p.JOINT_FIXED,
|
||||||
jointType=p.JOINT_FIXED, # Фиксированный констрейнт
|
jointAxis=[0, 0, 0],
|
||||||
jointAxis=[0, 0, 0], # Без вращательной оси
|
parentFramePosition=[0,0,0],
|
||||||
parentFramePosition=parentFramePosition, # Позиция относительно робота
|
childFramePosition=[0, 0, 0],
|
||||||
childFramePosition=[1, 1, 1], # Позиция объекта (относительно себя)
|
parentFrameOrientation=p.getQuaternionFromEuler(np.radians([0, 0, 0])),
|
||||||
parentFrameOrientation=parentFrameOrientation, # Ориентация относительно робота
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
|
|
|
@ -188,8 +188,9 @@
|
||||||
|
|
||||||
<link name="tcp">
|
<link name="tcp">
|
||||||
<visual>
|
<visual>
|
||||||
|
<origin rpy="0 0 0" xyz="0.04 0 0" />
|
||||||
<geometry>
|
<geometry>
|
||||||
<box size="0.05 0.05 0.05" />
|
<box size="0.02 0.02 0.02" />
|
||||||
</geometry>
|
</geometry>
|
||||||
<material name="red" />
|
<material name="red" />
|
||||||
</visual>
|
</visual>
|
||||||
|
|
Loading…
Reference in New Issue