-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement real-time logging of control variables
- Loading branch information
Showing
3 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"import pickle\n", | ||
"\n", | ||
"import pandas\n", | ||
"from pandas import DataFrame\n", | ||
"import yaml\n", | ||
"\n", | ||
"\n", | ||
"def log_as_dataframe(log):\n", | ||
" columns = ['timestamp', 'level', 'source', 'function', 'data']\n", | ||
" df = pandas.DataFrame(log, columns=columns)\n", | ||
" return df\n", | ||
"\n", | ||
"\n", | ||
"df = log_as_dataframe(pickle.load(open('../log.pkl', 'rb')))\n", | ||
"df = df[df['level'] == 'DATA']\n", | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"data = []\n", | ||
"for row in df.itertuples():\n", | ||
" try:\n", | ||
" value = yaml.load(row.data)\n", | ||
" except yaml.error.YAMLError:\n", | ||
" continue\n", | ||
" if len(value) != 10:\n", | ||
" print(value)\n", | ||
" continue\n", | ||
" data.append([row.timestamp] + value)\n", | ||
"df = DataFrame(data)\n", | ||
"df.columns = ['timestamp', 'front_left', 'front_right', 'side_left', 'side_right',\n", | ||
" 'linear_ideal', 'linear_measured', 'angular_ideal', 'angular_measured',\n", | ||
" 'pwm_left', 'pwm_right']\n", | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"diffs = df['timestamp'].diff().shift(-1)\n", | ||
"df = df[(diffs > 0) & (diffs < 4)]\n", | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"df['timestamp'] /= 1000\n", | ||
"df.set_index('timestamp')\n", | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from bokeh.io import output_notebook\n", | ||
"from bokeh.io import show\n", | ||
"from bokeh.layouts import gridplot\n", | ||
"from bokeh.models import ColumnDataSource\n", | ||
"from bokeh.plotting import figure\n", | ||
"\n", | ||
"\n", | ||
"output_notebook()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def show_data(df):\n", | ||
" sensors = figure(width=800, height=400,\n", | ||
" title='Front sensors log',\n", | ||
" x_axis_label='Time (s)',\n", | ||
" y_axis_label='Distance (m)',\n", | ||
" y_range=(0., 0.4))\n", | ||
" sensors.line(x=df.index, y=df['front_left'], color='orange', legend='Front-left')\n", | ||
" sensors.line(x=df.index, y=df['front_right'], legend='Front-right')\n", | ||
"\n", | ||
" linear = figure(width=800, height=400,\n", | ||
" title='Linear speed',\n", | ||
" x_axis_label='Time (s)',\n", | ||
" y_axis_label='Speed (m/s)',\n", | ||
" x_range=sensors.x_range)\n", | ||
" linear.line(x=df.index, y=df['linear_ideal'], color='orange', legend='Ideal')\n", | ||
" linear.line(x=df.index, y=df['linear_measured'], legend='Measured')\n", | ||
"\n", | ||
" angular = figure(width=800, height=400,\n", | ||
" title='Angular speed',\n", | ||
" x_axis_label='Time (s)',\n", | ||
" y_axis_label='Speed (rad/s)',\n", | ||
" x_range=sensors.x_range)\n", | ||
" angular.line(x=df.index, y=df['angular_ideal'], color='orange', legend='Ideal')\n", | ||
" angular.line(x=df.index, y=df['angular_measured'], legend='Measured')\n", | ||
"\n", | ||
" pwm = figure(width=800, height=400,\n", | ||
" title='Output PWM',\n", | ||
" x_axis_label='Time (s)',\n", | ||
" y_axis_label='Duty',\n", | ||
" x_range=sensors.x_range)\n", | ||
" pwm.line(x=df.index, y=df['pwm_left'], color='orange', legend='Left')\n", | ||
" pwm.line(x=df.index, y=df['pwm_right'], legend='Right')\n", | ||
"\n", | ||
" grid = gridplot([sensors, linear, angular, pwm], ncols=1)\n", | ||
"\n", | ||
" show(grid)\n", | ||
"\n", | ||
"\n", | ||
"show_data(df)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.6.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters