Skip to content

Commit

Permalink
Merge pull request #3 from taoyilee/dev
Browse files Browse the repository at this point in the history
Dev v0.2 release
  • Loading branch information
Michael (Tao-Yi) Lee authored Mar 21, 2018
2 parents 3a65167 + bf68abb commit 7624d73
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 195 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.csv
data_collection
.idea
# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
Empty file modified LICENSE
100644 → 100755
Empty file.
22 changes: 19 additions & 3 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,28 @@ Beagle Bone Blue Data Acquisition is a collection of python scripts which allows
Install smbus-cffi on your beagle bone. It is recommended to use virtual environment

```commandline
pip install smbus-cffi
pip install -r requirements.txt
```

Run read9axis to acquire 9-axis data dump in CLI
Run ./bbblue_acq to acquire 12-axis data dump in CLI
```commandline
python read9axis.py
./bbblue_acq
#usage: bbblue_acq [-h] [-3] [-6] [-9] [-12] [-c] [-d] [--csv CSV]
# [--db-server-ip DB_SERVER_IP]
#Beagle Bone Blue Data Acquisition Wrapper
#optional arguments:
# -h, --help show this help message and exit
# -3 3 Axis Mode
# -6 6 Axis Mode
# -9 9 Axis Mode
# -12 12 Axis Mode
# -c Write CSV
# -d Write Database
# --csv CSV Specific CSV File Name Write
# --db-server-ip DB_SERVER_IP
# Mysql Database Server IP
```

## Remote Interpreter Setup
Expand Down
81 changes: 81 additions & 0 deletions bbblue_acq
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python
import argparse
import csv
import datetime
import os
import time

from app.sensors import AK8963 as msu
from app.sensors import BMP280 as barometer
from app.sensors import MPU9250 as imu


def main(write_csv=False, write_db=False, verbosity=0):
mpu9250 = imu.MPU9250()
ak8963 = msu.AK8963()
bmp280 = barometer.BMP280()

mpu9250.configMPU9250(imu.GFS_250, imu.AFS_8G)
ak8963.configAK8963(msu.AK8963_MODE_C100HZ, msu.AK8963_BIT_16)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H%M%S')
output_dir = "data_collection"
os.makedirs(output_dir, exist_ok=True)

output_file = os.path.join(output_dir, f"data_12axis_{st}.csv")

if write_csv:
print(f"** {st} Writing CSV to {output_file}")
csv_file_handle = open(output_file, 'w', newline='')
csv_writer = csv.writer(csv_file_handle, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(
["Data", "Timestamp", "Wall_Time", "MPU_Temp", "IMU_Ax", "IMU_Ay", "IMU_Az", "IMU_Gx", "IMU_Gy",
"IMU_Gz", "MSU_Ax", "MSU_Ay", "MSU_Az", "Baro_Temp", "Baro"])
i = 0
while True:
try:
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H%M%S')
temp_imu = mpu9250.readTemperature()
acc = mpu9250.readAccel()
gyro = mpu9250.readGyro()
magnet = ak8963.readMagnet()
temperature_barometer = bmp280.readTemperature()[0]
barometric_pressure = bmp280.readPressure()

if verbosity > 0:
print(f"{ts:.2f} {st} MPU9250 Data: = {temp_imu:.1f} C ")
print(f"{ts:.2f} {st} \t{acc['x']:= 7.2f} G {acc['y']:= 7.2f} G {acc['z']:= 7.2f} G")
print(f"{ts:.2f} {st} \t{gyro['x']:= 7.2f} dps {gyro['y']:= 7.2f} dps {gyro['z']:= 7.2f} dps")
print(f"{ts:.2f} {st} AK8963 Data: = {magnet['x']:= 7.2f} {magnet['y']:= 7.2f} {magnet['z']:= 7.2f}")
print(f"{ts:.2f} {st} BMP280 Data: = {temperature_barometer:.1f} C ", end="")
print(f"{barometric_pressure:.1f} hPa")

csv_writer.writerow([i, ts, st, temp_imu, acc['x'], acc['y'], acc['z'], gyro['x'], gyro['y'], gyro['z'],
magnet['x'], magnet['y'], magnet['z'], temperature_barometer,
barometric_pressure]) if write_csv else None
i += 1
except KeyboardInterrupt:
print(f"** {st} KeyboardInterrupt received, closing file.")
csv_file_handle.close() if write_csv else None
break


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Beagle Bone Blue Data Acquisition Wrapper')
parser.add_argument('-3', help='3 Axis Mode', action='store_true')
parser.add_argument('-6', help='6 Axis Mode', action='store_true')
parser.add_argument('-9', help='9 Axis Mode', action='store_true')
parser.add_argument('-12', help='12 Axis Mode', action='store_true')
parser.add_argument('-c', help='Write CSV', action='store_true')
parser.add_argument('-d', help='Write Database', action='store_true')
parser.add_argument('--csv', nargs=1, help='Specific CSV File Name Write')
parser.add_argument('--db-server-ip', nargs=1, help='Mysql Database Server IP')
parser.add_argument('--verbose', '-v', action='count')
args = vars(parser.parse_args())
write_csv = args['c']
write_db = args['d']
verbosity = args['verbose']
if not write_csv and not write_db:
verbosity = 1
main(write_csv=args['c'], write_db=args['d'], verbosity=verbosity)
55 changes: 0 additions & 55 deletions lib.py

This file was deleted.

13 changes: 0 additions & 13 deletions read10axis.py

This file was deleted.

32 changes: 0 additions & 32 deletions read12axis.py

This file was deleted.

10 changes: 0 additions & 10 deletions read6axis.py

This file was deleted.

13 changes: 0 additions & 13 deletions read9axis.py

This file was deleted.

9 changes: 0 additions & 9 deletions readbaro.py

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mysql-connector-python==8.0.6
smbus-cffi==0.5.1
60 changes: 0 additions & 60 deletions reset_AK8963.py

This file was deleted.

0 comments on commit 7624d73

Please sign in to comment.