Browse Source

updates to the hippoSIT - added unaudible trials

dianamaro 2 years ago
parent
commit
049409909c
6 changed files with 234 additions and 98 deletions
  1. 31 31
      aSIT.ipynb
  2. 16 8
      background.ipynb
  3. 103 7
      controllers/serial.ipynb
  4. 27 22
      controllers/sound.ipynb
  5. 31 21
      hippoSIT.ipynb
  6. 26 9
      postrack.ipynb

File diff suppressed because it is too large
+ 31 - 31
aSIT.ipynb


+ 16 - 8
background.ipynb

@@ -2,13 +2,15 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 17,
+   "execution_count": 25,
    "metadata": {},
    "outputs": [],
    "source": [
     "import cv2\n",
     "import os, json\n",
-    "import numpy as np"
+    "import numpy as np\n",
+    "\n",
+    "from controllers.situtils import FPSTimes"
    ]
   },
   {
@@ -20,12 +22,14 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 18,
+   "execution_count": 26,
    "metadata": {},
    "outputs": [],
    "source": [
-    "is_light = True\n",
-    "settings_filename = os.path.join('profiles', 'prodesk-home-aSIT.json')\n",
+    "is_light = False\n",
+    "#settings_filename = os.path.join('profiles', 'kate_postrack.json')\n",
+    "#settings_filename = os.path.join('profiles', 'kate_aSIT_single.json')\n",
+    "settings_filename = os.path.join('profiles', 'andrey_hippoSIT_test.json')\n",
     "\n",
     "with open(settings_filename) as json_file:\n",
     "    cfg = json.load(json_file)"
@@ -33,7 +37,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 19,
+   "execution_count": 27,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -58,8 +62,11 @@
     "cap.set(cv2.CAP_PROP_FPS, cfg_cam['fps'])\n",
     "cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))    \n",
     "\n",
+    "fps = FPSTimes()\n",
+    "\n",
     "while(True):\n",
     "    ret, frame = cap.read()\n",
+    "    fps.count()\n",
     "\n",
     "    # Draw the arena area\n",
     "    cv2.circle(frame, (cfg_pos['arena_x'], cfg_pos['arena_y']), cfg_pos['arena_radius'], BGR_COLOR['red'], 2)\n",
@@ -69,7 +76,8 @@
     "    cv2.circle(mask, (cfg_pos['arena_x'], cfg_pos['arena_y']), cfg_pos['arena_radius'], BGR_COLOR['white'], -1)\n",
     "    \n",
     "    frame = cv2.bitwise_and(src1=frame, src2=mask)\n",
-    "    cv2.putText(frame, 'LIGHT' if is_light else 'DARK', (10, 20), cv2.FONT_HERSHEY_DUPLEX, .5, (255, 255, 255))\n",
+    "    cv2.putText(frame, 'LIGHT' if is_light else 'DARK', (10, 20), cv2.FONT_HERSHEY_DUPLEX, .5, BGR_COLOR['white'])\n",
+    "    cv2.putText(frame, '%.2f FPS' % fps.get_avg_fps(), (10, 40), cv2.FONT_HERSHEY_DUPLEX, .5, BGR_COLOR['white'])    \n",
     "    cv2.imshow('Press \"c\" to capture, \"q\" to quit', frame)\n",
     "\n",
     "    k = cv2.waitKey(33)\n",
@@ -109,7 +117,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.8.10"
+   "version": "3.8.8"
   }
  },
  "nbformat": 4,

+ 103 - 7
controllers/serial.ipynb

