Go2Py_SIM/examples/02-MuJoCo-sim.ipynb

245 lines
155 KiB
Plaintext
Raw Normal View History

2024-03-18 11:36:53 +08:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lowlevel Simulation"
]
},
2024-03-18 11:36:53 +08:00
{
"cell_type": "code",
"execution_count": 1,
2024-03-18 11:36:53 +08:00
"metadata": {},
"outputs": [],
"source": [
"from Go2Py.sim.mujoco import Go2Sim\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
2024-03-18 11:36:53 +08:00
"metadata": {},
"outputs": [],
"source": [
"robot = Go2Sim(mode='lowlevel')"
2024-03-18 11:36:53 +08:00
]
},
{
"cell_type": "code",
"execution_count": 3,
2024-03-18 11:36:53 +08:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7d4b807ef0d0>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiQAAAGiCAYAAADX8t0oAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACa3UlEQVR4nO39e/RtV1nfj7/nXGvv/bmdz+dcknNOUgjSARUiFzHRcKq9ciRitFpjv+hINVqG/qQnVIylmlah0GoYOIZWK0JrW3AMpWlxFC8oYEaQUOWQQCQVgkaoqYnKOScQzuf+2XuvNefvj3lZc67L3mtf11p7Py/45OzL2mvN6zOf+cxnPpNJKSUIgiAIgiAqhFedAIIgCIIgCFJICIIgCIKoHFJICIIgCIKoHFJICIIgCIKoHFJICIIgCIKoHFJICIIgCIKoHFJICIIgCIKoHFJICIIgCIKoHFJICIIgCIKoHFJICIIgCIKonEoVkre//e34iq/4CqysrOCWW27Bww8/XGVyCIIgCIKoiMoUkv/xP/4H7r77brzpTW/CH/3RH+GlL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Bbui0sVqZUgCIIgCI/G6GGaZltIBplIJIA5OAuWOkqnJnedOrVIZi0SQRBELjUYEmuQhHI0JqFZhi47l8tbwxWSIdhCGnHAmtNyz+BHNmSnTC1cTebVkUnxIRaFGg9+NU5aMQ1eapnoodNN5WIrJJYRC81ePsYANOaYNRuvk2k1ljkOxLPuhRNlpc6SkpSl+lHn9jIBC5Ot2WaksmIa68H1qFTyIRlIPSqpehaoHBYoKz4Lm7GGsqD1saDZWm7qU6lLYiG
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"camera_state = robot.getCameraState()\n",
"plt.imshow(camera_state['rgb'])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAooAAAJ8CAYAAAB5v4CIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9eZQj533fC38LQKMX7I3e921melbOxuF0j2yToiTSkmVbopnYipNQ16GcvK99Y5mvZd1ocbTFr3xlW7bsSJajaImkY0e2oxtblmJSokhRHEkkp4He0fu+Y+lu7EvV/WPyFAtoAI2lqlCoej7n8JzhTDeeKqBQz7d+y/fHcBzHgUKhUCgUCoVCyUBX6QOgUCgUCoVCoSgTKhQpFAqFQqFQKFmhQpFCoVAoFAqFkhUqFCkUCoVCoVAoWaFCkUKhUCgUCoWSFSoUKRQKhUKhUChZoUKRQqFQKBQKhZIVKhQpFAqFQqFQKFmhQpFCoVAoFAqFkhUqFCkUCoVCoVAoWaFCkUKhUCgUCoWSFSoUKRQKhUKhUChZoUKRQqFQKBQKhZIVKhQpFAqFQqFQKFmhQpFCoVAoFAqFkhUqFCkUCoVCoVAoWaFCkUKhUCgUCoWS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NDaoUOGTMY7lQ4UihUIqBCkUKpUTyNaxkazQRc92lpSVsbm7CYrHg2rVrshl3VxqGYWCxWGCxWNDT0wOWZfHiiy/CZDJhf38fCwsLMBgMJ8y/qcDJTaHCkaSoqXCkULQFFYoUSgkIx/Bl2zCliijGYjGMj48jEomgp6eH73DVKuS97+zshMlkAsuyvIfj9vY2PB4PjEZjmodjXV1dpQ+7ZOT4rHMJR9IcE41GodPpTjTHUOF
"text/plain": [
"<Figure size 800x800 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.mplot3d import proj3d\n",
"\n",
"state = robot.getCameraState(get_pointcloud=True)\n",
"pcd = state['pointcloud']\n",
"\n",
"fig = plt.figure(figsize=(8, 8))\n",
"ax = fig.add_subplot(111, projection='3d')\n",
"\n",
"ax.scatter(pcd[:,0], pcd[:,1], pcd[:,2])\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'q': array([-0.02473053, 1.26249091, -2.82722067, 0.04536265, 1.25053037,\n",
" -2.79265437, -0.30646674, 1.2828985 , -2.82216135, 0.26426387,\n",
" 1.29362285, -2.84158745]),\n",
" 'dq': array([ 0.11278784, -0.00277931, 0.5229731 , -0.1364931 , -0.00321283,\n",
" 0.35066361, -0.11362303, 0.03049349, 0.49368981, 0.13078971,\n",
" 0.03355434, 0.59049033]),\n",
" 'tau_est': array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
2024-03-18 11:36:53 +08:00
"source": [
2024-05-05 08:09:01 +08:00
"robot.getJointStates()"
2024-03-18 11:36:53 +08:00
]
},
{
"cell_type": "code",
"execution_count": 9,
2024-03-18 11:36:53 +08:00
"metadata": {},
"outputs": [],
"source": [
2024-05-05 08:09:01 +08:00
"import mujoco\n",
"import time\n",
"import cv2\n",
"camera_dt = 1./60.\n",
2024-05-05 08:09:01 +08:00
"robot.standUpReset()\n",
"start_time = time.time()\n",
"step_counter = 0\n",
"while time.time()-start_time < 10:\n",
2024-05-05 08:09:01 +08:00
" state = robot.getJointStates()\n",
" tau = 20*np.eye(12)@(robot.q0 - state['q']).reshape(12,1)\n",
" robot.setCommands(np.zeros(12), np.zeros(12), np.zeros(12), np.zeros(12), tau)\n",
" robot.step()\n",
" if step_counter%(camera_dt//robot.dt)==0:\n",
" camera_state = robot.getCameraState()\n",
" cv2.imshow('rgb', cv2.cvtColor(camera_state['rgb'], cv2.COLOR_BGR2RGB))\n",
" cv2.waitKey(1)\n",
" step_counter+=1\n",
"cv2.destroyAllWindows()"
2024-03-18 11:36:53 +08:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Highlevel Simulation"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
2024-05-27 23:47:55 +08:00
"outputs": [],
"source": [
"from Go2Py.sim.mujoco import Go2Sim\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"p_gains: [20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.]\n"
]
}
],
"source": [
"robot = Go2Sim(mode='highlevel')\n",
"robot.standUpReset()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
2024-05-27 23:47:55 +08:00
"outputs": [],
"source": [
"import mujoco\n",
"import time\n",
"import cv2\n",
"camera_dt = 1./60.\n",
"robot.standUpReset()\n",
"start_time = time.time()\n",
"step_counter = 0\n",
"while time.time()-start_time < 10:\n",
" robot.step(0,0,0., step_height=0,kp=[2, 0.5, 0.5], ki=[0.02, 0.01, 0.01])\n",
" if step_counter%(camera_dt//robot.dt)==0:\n",
" camera_state = robot.getCameraState()\n",
" cv2.imshow('rgb', cv2.cvtColor(camera_state['rgb'], cv2.COLOR_BGR2RGB))\n",
" cv2.waitKey(1)\n",
" step_counter+=1\n",
"cv2.destroyAllWindows()"
]
},
{
"cell_type": "code",
2024-05-27 23:47:55 +08:00
"execution_count": null,
"metadata": {},
2024-05-27 23:47:55 +08:00
"outputs": [],
"source": [
"robot.getLaserScan()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2024-05-27 23:47:55 +08:00
"import matplotlib.pyplot as plt\n",
"lidar = robot.getLaserScan(max_range=3.)\n",
"idx = np.where(lidar['dist']!=-1)[0]\n",
"plt.plot(lidar['dist'][idx])"
]
2024-03-18 11:36:53 +08:00
}
],
"metadata": {
"kernelspec": {
"display_name": "b1-env",
"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.12"
2024-03-18 11:36:53 +08:00
}
},
"nbformat": 4,
"nbformat_minor": 2
}