Go2Py/examples/vicon2gt-dataset-collector....

141 lines
3.2 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lowlevel Interface Test"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pygame 2.5.2 (SDL 2.28.2, Python 3.8.18)\n",
"Hello from the pygame community. https://www.pygame.org/contribute.html\n"
]
}
],
"source": [
"from Go2Py.robot.interface.ros2 import GO2Real, ros2_init, ROS2ExecutorManager\n",
"from Go2Py.robot.interface.ros2 import ROS2TFInterface\n",
"import time\n",
"ros2_init()\n",
"vicon = ROS2TFInterface('vicon/World', 'vicon/GO2/GO2', 'vicon')\n",
"robot = GO2Real(mode='highlevel')\n",
"ros2_exec_manager = ROS2ExecutorManager()\n",
"ros2_exec_manager.add_node(robot)\n",
"ros2_exec_manager.add_node(vicon)\n",
"ros2_exec_manager.start()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"for i in range(1000):\n",
" time.sleep(0.01)\n",
" imu = robot.getIMU()\n",
" accel = imu['accel']\n",
" gyro = imu['gyro']\n",
" q = imu['quat']\n",
" pose = vicon.get_pose()\n",
" stamp = time.time()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"import numpy as np\n",
"im = []\n",
"acc = []\n",
"gy = []\n",
"quaternion = []\n",
"pos = []\n",
"stamps = []\n",
"for i in range(2000):\n",
" time.sleep(0.01)\n",
" imu = robot.getIMU()\n",
" accel = imu['accel']\n",
" gyro = imu['gyro']\n",
" q = imu['quat']\n",
" pose = vicon.get_pose()\n",
" stamp = time.time()\n",
" im.append(imu)\n",
" acc.append(accel)\n",
" gy.append(gyro)\n",
" quaternion.append(q)\n",
" pos.append(pose)\n",
" stamps.append(stamp)\n",
"\n",
"imu = np.array(im)\n",
"accel = np.array(acc)\n",
"gyro = np.array(gy)\n",
"q = np.array(quaternion)\n",
"pose = np.array(pos)\n",
"stamp = np.array(stamps)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"import pickle \n",
"with open('vicon2gt_3.pkl', 'wb') as f:\n",
" pickle.dump(\n",
" {\n",
" 'imu':imu,\n",
" 'accel':accel,\n",
" 'gyro':gyro,\n",
" 'q':q,\n",
" 'pose':pose,\n",
" 'stamp':stamp\n",
" }\n",
" ,f\n",
" )"
]
},
{
"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.18"
}
},
"nbformat": 4,
"nbformat_minor": 4
}