Go2Py/pin_model.ipynb

586 lines
26 KiB
Plaintext
Raw Normal View History

2024-03-24 10:42:44 +08:00
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pinocchio as pin"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dir(pin)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from Go2Py import ASSETS_PATH\n",
"urdf_path = os.path.join(ASSETS_PATH, 'urdf/go2.urdf')\n",
"urdf_root_path = os.path.join(ASSETS_PATH, 'urdf')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"robot = pin.RobotWrapper.BuildFromURDF(urdf_path, urdf_root_path, pin.JointModelFreeFlyer())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"robot_model = robot.model\n",
"robot_data = robot.data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"robot_mass = sum([I.mass for I in robot_model.inertias])\n",
"base_frame_name = robot_model.frames[2].name"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for frame in robot.model.frames:\n",
" print(frame.name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for name in robot.model.names:\n",
" print(name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"robot_model.getJointId(\"RR_calf_joint\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"unitree_joints = [\n",
" 'FR_hip_joint',\n",
" 'FR_thigh_joint',\n",
" 'FR_calf_joint',\n",
" 'FL_hip_joint',\n",
" 'FL_thigh_joint',\n",
" 'FL_calf_joint',\n",
" 'RR_hip_joint',\n",
" 'RR_thigh_joint',\n",
" 'RR_calf_joint',\n",
" 'RL_hip_joint',\n",
" 'RL_thigh_joint',\n",
" 'RL_calf_joint',\n",
" ]\n",
"pin_joints = [name for name in robot.model.names[2:]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pin_unitree_id_translator = [robot.model.getJointId(joint_name) for joint_name in unitree_joints]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pin_unitree_id_translator"
]
},
{
"cell_type": "code",
2024-03-29 01:32:00 +08:00
"execution_count": 3,
2024-03-24 10:42:44 +08:00
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from Go2Py import ASSETS_PATH\n",
"import pinocchio as pin\n",
"import numpy as np\n",
"urdf_path = os.path.join(ASSETS_PATH, 'urdf/go2.urdf')\n",
"urdf_root_path = os.path.join(ASSETS_PATH, 'urdf')\n",
"\n",
"\n",
"class Go2Model:\n",
" def __init__(self):\n",
" self.robot = pin.RobotWrapper.BuildFromURDF(urdf_path, urdf_root_path, pin.JointModelFreeFlyer())\n",
" # Standing joint configuration in Unitree Joint order\n",
" self.ef_frames = ['FR_foot', 'FL_foot', 'RR_foot', 'RL_foot']\n",
" self.dq_reordering_idx = np.array([0, 1, 2, 3, 4, 5,\\\n",
" 9, 10, 11, 6, 7, 8, 15, 16, 17, 12, 13, 14])\n",
" self.q_reordering_idx = np.array([9, 10, 11, 6, 7, 8, 15, 16, 17, 12, 13, 14])-6\n",
" self.ef_J_ = {}\n",
" \n",
" def update(self, q, dq, T, v):\n",
" q_ = np.hstack([pin.SE3ToXYZQUATtuple(pin.SE3(T)), q[self.q_reordering_idx]])\n",
" dq_ = np.hstack([v, dq[self.q_reordering_idx]])\n",
" self.robot.computeJointJacobians(q_)\n",
" self.robot.framesForwardKinematics(q_)\n",
" self.robot.centroidalMomentum(q_,dq_)\n",
" self.nle_ = self.robot.nle(q_, dq_)[self.dq_reordering_idx]\n",
" self.g_ = self.robot.gravity(q_)[self.dq_reordering_idx]\n",
" self.M_ = self.robot.mass(q_)[[self.dq_reordering_idx],[self.dq_reordering_idx]]\n",
" self.Minv_ = pin.computeMinverse(self.robot.model, self.robot.data, q_)[[self.dq_reordering_idx],[self.dq_reordering_idx]]\n",
" for ef_frame in self.ef_frames:\n",
2024-03-29 01:32:00 +08:00
" J = self.robot.getFrameJacobian(self.robot.model.getFrameId(ef_frame), pin.ReferenceFrame.LOCAL_WORLD_ALIGNED)\n",
2024-03-24 10:42:44 +08:00
" self.ef_J_[ef_frame]=J[:, self.dq_reordering_idx]\n",
"\n",
" def getInfo(self):\n",
" return {\n",
" 'M':self.M_,\n",
" 'Minv':self.Minv_,\n",
" 'nle':self.nle_,\n",
" 'g':self.g_,\n",
" 'J':self.ef_J_,\n",
" }"
]
},
{
"cell_type": "code",
2024-03-29 01:32:00 +08:00
"execution_count": 4,
2024-03-24 10:42:44 +08:00
"metadata": {},
"outputs": [],
"source": [
"model = Go2Model()"
]
},
{
"cell_type": "code",
2024-03-29 01:32:00 +08:00
"execution_count": 5,
2024-03-24 10:42:44 +08:00
"metadata": {},
"outputs": [],
"source": [
"model.update(np.zeros(12), np.zeros(12), np.eye(4), np.zeros(6))"
]
},
{
"cell_type": "code",
2024-03-29 01:32:00 +08:00
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from Go2Py.sim.mujoco import Go2Sim\n",
"robot = Go2Sim()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"robot.step()\n",
"mujoco_params = robot.getDynamicsParams()"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"states = robot.getJointStates()\n",
"q = states['q']\n",
"dq = states['dq']\n",
"trans, quat = robot.getPose()\n",
"quat = np.hstack([quat[1:], quat[0]])\n",
"q = np.hstack([trans, quat, q])"
]
},
{
"cell_type": "code",
"execution_count": 102,
"metadata": {},
"outputs": [],
"source": [
"dq_reordering_idx = np.array([0, 1, 2, 3, 4, 5,\\\n",
" 9, 10, 11, 6, 7, 8, 15, 16, 17, 12, 13, 14])"
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-0.5194361885075903"
]
},
"execution_count": 125,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"M1 = model.robot.mass(q)[dq_reordering_idx,:]\n",
"M1=M1[:,dq_reordering_idx]\n",
"# M2 = robot.getDynamicsParams()['M']\n",
"(M1-M2).sum()\n",
"# M1.shape"
]
},
{
"cell_type": "code",
"execution_count": 126,
2024-03-24 10:42:44 +08:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2024-03-29 01:32:00 +08:00
"<matplotlib.image.AxesImage at 0x7f87343e1f10>"
2024-03-24 10:42:44 +08:00
]
},
2024-03-29 01:32:00 +08:00
"execution_count": 126,
2024-03-24 10:42:44 +08:00
"metadata": {},
"output_type": "execute_result"
2024-03-29 01:32:00 +08:00
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAL60lEQVR4nO3dbazedX3H8fdn54C1x2FhGKJtQ3nAWIhkw5y4IolZgGU4nTUbGkgw6Ez6ZAoaEsU94clMamK8WWY0DSIkEshSSWwMEQnoGM4xDzdRoFUIdVAsthuZds262vLdg3ORdGc9lF3/3znXBb/3K2nOdZff9Q3l3f91d35XqgpJr32/NekBJK0OY5c6YexSJ4xd6oSxS52YXc07O/OMmdq08ZTB6/zsx2sbTANH1s81WWfmcJNlpMH++z9f4OjhQznRdasa+6aNp/Avd28cvM6frL+wwTSw59rNTdZZt7vJMtJgu3Z+YdnrfBgvdcLYpU4Yu9QJY5c6MSj2JJcn+WmSp5Lc0GooSe2NHXuSGeDLwLuA84GrkpzfajBJbQ05sr8deKqqnq6qI8AdwJY2Y0lq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csPs25JMk3JjjPXmBvVb30aGcHi/FPymXAnqo6UFW/Ae4E3jHBeY73yyRvBhj93D+JIaYl9h8B5yY5J8mpLL6wsnOSAyUJi89Hd1XV5yc5C0BVfbqqNlTVJhb/+9xXVRM7clXV88CzSc4bXXQp8MSk5mHx4fvmJGtHf3eXMj0vZO4Erhmdvgb41iSGmJ3EnS5VVUe
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"plt.imshow(M1[6:,6:])"
]
},
{
"cell_type": "code",
"execution_count": 117,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f87342cbd30>"
]
},
"execution_count": 117,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAL4klEQVR4nO3db4idd5nG8evamYQm42L6Zyk6CW1elJagSLtDaS2VpelC1WIEl92WbalFCLgaYylI3Dd9K24RfVGEEFuLtilLLFhKqZaolS1rNtO0aJMoCVGb1NTEDWoJxJmYa1/MKWTHpOme53fmOdv7+4Ew5zzn8Dt3kvnOc/4+4yQC8M73V30PAGBpEDtQBLEDRRA7UASxA0VMLuWNXXbJRK5Y0/0mD/x0qsE00p8vbbPOxJ/ONFkH6OrUqd9rbv6kz3XZksZ+xZpJ/eTZ1Z3X+cj0dQ2mkU5suLHJOqsOnWqyDtDV7tmHznsZd+OBIogdKILYgSKIHSiiU+y2b7P9C9sHbW9pNRSA9oaO3faEpIckfVjSOkl32l7XajAAbXXZs18v6WCSQ0nmJD0haUObsQC01iX2aUmHzzp/ZLDtf7G90fas7dnf/TdvPgH6M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4jko4kefPezg4txN+XWyX9MsnxJPOSnpT0wR7nOdtvbb9HkgZfj/UxxLjEvlvSVbbX2l6uhSdWnupzINvWwuPR/Um+0ucskpTki0lWJ7lSC/8+P0jS254ryeuSDtu+erBpvaR9fc2jhbvvN9heOfi/W6/xeSLzKUn3DE7fI+m7fQwx2ceNLpbktO3PSvqeFp5FfTj
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(M2[6:,6:])"
]
},
{
"cell_type": "code",
"execution_count": 129,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"15.206408000000003"
]
},
"execution_count": 129,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"robot.model.body_mass.sum()"
]
},
{
"cell_type": "code",
"execution_count": 135,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"15.019000000000004"
]
},
"execution_count": 135,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = model.robot.model\n",
"sum([i.mass for i in s.inertias])"
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {},
"outputs": [],
"source": [
"Jp, Jr = robot.getSiteJacobian('FL_foot')\n",
"model.robot.computeJointJacobians(q).T\n",
"J = model.robot.getFrameJacobian(model.robot.model.getFrameId('FL_foot'), pin.ReferenceFrame.LOCAL_WORLD_ALIGNED)"
]
},
{
"cell_type": "code",
"execution_count": 143,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(0.009002122197148882, 0.13167880433018087)"
]
},
"execution_count": 143,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(Jp.T-J[0:3,:].T).sum(),(Jr.T-J[3:,:].T).sum()"
]
},
{
"cell_type": "code",
"execution_count": 136,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f87343b4af0>"
]
},
"execution_count": 136,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoA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B9JrCP4b+Vf5n2mO8Kmj8ibwBOkvThkpmm4+YSq2ous5J0Hc1hv1sK5zgR+CLwpZI5pjAKzKE5HPoF4IftjFdDN+yi3gXM77k/3i4rrsJ5Ic8FLpX0FM0hovMl3Vw2EjuBnbYn322soSnukt4H/MH2XtsHgLXAOYUz9fqzpNcDtN+LvX3uJemjwCXAh1z+Gt030fyh3dxu7+PAJkmvK5qq2d7XunEfzTvboZ7knDTsor4fOE3SQkkzaU76rBtyhv9Q47yQtq+1PW57Ac3z9HPbRfcUbT8D7JD05nbRBcAjBSNBc8hjmaQT29fxAuo6+boOWNneXgncUTAL0Fx5RXNI7VLbL5bOY/v3tl9re0G7ve8Ezmq3t5JuB84DkLQImEmpfxxle6hfwHKaM83bgeuG/fjTZHonzVvSLcCD7dfy0rl68r0XuLN0jjbL24CN7XN1OzC7gkxfBh4DHgJ+AMwqlONWmuPkB2jK5uPAXJqrPZ4AfgbMqSDTNppzRZPb+ndKZzps/VPAWOlMNMV8c7tdbQLOL7Fd2c4nEyMiapeTiRERlUtRR0RULkUdEVG5FHVEROVS1BERlUtRR0RULkUdEVG5FHVEROX+CVay0Z8v1PAYAAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(Jp)"
]
},
{
"cell_type": "code",
"execution_count": 138,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f873605d820>"
]
},
"execution_count": 138,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAABXCAYAAAAtSw8kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAHrUlEQVR4nO3dW6xcZQHF8f/ytEWLRtoeR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Vs72vceMRmne2Qz3JOWbYRf0oME/SXElTaE76rB1yhv9S47yQtm+yPcv2HJrX6Ze2i+4p2n4O2C3pre2iy4FtBSNBc8hjkaSp7Xq8nLpOvq4Flre3lwP3FswCNFde0RxSu9r2i6Xz2P697TfYntNu73uAi9rtraR7gMsAJJ0HTKHUF0fZHuoPsJTmTPMu4OZhP/8Emd5N85Z0M7Cp/VlaOldPvvcD95XO0WZ5B7Chfa3uAaZVkOmrwBPAFuBHwBmFctxFc5z8ME3ZfBKYQXO1x1PAL4DpFWTaSXOuaGxb/17pTMc9/gwwWjoTTTHf0W5XG4HFJbYr2/lkYkRE7XIyMSKicinqiIjKpagjIiqXoo6IqFyKOiKicinqiIjKpagjIiqXoo6IqNy/ARrlz6Ly35fuAAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
2024-03-24 10:42:44 +08:00
}
],
"source": [
2024-03-29 01:32:00 +08:00
"plt.imshow(J[0:3,dq_reordering_idx])"
2024-03-24 10:42:44 +08:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"q = np.hstack([pin.SE3ToXYZQUATtuple(pin.SE3(np.eye(4))), np.zeros(12)])\n",
"v = np.zeros(18)\n",
"robot.computeJointJacobians(q)\n",
"robot.framesForwardKinematics(q)\n",
"robot.updateGeometryPlacements(q)\n",
"nle = robot.nle(q, v)\n",
"g = robot.gravity(q)\n",
"robot.centroidalMomentum(q,v)\n",
"pin.computeMinverse(q)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"robot.frameJacobian(q, robot.model.getFrameId('FL_Foot'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"robot.model.frames[2]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"robot.getFrameJacobian(robot.model.getFrameId('FL_Foot'), pin.ReferenceFrame.LOCAL_WORLD_ALIGNED)[0:6,0:6]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pin.se3ToXYZQUATtuple(pin.SE3(np.eye(4)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pin.SE3(np.eye(4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pin.rnea(robot.model, robot.data, q, v, v).shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"M = pin.crba(robot.model, robot.data, q)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"M.T-M"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}