Skip to content

Commit

Permalink
Merge pull request #20 from MobileRoboticsSkoltech/control_server
Browse files Browse the repository at this point in the history
Remote recording control
  • Loading branch information
azaat authored Mar 10, 2021
2 parents 5a81d70 + 3ecc96b commit b2459f8
Show file tree
Hide file tree
Showing 27 changed files with 1,376 additions and 167 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ uninstall.bat
*.keystore

opencamera-extended-firebase-adminsdk-yv5yz-e33a8ce5c1.json

*.csv

*.mp4
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ script:
--app $TRAVIS_BUILD_DIR/app/build/outputs/apk/debug/app-debug.apk
--test $TRAVIS_BUILD_DIR/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
--device model=blueline,version=28,locale=en,orientation=portrait
--device model=x1q,version=29,locale=en,orientation=portrait
--test-targets "class net.sourceforge.opencamera.test.SubsetTests";
fi

Expand All @@ -68,9 +69,9 @@ deploy:
provider: releases
api-key: $GITHUB_API_KEY
file: $TRAVIS_BUILD_DIR/app/build/outputs/apk/release/app-release.apk
name: dev-build-$TRAVIS_TAG
name: $TRAVIS_TAG
body: Automatic build of $TRAVIS_BRANCH ($TRAVIS_COMMIT) built by Travis CI on $(date +'%F %T %Z').
prerelease: true
prerelease: false
overwrite: true
target_commitish: $TRAVIS_COMMIT
on:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ This project is based on [Open Camera](https://opencamera.org.uk/) — a popul
- IMU data and frame timestamps in the directory ```{VIDEO_DATE}```:
-```{VIDEO_NAME}_gyro.csv```, data format: ```X-data, Y-data, Z-data, timestamp (ns)```
- ```{VIDEO_NAME}_accel.csv```, data format: ```X-data, Y-data, Z-data, timestamp (ns)```
- ```{VIDEO_NAME}_timestamps.csv```, data format: ```timestamp (ns)```
- ```{VIDEO_NAME}_timestamps.csv```, data format: ```timestamp (ns)```

### Remote recording

- **Connect** smartphone to the same network as PC
- Use scripts provided in ```./api_client/``` directory to **send requests** for the application

## Good practices for data recording

Expand Down
153 changes: 153 additions & 0 deletions api_client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
### VirtualEnv template
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml

# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# Gradle:
.idea/gradle.xml
.idea/libraries

# Mongo Explorer plugin:
.idea/mongoSettings.xml

.idea/

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

*.csv
15 changes: 15 additions & 0 deletions api_client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Remote control API client

Provides **Python 3** and **Python 2**-compatible interface for communication with the smartphone running OpenCamera Sensors.

### Setup

Install requirements.

### Usage

See ```src/RemoteControl.py``` for class documentation and available public methods.

- ```basic_example.py``` - example usage of all class methods
- ```async_imu_example``` - example with non-blocking usage of ```get_imu``` method that works in
**Python 2**
30 changes: 30 additions & 0 deletions api_client/async_imu_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import time
from src.RemoteControl import RemoteControl
from concurrent.futures import ThreadPoolExecutor

HOST = '192.168.1.100' # The smartphone's IP address


def main():
remote = RemoteControl(HOST)

with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(remote.get_imu, 10000, True, False)
# Do something else
print("doing other stuff...")
time.sleep(10)
print("done doing other stuff")
# Get result when needed
accel_data, gyro_data = future.result()
# Process result somehow (here just file output)
print("Accelerometer data length: %d" % len(accel_data))
with open("accel.csv", "w+") as accel:
accel.writelines(accel_data)

print('EXITED')
remote.close()


if __name__ == '__main__':
main()

34 changes: 34 additions & 0 deletions api_client/basic_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import time
from src.RemoteControl import RemoteControl
import subprocess

HOST = '192.168.1.100' # The smartphone's IP address


def main():
# example class usage
# constructor starts the connection
remote = RemoteControl(HOST)
print("Connected")

accel_data, gyro_data = remote.get_imu(10000, True, False)
print("Accelerometer data length: %d" % len(accel_data))
with open("accel.csv", "w+") as accel:
accel.writelines(accel_data)

phase, duration = remote.start_video()
print("%d %f" % (phase, duration))
time.sleep(5)
remote.stop_video()

# receives last video (blocks until received)
start = time.time()
filename = remote.get_video(want_progress_bar=True)
end = time.time()
print("elapsed: %f" % (end - start))
print('Closing connection')
remote.close()


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions api_client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
futures
progress
Loading

0 comments on commit b2459f8

Please sign in to comment.