diff --git a/scripts/generate_concert_robot_JSON.ipynb b/scripts/generate_concert_robot_JSON.ipynb index bf8f4f9..3579dfa 100644 --- a/scripts/generate_concert_robot_JSON.ipynb +++ b/scripts/generate_concert_robot_JSON.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -13,9 +13,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ResourceFinder initialized with config file: config_file.yaml\n", + "ResourceFinder found the following resources paths: [['resources_path'], ['external_resources', 'concert_resources_path'], ['external_resources', 'dagana_path']]\n" + ] + } + ], "source": [ "#create UrdfWriter object and joint map to store homing values\n", "urdf_writer = UrdfWriter(speedup=True, floating_base=True)\n", @@ -24,12 +33,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'mobile_base',\n", + " 'type': ,\n", + " 'flange_size': '4',\n", + " 'selected_connector': 'mobile_base_con1',\n", + " 'selected_meshes': ['mobile_base_con1'],\n", + " 'urdf_string': ''}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#add mobile base\n", - "urdf_writer.add_module('concert/mobile_platform_concert.json', 0, False)\n" + "urdf_writer.add_module('concert/mobile_platform_concert.json', module_name='mobile_base')\n" ] }, { @@ -42,73 +67,83 @@ "# leg + wheel 1\n", "data = urdf_writer.select_module_from_name('mobile_base_con1')\n", "wheel_data, steering_data = urdf_writer.add_wheel_module(wheel_filename='concert/module_wheel_concert.json', \n", - " steering_filename='concert/module_steering_concert_fl_rr.json', \n", - " angle_offset=0.0)\n", - "homing_joint_map[str(steering_data['lastModule_name'])] = {'angle': 1.57}\n", - "homing_joint_map[str(wheel_data['lastModule_name'])] = {'angle': 0.0}\n", + " steering_filename='concert/module_steering_concert_fl_rr.json')\n", + "homing_joint_map[str(steering_data['name'])] = 0.0\n", + "homing_joint_map[str(wheel_data['name'])] = 0.0\n", "\n", "# leg + wheel 2\n", "data = urdf_writer.select_module_from_name('mobile_base_con2')\n", "wheel_data, steering_data = urdf_writer.add_wheel_module(wheel_filename='concert/module_wheel_concert.json', \n", - " steering_filename='concert/module_steering_concert_fr_rl.json', \n", - " angle_offset=0.0)\n", - "homing_joint_map[str(steering_data['lastModule_name'])] = {'angle': -1.57}\n", - "homing_joint_map[str(wheel_data['lastModule_name'])] = {'angle': 0.0}\n", + " steering_filename='concert/module_steering_concert_fr_rl.json')\n", + "homing_joint_map[str(steering_data['name'])] = 0.0\n", + "homing_joint_map[str(wheel_data['name'])] = 0.0\n", "\n", "# leg + wheel 3\n", "data = urdf_writer.select_module_from_name('mobile_base_con3')\n", "wheel_data, steering_data = urdf_writer.add_wheel_module(wheel_filename='concert/module_wheel_concert.json', \n", - " steering_filename='concert/module_steering_concert_fr_rl.json', \n", - " angle_offset=0.0)\n", - "homing_joint_map[str(steering_data['lastModule_name'])] = {'angle': -1.57}\n", - "homing_joint_map[str(wheel_data['lastModule_name'])] = {'angle': 0.0}\n", + " steering_filename='concert/module_steering_concert_fr_rl.json')\n", + "homing_joint_map[str(steering_data['name'])] = 0.0\n", + "homing_joint_map[str(wheel_data['name'])] = 0.0\n", "\n", "# leg + wheel 4\n", "data = urdf_writer.select_module_from_name('mobile_base_con4')\n", "wheel_data, steering_data = urdf_writer.add_wheel_module(wheel_filename='concert/module_wheel_concert.json', \n", - " steering_filename='concert/module_steering_concert_fl_rr.json', \n", - " angle_offset=0.0)\n", - "homing_joint_map[str(steering_data['lastModule_name'])] = {'angle': 1.57}\n", - "homing_joint_map[str(wheel_data['lastModule_name'])] = {'angle': 0.0}" + " steering_filename='concert/module_steering_concert_fl_rr.json')\n", + "homing_joint_map[str(steering_data['name'])] = 0.0\n", + "homing_joint_map[str(wheel_data['name'])] = 0.0" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "KeyError", + "evalue": "'concert/module_joint_elbow_concert.json was not found in the available resources'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mKeyError\u001b[39m Traceback (most recent call last)", + "\u001b[36mFile \u001b[39m\u001b[32m~/xbot2_ws/src/modular/src/modular/URDF_writer.py:1883\u001b[39m, in \u001b[36mUrdfWriter.add_module\u001b[39m\u001b[34m(self, filename, offsets, reverse, addons, robot_id, active_ports, is_structural, module_name)\u001b[39m\n\u001b[32m 1882\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1883\u001b[39m module_dict = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mmodular_resources_manager\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_available_modules_dict\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m]\u001b[49m\n\u001b[32m 1884\u001b[39m template_dict = \u001b[38;5;28mself\u001b[39m.modular_resources_manager.get_available_modules_dict()[\u001b[33m'\u001b[39m\u001b[33mtemplate.yaml\u001b[39m\u001b[33m'\u001b[39m]\n", + "\u001b[31mKeyError\u001b[39m: 'concert/module_joint_elbow_concert.json'", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[31mKeyError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[12]\u001b[39m\u001b[32m, line 5\u001b[39m\n\u001b[32m 2\u001b[39m data = urdf_writer.select_module_from_name(\u001b[33m'\u001b[39m\u001b[33mmobile_base_con5\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m# J1\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m5\u001b[39m data = \u001b[43murdf_writer\u001b[49m\u001b[43m.\u001b[49m\u001b[43madd_module\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mconcert/module_joint_elbow_concert.json\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 6\u001b[39m homing_joint_map[\u001b[38;5;28mstr\u001b[39m(data[\u001b[33m'\u001b[39m\u001b[33mname\u001b[39m\u001b[33m'\u001b[39m])] = {\u001b[33m'\u001b[39m\u001b[33mangle\u001b[39m\u001b[33m'\u001b[39m: \u001b[32m0.5\u001b[39m}\n\u001b[32m 8\u001b[39m \u001b[38;5;66;03m#add a 10cm passive link\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32m~/xbot2_ws/src/modular/src/modular/URDF_writer.py:1894\u001b[39m, in \u001b[36mUrdfWriter.add_module\u001b[39m\u001b[34m(self, filename, offsets, reverse, addons, robot_id, active_ports, is_structural, module_name)\u001b[39m\n\u001b[32m 1892\u001b[39m \u001b[38;5;28mself\u001b[39m.print(\u001b[33m\"\u001b[39m\u001b[33mModule loaded from JSON: \u001b[39m\u001b[33m\"\u001b[39m + new_module.name)\n\u001b[32m 1893\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1894\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(filename+\u001b[33m'\u001b[39m\u001b[33m was not found in the available resources\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m 1896\u001b[39m \u001b[38;5;66;03m# Socket module is a custom type. It behaves differently from other link modules because it has no electronics onboard. Its parent should always be the base_link. On the hardware it will actually be connected to a non-structural hub, which therefore will not be part of the URDF, so we consider the base_link to be the parent in any case. This means the ports of the hub will not actually be occupied, so potentially there is no limit to how many sockets could be connected (>3).\u001b[39;00m\n\u001b[32m 1897\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m new_module.type \u001b[38;5;129;01mis\u001b[39;00m ModuleType.SOCKET:\n", + "\u001b[31mKeyError\u001b[39m: 'concert/module_joint_elbow_concert.json was not found in the available resources'" + ] + } + ], "source": [ "# manipulator\n", "data = urdf_writer.select_module_from_name('mobile_base_con5')\n", "\n", "# J1\n", - "data = urdf_writer.add_module('concert/module_joint_elbow_concert.json', 0, False)\n", - "homing_joint_map[str(data['lastModule_name'])] = {'angle': 0.5}\n", + "data = urdf_writer.add_module('concert/module_joint_elbow_A_concert.json')\n", + "homing_joint_map[str(data['name'])] = {'angle': 0.5}\n", "\n", "#add a 10cm passive link\n", - "data = urdf_writer.add_module('concert/module_link_straight_10_concert.json', 0, False)\n", + "data = urdf_writer.add_module('concert/module_link_straight_10_concert.json')\n", "\n", "# J2\n", - "data = urdf_writer.add_module('concert/module_joint_elbow_concert.json', 0, False)\n", - "homing_joint_map[str(data['lastModule_name'])] = {'angle': -0.5}\n", + "data = urdf_writer.add_module('concert/module_joint_elbow_B_concert.json')\n", + "homing_joint_map[str(data['name'])] = {'angle': -0.5}\n", "\n", "#add a 20cm passive link\n", - "data = urdf_writer.add_module('concert/module_link_straight_20_concert.json', 0, False)\n", + "data = urdf_writer.add_module('concert/module_link_straight_20_concert.json')\n", "\n", "# J3\n", - "data = urdf_writer.add_module('concert/module_joint_yaw_concert.json', 0, False)\n", - "homing_joint_map[data['lastModule_name']] = {'angle': 0.0}\n", + "data = urdf_writer.add_module('concert/module_joint_yaw_concert.json')\n", + "homing_joint_map[data['name']] = {'angle': 0.0}\n", "\n", "# J4\n", - "data = urdf_writer.add_module('concert/module_joint_elbow_concert.json', 0, False)\n", - "homing_joint_map[str(data['lastModule_name'])] = {'angle': 0.5}\n", + "data = urdf_writer.add_module('concert/module_joint_elbow_concert.json')\n", + "homing_joint_map[str(data['name'])] = {'angle': 0.5}\n", "\n", "# J5\n", - "data = urdf_writer.add_module('concert/module_joint_elbow_concert.json', 0, False)\n", - "homing_joint_map[str(data['lastModule_name'])] = {'angle': -0.5}\n", - "\n", - "# gripper\n", - "urdf_writer.add_simple_ee(0.0, 0.0, 0.2, 0.0)" + "data = urdf_writer.add_module('concert/module_joint_elbow_concert.json')\n", + "homing_joint_map[str(data['name'])] = {'angle': -0.5}" ] }, { @@ -156,7 +191,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.8.10 64-bit", + "display_name": "env (3.12.3)", "language": "python", "name": "python3" }, @@ -170,14 +205,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.12.3" }, - "orig_nbformat": 2, - "vscode": { - "interpreter": { - "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" - } - } + "orig_nbformat": 2 }, "nbformat": 4, "nbformat_minor": 2