Skip to content

Commit 166dd8a

Browse files
authored
Educational visualization for demos (#732)
2 parents 83e4fcd + c0a56c9 commit 166dd8a

34 files changed

Lines changed: 3599 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
out/

bitbots_misc/bitbots_education/bitbots_education/__init__.py

Whitespace-only changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import csv
2+
import os
3+
import time
4+
5+
from ament_index_python import get_package_share_directory
6+
from flask import Flask, render_template, request
7+
8+
template_dir = os.path.join(get_package_share_directory("bitbots_education"), "templates")
9+
static_folder = os.path.join(get_package_share_directory("bitbots_education"), "static")
10+
csv_file_path = os.path.realpath("logs.csv")
11+
12+
app = Flask(__name__, template_folder=template_dir, static_folder=static_folder)
13+
14+
15+
def write_csv(vp, page, button, status):
16+
file_exists = os.path.isfile(csv_file_path)
17+
with open(csv_file_path, "a+", newline="") as file:
18+
writer = csv.writer(file)
19+
# Kopfzeile nur schreiben, wenn die Datei neu ist
20+
if not file_exists or os.stat("logs.csv").st_size == 0:
21+
writer.writerow(["VP", "Page", "Button", "Status", "Timestamp"])
22+
curr_time = time.time()
23+
writer.writerow([vp, page, button, status, curr_time])
24+
25+
26+
def vp_track(page, button, status):
27+
username = request.cookies.get("vp_number")
28+
if username is not None:
29+
write_csv(username, page, button, status)
30+
31+
32+
@app.route("/")
33+
def index():
34+
vp_track("dashboard", "", "")
35+
dashboard = "pages/dashboard.html"
36+
return render_template(dashboard, logging=bool(request.args.get("logging", False)))
37+
38+
39+
@app.route("/imu")
40+
def imu():
41+
vp_track("imu", "", "")
42+
return render_template("pages/imu.html")
43+
44+
45+
@app.route("/vision")
46+
def vision():
47+
vp_track("vision", "", "")
48+
return render_template("pages/vision.html")
49+
50+
51+
@app.route("/motors")
52+
def motors():
53+
vp_track("motors", "", "")
54+
return render_template("pages/motors.html")
55+
56+
57+
@app.route("/behavior")
58+
def behavior():
59+
vp_track("behavior", "", "")
60+
return render_template("pages/behavior.html")
61+
62+
63+
@app.route("/logs")
64+
def logs():
65+
page = request.args.get("page")
66+
button = request.args.get("button")
67+
status = request.args.get("status")
68+
vp_track(page[1:], button, status)
69+
return ("", 204)
70+
71+
72+
def main():
73+
app.run(host="0.0.0.0", port=8000)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<launch>
3+
<include file="$(find-pkg-share rosbridge_server)/launch/rosbridge_websocket_launch.xml">
4+
<arg name="delay_between_messages" value="0.0"/>
5+
</include>
6+
<node pkg="web_video_server" exec="web_video_server" name="web_video_server_education">
7+
<param name="port" value="8081"/>
8+
</node>
9+
<node pkg="bitbots_education" exec="webserver" name="education_webserver" output="screen">
10+
</node>
11+
12+
<executable cmd="ros2 param set bitbots_vision component_debug_image_active true --timeout 20000" name="education_vision_debug_activator" output="screen"/>
13+
</launch>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<launch>
3+
<include file="$(find-pkg-share bitbots_education)/launch/education.launch">
4+
</include>
5+
<include file="$(find-pkg-share bitbots_webots_sim)/launch/simulation.launch">
6+
</include>
7+
<include file="$(find-pkg-share bitbots_bringup)/launch/motion_standalone.launch">
8+
<arg name="sim" value="true"/>
9+
</include>
10+
</launch>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>bitbots_education</name>
5+
<version>0.0.0</version>
6+
<description>A web interface that shows live data in easy to understand visualizations for public events.</description>
7+
<maintainer email="wedmann.lea@gmail.com">root</maintainer>
8+
<license>MIT</license>
9+
10+
<depend>web_video_server</depend>
11+
<depend>rosbridge_suite</depend>
12+
<depend>python3-jinja2</depend>
13+
<depend>python3-flask</depend>
14+
<test_depend>python3-pytest</test_depend>
15+
16+
<export>
17+
<build_type>ament_python</build_type>
18+
</export>
19+
</package>

bitbots_misc/bitbots_education/resource/bitbots_education

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.csv
2+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[develop]
2+
script_dir=$base/lib/bitbots_education
3+
[install]
4+
install_scripts=$base/lib/bitbots_education
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import glob
2+
import os
3+
4+
from setuptools import find_packages, setup
5+
6+
package_name = "bitbots_education"
7+
8+
9+
def generate_data_files(share_path, directory):
10+
data_files = []
11+
12+
for path, _, files in os.walk(directory):
13+
p = share_path + path
14+
list_entry = (p, [os.path.join(path, f) for f in files if not f.startswith(".")])
15+
data_files.append(list_entry)
16+
17+
return data_files
18+
19+
20+
setup(
21+
name=package_name,
22+
data_files=[
23+
("share/ament_index/resource_index/packages", ["resource/" + package_name]),
24+
("share/" + package_name, ["package.xml"]),
25+
("share/" + package_name + "/launch", glob.glob("launch/*.launch")),
26+
]
27+
+ generate_data_files("share/" + package_name + "/", "templates/")
28+
+ generate_data_files("share/" + package_name + "/", "static/"),
29+
version="0.0.0",
30+
packages=find_packages(exclude=["test"]),
31+
install_requires=["setuptools"],
32+
zip_safe=True,
33+
license="MIT",
34+
tests_require=["pytest"],
35+
entry_points={
36+
"console_scripts": [
37+
"webserver = bitbots_education.app:main",
38+
],
39+
},
40+
)

0 commit comments

Comments
 (0)