From 7d6c9b95ecd4f71c86989619f5ee1bb5dc2335ab Mon Sep 17 00:00:00 2001 From: Misko Date: Tue, 19 Mar 2024 22:00:18 -0700 Subject: [PATCH] updaets to notebooks --- spf/notebooks/docker.ipynb | 113 +++++++++++++ spf/notebooks/gps_boundary.ipynb | 21 ++- .../load_real_data_session_v3rx.ipynb | 94 +++++++++- spf/notebooks/mavlink.ipynb | 160 ++++++++++++++++++ 4 files changed, 381 insertions(+), 7 deletions(-) create mode 100644 spf/notebooks/docker.ipynb create mode 100644 spf/notebooks/mavlink.ipynb diff --git a/spf/notebooks/docker.ipynb b/spf/notebooks/docker.ipynb new file mode 100644 index 00000000..6a7fc2ca --- /dev/null +++ b/spf/notebooks/docker.ipynb @@ -0,0 +1,113 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# docker run --rm -it -p 14590-14595:14590-14595 ardupilot_spf /ardupilot/Tools/autotest/sim_vehicle.py \\\n", + "# -l 37.76509485,-122.40940127,0,0 -v rover -f rover-skid \\\n", + "# --out tcpin:0.0.0.0:14590 --out tcpin:0.0.0.0:14591 -S 1\n", + "import docker" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client = docker.from_env()\n", + "container = client.containers.run(\n", + " \"csmisko/ardupilotspf:latest\",\n", + " \"/ardupilot/Tools/autotest/sim_vehicle.py -l 37.76509485,-122.40940127,0,0 \\\n", + " -v rover -f rover-skid --out tcpin:0.0.0.0:14590 --out tcpin:0.0.0.0:14591 -S 5\",\n", + " stdin_open=True,\n", + " ports={\n", + " \"14590/tcp\": (\"127.0.0.1\", 14590),\n", + " \"14591/tcp\": (\"127.0.0.1\", 14591),\n", + " },\n", + " detach=True,\n", + " remove=True,\n", + " auto_remove=True,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "output = container.attach(stdout=True, stream=True, logs=True)\n", + "online = False\n", + "for line in output:\n", + " if \"Detected vehicle\" in line:\n", + " online = True\n", + "if not online:\n", + " raise ValueError\n", + "\n", + "# (\"ardupilot_spf\"\n", + "# image=\"ardupilot_spf\",\n", + "# auto_remove=True,\n", + "# name=\"test_postgres\",\n", + "# ports={\"14590/tcp\": (\"127.0.0.1\", 14590)},\n", + "# detach=True,\n", + "# remove=True,\n", + "# )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "container" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client.containers.list()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "spf", + "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.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/spf/notebooks/gps_boundary.ipynb b/spf/notebooks/gps_boundary.ipynb index b14c5766..e3aa9008 100644 --- a/spf/notebooks/gps_boundary.ipynb +++ b/spf/notebooks/gps_boundary.ipynb @@ -8,7 +8,17 @@ "source": [ "import numpy as np\n", "\n", - "from boundaries import franklin_boundary, crissy_boundary, crissy_boundary_convex\n", + "repo_root = \"/Users/miskodzamba/Dropbox/research/gits/spf/\"\n", + "import sys\n", + "\n", + "sys.path.append(repo_root) # go to parent dir\n", + "# from boundaries import\n", + "from spf.gps.boundaries import (\n", + " franklin_boundary,\n", + " crissy_boundary,\n", + " crissy_boundary_convex,\n", + " franklin_safe,\n", + ")\n", "\n", "from matplotlib import pyplot as plt\n", "\n", @@ -19,6 +29,15 @@ "plt.axis(\"equal\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "franklin_safe.mean(axis=0)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/spf/notebooks/load_real_data_session_v3rx.ipynb b/spf/notebooks/load_real_data_session_v3rx.ipynb index 39f29ce1..9bf4a370 100644 --- a/spf/notebooks/load_real_data_session_v3rx.ipynb +++ b/spf/notebooks/load_real_data_session_v3rx.ipynb @@ -30,8 +30,16 @@ "data_root_dir = (\n", " \"/Users/miskodzamba/Dropbox/research/spf_aux/missions/march13/rover3/second_try\"\n", ")\n", + "data_root_dir = (\n", + " \"/Users/miskodzamba/Dropbox/research/spf_aux/missions/march13/rover1/second_try\"\n", + ")\n", + "# data_root_dir = \"/Users/miskodzamba/Dropbox/research/spf_aux/missions/march14/rover3\"\n", "# data_root_dir = \"/Users/miskodzamba/Dropbox/research/spf_aux/missions/march13/roof/laptop_recording\"\n", "\n", + "# march 17\n", + "data_root_dir = \"/Users/miskodzamba/Dropbox/research/spf_aux/missions/march17/rover3\"\n", + "# data_root_dir = \"/Users/miskodzamba/Dropbox/research/spf_aux/missions/march17/rover2/1\"\n", + "\n", "width = 3000 # height is assumed to be same\n", "step_size = 1\n", "\n", @@ -46,11 +54,73 @@ "# pick a session from the dataset\n", "session_idx = 0 # 2**14\n", "session1 = ds[(0, session_idx)]\n", - "session2 = session1\n", - "# session2 = ds[(1, session_idx)]\n", + "# session2 = session1\n", + "session2 = ds[(1, session_idx)]\n", "print(ds.root_dir)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "c3554a8c", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "import datetime\n", + "\n", + "z = datetime.datetime.fromtimestamp(session2[\"time_stamps\"][0]) #\n", + "# .strftime(\n", + "# \"%Y-%m-%d %H:%M:%S\"\n", + "# )\n", + "z.minute, z" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "91afc2e7", + "metadata": {}, + "outputs": [], + "source": [ + "z = datetime.datetime.fromtimestamp(session2[\"time_stamps\"][0]) #\n", + "z" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a14e7c90", + "metadata": {}, + "outputs": [], + "source": [ + "z = datetime.datetime.fromtimestamp(session2[\"time_stamps\"][0]) #\n", + "z" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "696def35", + "metadata": {}, + "outputs": [], + "source": [ + "z = datetime.datetime.fromtimestamp(datetime.datetime.now().timestamp())\n", + "z.strftime(\"%Y_%m_%d_%H_%M_%S\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "91dbf93c", + "metadata": {}, + "outputs": [], + "source": [ + "z = datetime.datetime.fromtimestamp(datetime.datetime.now().timestamp())\n", + "z.strftime(\"%Y_%m_%d_%H_%M_%S\")" + ] + }, { "cell_type": "code", "execution_count": null, @@ -214,6 +284,16 @@ "peaks" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "de5b3716", + "metadata": {}, + "outputs": [], + "source": [ + "session1.keys()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -280,12 +360,14 @@ " # )\n", " axs[0, 1 + session_idx].set_title(f\"SDR:{session_idx} phaseRX0-phaseRX1\")\n", " axs[0, 1 + session_idx].scatter(\n", - " np.arange(peaks_at_t_in_radians.shape[0]), peaks_at_t_in_radians[:, 0]\n", + " np.arange(peaks_at_t_in_radians.shape[0]),\n", + " peaks_at_t_in_radians[:, 0],\n", + " alpha=0.1,\n", " )\n", - " # print(peaks_at_t_in_radians[:, 0].shape)\n", - " # axs[0, 1 + session_idx].scatter(peaks_at_t_in_radians[:, 0])\n", " axs[0, 1 + session_idx].scatter(\n", - " np.arange(peaks_at_t_in_radians.shape[0]), peaks_at_t_in_radians[:, 1]\n", + " np.arange(peaks_at_t_in_radians.shape[0]),\n", + " peaks_at_t_in_radians[:, 1],\n", + " alpha=0.1,\n", " )\n", " axs[0, 1 + session_idx].set_ylim([-np.pi, +np.pi])\n", " axs[0, 1 + session_idx].set_xlabel(\"Time\")\n", diff --git a/spf/notebooks/mavlink.ipynb b/spf/notebooks/mavlink.ipynb new file mode 100644 index 00000000..e90b7877 --- /dev/null +++ b/spf/notebooks/mavlink.ipynb @@ -0,0 +1,160 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from pymavlink import mavutil, mavwp\n", + "\n", + "\n", + "ip = \"192.168.1.140\"\n", + "port = 14550\n", + "\n", + "\n", + "connection = mavutil.mavlink_connection(f\"udpin:{ip}:{port}\") # tcp is 5670\n", + "\n", + "connection.wait_heartbeat()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "connection.mav.play_tune_send(\n", + " connection.target_system,\n", + " connection.target_component,\n", + " # b\"T200O2L1A#\"\n", + " b\"MFT240L8 O4aO5dc O4aO5dc O4aO5dc L16dcdcdcdc\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for x in range(255):\n", + " connection.mav.command_long_send(\n", + " x, # connection.target_system,\n", + " 0, # connection.target_component,\n", + " mavutil.mavlink.MAV_CMD_USER_1,\n", + " 0, # set position\n", + " 1, # param1\n", + " 2, # param2\n", + " 3, # param3\n", + " 4, # param4\n", + " 5, # 37.8047122, # lat\n", + " 6, # -122.4659164, # lon\n", + " 7,\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "connection.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_CRITICAL, \"test\".encode())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "connection.param_fetch_all()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "text = \"Hello Pixhawk\".encode(\"utf-8\")\n", + "connection.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_INFO, text)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "connection.mav.param_set_send\n", + "# (\"pi_routine\",1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "connection.param_fetch_one(\"MODE\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "param_set_send(self, parm_name, parm_value, parm_type=None):\n", + "\n", + "mav.param_set_send(7, 1, b\"WP_RADIUS\", 101, mavlink.MAV_PARAM_TYPE_REAL32)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from pymavlink import mavparm\n", + "\n", + "d = mavparm.MAVParmDict()\n", + "import os\n", + "\n", + "os.path.curdir" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "d.load(\"../\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "spf", + "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.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}