@@ -2,7 +2,8 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 1,
+   "id": "82162890",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -13,7 +14,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 2,
+   "id": "fe78b7d4",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -53,7 +55,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 3,
+   "id": "99209a2c",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -81,6 +84,7 @@
   },
   {
    "cell_type": "markdown",
+   "id": "56d33a31",
    "metadata": {},
    "source": [
     "### Testing Arduino TTL pulses"
@@ -88,7 +92,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 4,
+   "id": "a8ee4492",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -98,6 +103,7 @@
   {
    "cell_type": "code",
    "execution_count": 11,
+   "id": "8aef8b20",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -107,7 +113,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 32,
+   "execution_count": 20,
+   "id": "94466a46",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -117,7 +124,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 21,
+   "execution_count": 5,
+   "id": "c0687f02",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -127,9 +135,94 @@
     "    time.sleep(2)"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "id": "7e755da5",
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "['PWM_CAPABLE',\n",
+       " '__class__',\n",
+       " '__delattr__',\n",
+       " '__dict__',\n",
+       " '__dir__',\n",
+       " '__doc__',\n",
+       " '__eq__',\n",
+       " '__format__',\n",
+       " '__ge__',\n",
+       " '__getattribute__',\n",
+       " '__gt__',\n",
+       " '__hash__',\n",
+       " '__init__',\n",
+       " '__init_subclass__',\n",
+       " '__le__',\n",
+       " '__lt__',\n",
+       " '__module__',\n",
+       " '__ne__',\n",
+       " '__new__',\n",
+       " '__reduce__',\n",
+       " '__reduce_ex__',\n",
+       " '__repr__',\n",
+       " '__setattr__',\n",
+       " '__sizeof__',\n",
+       " '__str__',\n",
+       " '__subclasshook__',\n",
+       " '__weakref__',\n",
+       " '_get_mode',\n",
+       " '_mode',\n",
+       " '_set_mode',\n",
+       " 'board',\n",
+       " 'disable_reporting',\n",
+       " 'enable_reporting',\n",
+       " 'mode',\n",
+       " 'pin_number',\n",
+       " 'port',\n",
+       " 'read',\n",
+       " 'reporting',\n",
+       " 'type',\n",
+       " 'value',\n",
+       " 'write']"
+      ]
+     },
+     "execution_count": 7,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "dir(board.digital[5])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "id": "bc432891",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "False"
+      ]
+     },
+     "execution_count": 14,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "board.digital[5].value"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": 12,
+   "id": "f883b19d",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -138,6 +231,7 @@
   },
   {
    "cell_type": "markdown",
+   "id": "54d9ffa1",
    "metadata": {},
    "source": [
     "### Testing feeder"
@@ -146,6 +240,7 @@
   {
    "cell_type": "code",
    "execution_count": 4,
+   "id": "990f5a4f",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -160,6 +255,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
+   "id": "982eb841",
    "metadata": {},
    "outputs": [],
    "source": []
@@ -181,7 +277,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.8.10"
+   "version": "3.8.8"
   }
  },
  "nbformat": 4,

+ 27 - 22
controllers/sound.ipynb

@@ -468,8 +468,8 @@
        "  'hostapi': 2,\n",
        "  'max_input_channels': 6,\n",
        "  'max_output_channels': 10,\n",
-       "  'default_low_input_latency': 0.005804988662131519,\n",
-       "  'default_low_output_latency': 0.005804988662131519,\n",
+       "  'default_low_input_latency': 0.0014512471655328798,\n",
+       "  'default_low_output_latency': 0.0014512471655328798,\n",
        "  'default_high_input_latency': 0.09287981859410431,\n",
        "  'default_high_output_latency': 0.09287981859410431,\n",
        "  'default_samplerate': 44100.0}]"
@@ -487,21 +487,22 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [],
    "source": [
     "import sounddevice as sd\n",
     "import numpy as np\n",
+    "import keyboard  # using module keyboard\n",
     "\n",
     "sd.default.device = [1, 26]\n",
     "sd.default.samplerate = 44100\n",
-    "stream = sd.OutputStream(samplerate=44100, channels=10, dtype='float32')\n"
+    "stream = sd.OutputStream(samplerate=44100, channels=10, dtype='float32')"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 2,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -511,33 +512,37 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 3,
    "metadata": {},
    "outputs": [],
    "source": [
-    "stream.start()\n",
+    "duration = 0.5\n",
     "\n",
-    "duration = 10\n",
     "x1 = np.linspace(0, duration * 220 * 2*np.pi, int(duration*44100), dtype=np.float32)\n",
     "x2 = np.linspace(0, duration * 440 * 2*np.pi, int(duration*44100), dtype=np.float32)\n",
     "y1 = np.sin(x1)\n",
     "y2 = np.sin(x2)\n",
-    "sil = np.zeros(len(x1), dtype=np.float32)\n",
-    "\n",
-    "#stream.write(np.column_stack([y1, sil, sil, sil, sil, sil, sil, sil, sil, sil]) * 0.5)\n",
-    "#stream.write(np.column_stack([sil, y1, sil, sil, sil, sil, sil, sil, sil, sil]) * 0.5)\n",
-    "stream.write(np.column_stack([sil, sil, sil, sil, sil, y1, sil, sil, sil, sil]) * 0.5)\n",
-    "#stream.write(np.column_stack([sil, sil, sil, sil, sil, y1, sil, sil, sil, sil]) * 0.5)\n",
-    "\n",
+    "sil = np.zeros(len(x1), dtype=np.float32)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "stream.start()\n",
     "\n",
-    "# for i in range(10):\n",
-    "#     if i % 2 == 0:\n",
-    "#         output = np.column_stack([y1, sil, sil, sil])\n",
-    "#     else:\n",
-    "#         output = np.column_stack([sil, sil, y2, sil])\n",
-    "#     stream.write(output*0.5)\n",
+    "try:\n",
+    "    while True:  # making a loop\n",
+    "        if keyboard.is_pressed('q'):  # if key 'q' is pressed \n",
+    "            break  # finishing the loop\n",
     "\n",
-    "stream.stop()"
+    "        stream.write(np.column_stack([y1, sil, sil, sil, sil, sil, sil, y2, sil, sil]) * 0.8)\n",
+    "        #stream.write(np.column_stack([y2, y2, y2, y2, y2, y2, y2, y2, y2, y2]) * 0.8)\n",
+    "    \n",
+    "finally:\n",
+    "    stream.stop()"
    ]
   },
   {

File diff suppressed because it is too large
+ 31 - 21
hippoSIT.ipynb


+ 26 - 9
postrack.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 36,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -44,16 +44,16 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 37,
    "metadata": {},
    "outputs": [],
    "source": [
-    "cfg_filename = os.path.join('profiles', 'andrey_postrack_test.json')"
+    "cfg_filename = os.path.join('profiles', 'kate_postrack.json')"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 38,
    "metadata": {
     "scrolled": false
    },
@@ -75,7 +75,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 39,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -106,7 +106,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 40,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -116,7 +116,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 41,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -142,7 +142,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 42,
    "metadata": {
     "scrolled": true
    },
@@ -151,7 +151,10 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Webcam stream 1024.0:768.0 at 20.00 FPS started\n"
+      "Webcam stream 1024.0:768.0 at 20.00 FPS started\n",
+      "Position tracker stopped\n",
+      "Video writer stopped\n",
+      "Camera released\n"
      ]
     }
    ],
@@ -297,6 +300,20 @@
     "        ctrl.stop()"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
   {
    "cell_type": "code",
    "execution_count": null,