From ccd9be7e0bf35f8bd9d36f5c83326c848f36f677 Mon Sep 17 00:00:00 2001
From: rschoene <rene.schoene@tu-dresden.de>
Date: Wed, 18 May 2022 17:51:54 +0200
Subject: [PATCH] WIP: updated protobuf, working on correct robot position
 handling

---
 main.py | 43 +++++++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/main.py b/main.py
index 92152b6..868fd53 100644
--- a/main.py
+++ b/main.py
@@ -24,8 +24,8 @@ fixed_svg_filename = "2022-05-04T10-19-30-9155.svg"
 image_directory = '/data/git/jastadd/ros3rag/ros3rag.placeB/images/'
 static_image_route = '/static/'
 
-MQTT_SERVER = '192.168.0.122'
-# MQTT_SERVER = 'localhost'
+# MQTT_SERVER = '192.168.0.122'
+MQTT_SERVER = 'localhost'
 mqttc = mqtt.Client()
 
 # mqtt client connected?
@@ -51,15 +51,15 @@ commands = {
     'send-place-b-exit': ('place-b/exit', '1'),
     # 'send-place-a-demo-objRed-blue': ('place-a/demo/move/objectRed1/blue', '1'),
     # 'send-place-a-demo-objRed-red': ('place-a/demo/move/objectRed1/red', '1'),
-    # 'send-place-b-demo-objRed-red': ('place-b/demo/move/objectRed1/red', '1'),
+    # 'send-place-b-demo-objRed-red': ('place-b/demo', 'objectRed1/red'),
 
-    'send-place-b-demo-initial_scene': ('demo/initial_scene', '1'),
-    'send-place-b-demo-arm1-active': ('demo/arm1/active', '1'),
-    'send-place-b-demo-arm1-inactive': ('demo/arm1/inactive', '1'),
-    'send-place-b-demo-arm2-active': ('demo/arm2/active', '1'),
-    'send-place-b-demo-arm2-inactive': ('demo/arm2/inactive', '1'),
-    'send-place-b-demo-big-blue-cz': ('demo/big-blue/cz', '1'),
-    'send-place-b-demo-big-blue-g1': ('demo/big-blue/g1', '1'),
+    'send-place-b-demo-initial_scene': ('place-b/demo', 'initial_scene'),
+    'send-place-b-demo-arm1-moving': ('place-b/demo', 'arm1/moving'),
+    'send-place-b-demo-arm1-idle': ('place-b/demo', 'arm1/idle'),
+    'send-place-b-demo-arm2-moving': ('place-b/demo', 'arm2/moving'),
+    'send-place-b-demo-arm2-idle': ('place-b/demo', 'arm2/idle'),
+    'send-place-b-demo-big-blue-cz': ('place-b/demo', 'big-blue/cz'),
+    'send-place-b-demo-big-blue-g1': ('place-b/demo', 'big-blue/g1'),
 
     'send-coordinator-model': ('coordinator/model', '1'),
     'send-coordinator-model-details': ('coordinator/model', 'details'),
@@ -105,6 +105,14 @@ conversion_topics = {
 
 bytes_topics = [
 ]
+topics_enabled_once_seen = [
+  "coordinating/rag-a/status",
+  "coordinating/rag-b/status",
+  "place-b/model/svg/path",
+  "place-b/arm1/position",
+  "place-b/arm2/position"
+]
+
 svg_image_topic = 'place-b/model/svg/path'
 
 button_style_normal = {"marginRight": "15px"}
@@ -200,10 +208,10 @@ app.layout = html.Div([
                     html.Button('Exit', id='send-place-b-exit', style=button_style_exit),
                     # html.Button('obj-Red -> Red', id='send-place-b-demo-objRed-red', style=button_style_normal),
                     html.Button('initial_scene', id='send-place-b-demo-initial_scene', style=button_style_normal),
-                    html.Button('arm1-active', id='send-place-b-demo-arm1-active', style=button_style_normal),
-                    html.Button('arm1-inactive', id='send-place-b-demo-arm1-inactive', style=button_style_normal),
-                    html.Button('arm2-active', id='send-place-b-demo-arm2-active', style=button_style_normal),
-                    html.Button('arm2-inactive', id='send-place-b-demo-arm2-inactive', style=button_style_normal),
+                    html.Button('arm1-moving', id='send-place-b-demo-arm1-moving', style=button_style_normal),
+                    html.Button('arm1-idle', id='send-place-b-demo-arm1-idle', style=button_style_normal),
+                    html.Button('arm2-moving', id='send-place-b-demo-arm2-moving', style=button_style_normal),
+                    html.Button('arm2-idle', id='send-place-b-demo-arm2-idle', style=button_style_normal),
                     html.Button('big-blue-cz', id='send-place-b-demo-big-blue-cz', style=button_style_normal),
                     html.Button('big-blue-g1', id='send-place-b-demo-big-blue-g1', style=button_style_normal),
                 ], className="four columns"),
@@ -381,6 +389,7 @@ def check_connection(_n_intervals):
     Output('mqtt-log', 'value'),
     Output('javascriptLog', 'run'),
     Output('topics-to-filter', 'options'),
+    Output('topics-to-filter', 'value'),
     Output('model-b-svg-img', 'src'),
     Input('every-1-second', 'n_intervals'),
     Input('clear-mqtt-log', 'n_clicks'),
@@ -412,7 +421,7 @@ def append_to_mqtt_log(_n_intervals, clear_n_clicks, filter_options, topics_to_f
 
     trigger_id = ctx.triggered[0]['prop_id'].split('.')[0]
     if trigger_id == 'clear-mqtt-log':
-        return "", "", "", filter_options, new_svg_img_src
+        return "", "", "", filter_options, topics_to_filter, new_svg_img_src
 
     if trigger_id == 'topics-to-filter':
         filtered_value = ""
@@ -445,6 +454,8 @@ def append_to_mqtt_log(_n_intervals, clear_n_clicks, filter_options, topics_to_f
                     filtered_value += msg + "\n"
                 if topic not in (option['label'] for option in filter_options):
                     filter_options.append({'label': topic, 'value': topic})
+                    if topic in topics_enabled_once_seen:
+                        topics_to_filter.append(topic)
         else:
             return dash.no_update
     log_cmd = '''
@@ -453,7 +464,7 @@ def append_to_mqtt_log(_n_intervals, clear_n_clicks, filter_options, topics_to_f
              var textarea = document.getElementById('mqtt-log');
              textarea.scrollTop = textarea.scrollHeight;
              ''' if should_scroll else ""
-    return filtered_value, value, log_cmd, filter_options, new_svg_img_src
+    return filtered_value, value, log_cmd, filter_options, topics_to_filter, new_svg_img_src
 
 
 @app.callback(
-- 
GitLab