140 lines
3.3 KiB
Plaintext
140 lines
3.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "43832635-49f6-45d0-9a5f-14d4d634731d",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0"
|
|
]
|
|
},
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import pybullet as p\n",
|
|
"p.connect(p.GUI)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "e374f315-b9ab-42d1-b33d-518c74f95c43",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"floor_shape = p.createCollisionShape(p.GEOM_PLANE)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "f844a0fb-efa5-4461-9589-31ba09f526b8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"floor = p.createMultiBody(floor_shape, floor_shape) #(vision geometry, collision geometry)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "fb392ce2-d95b-4481-9246-08ca71adeb12",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create a new geometry, box instead of a plane\n",
|
|
"box_shape = p.createCollisionShape(p.GEOM_BOX, halfExtents = [1, 1, 1])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "c50db6e4-d784-4924-8751-da704e376352",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"box = p.createMultiBody(box_shape, box_shape) #create a box at (0.0.0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "857c7c29-7bf0-486b-8aa4-9deb5e0a76e5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"p.setGravity(0, 0, -10) #(x, z, y) forces\n",
|
|
"p.setRealTimeSimulation(1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "c6c09422-92f2-4eef-8c22-55fb86c1c1b0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"box_object1 = p.createMultiBody(box_shape,box_shape)\n",
|
|
"box_object2 = p.createMultiBody(box_shape,box_shape)\n",
|
|
"p.resetBasePositionAndOrientation(box_object1, [0, -1, 2], [0, 0, 0, 1])\n",
|
|
"p.resetBasePositionAndOrientation(box_object2, [0, 1, 2], [0, 0, 0, 1])\n",
|
|
"p.setGravity(0, 0, -10)\n",
|
|
"p.setRealTimeSimulation(1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "e3e857c9-d3e4-4028-8abf-3ad25b4cbc63",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fruits = [p.createMultiBody(box_shape,box_shape)] * 9\n",
|
|
"for index in range(9):\n",
|
|
" p.resetBasePositionAndOrientation(fruits[index], [index, index * 3, 4], [0, 0, 0, 1])\n",
|
|
"p.setGravity(0, 0, -10)\n",
|
|
"p.setRealTimeSimulation(1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 27,
|
|
"id": "7834922b-8671-4997-a14d-696ddd217805",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"box_object3 = p.createMultiBody(box_shape,box_shape)\n",
|
|
"p.resetBasePositionAndOrientation(box_object1, [5, 5, 5], [3, 3, 3, 1])"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.8"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|