I currently developing another app that uses streamlit to display data from a VL53L5CX 8x8 TOF sensor. When running in applab hooked up in PC mode (direct connect) Streamlit opens up in the default browser no issue. But if I set the app to "Run at Startup" and apply power it appears that the app starts but the Streamlit browser window never opens up. So on the off chance i had to manually connect I typed in the default web address for streamlit and the browser said address could not connect.
Next step was to try "Run at Startup" with the " UNO Q Pin Toggle" example set to "Run at Startup" and found the following:
- With applab open and run at startup selected browser window did not automatically open, but if I type the address into the browser it will open and connect no issue. Now if I close applab I still can connect, display and change the LEDS.
- Powering off and restarting the Q and waiting for it to finish booting it will still work.
But if I do the same with Streamlit I can not connect.
Any ideas on how to make it work?
For reference here is my current main. Tried it a couple different ways - with user loop, main() etc
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import time
from arduino.app_utils import App, Bridge
import streamlit as st
import config as config
from geometry import (
CoordinateMethod,
compute_zone_angles,
distances_to_points,
)
from planner import PotentialFieldPlanner
print("Hello world!")
# --- Initialize Steering Planner ---
# Configure height bounds based on TOF_BOARD mounting position (in meters)
sensor_height_m = config.TOF_BOARD.world_position[1] # 0.105 m (105 mm)
planner = PotentialFieldPlanner(
safe_distance_m=0.50, # 50 cm
min_height_m=-(sensor_height_m - 0.03), # Cut off floor at ~7.5 cm height
max_height_m=0.20,
k_rep=0.01,
)
st.set_page_config(layout="wide")
st.title("🛰️ UNO Q – Real‑Time 3D Point Cloud Viewer")
# --- Layout ---
col_plot, col_table = st.columns([2, 1])
placeholder_plot = col_plot.empty()
placeholder_table = col_table.empty()
# --- Controls ---
auto_refresh = st.sidebar.checkbox("Auto‑refresh", value=True)
refresh_rate = st.sidebar.slider("Refresh rate (seconds)", 0.05, 1.0, 0.1)
def make_3d_plot(points, steering_cmd=None):
x = points[:, 0] + config.TOF_BOARD.world_position[0]
y = points[:, 1] + config.TOF_BOARD.world_position[1]
z = points[:, 2] + config.TOF_BOARD.world_position[2]
fig = go.Figure()
# Point Cloud
fig.add_trace(
go.Scatter3d(
x=z,
y=x,
z=y,
mode="markers",
marker=dict(size=3, color=x, colorscale="Viridis", opacity=0.8),
name="ToF Cloud",
)
)
# Optional: Plot Steering Vector Line
if steering_cmd and steering_cmd.obstacle_detected:
# Scale vector for visualization length
vec_length = 0.3
rad = np.radians(steering_cmd.steering_angle_deg)
target_x = vec_length * np.sin(rad)
target_z = vec_length * np.cos(rad)
fig.add_trace(
go.Scatter3d(
x=[config.TOF_BOARD.world_position[2], target_z],
y=[config.TOF_BOARD.world_position[0], target_x],
z=[
config.TOF_BOARD.world_position[1],
config.TOF_BOARD.world_position[1],
],
mode="lines+markers",
line=dict(color="red", width=6),
name="Steering Vector",
)
)
fig.update_layout(
height=700,
scene=dict(
xaxis_title="Z Forward (m)",
yaxis_title="X Lateral (m)",
zaxis_title="Y Height (m)",
aspectmode="data",
),
)
return fig
def fetch_range():
"""
Calls UNO Q get_range RPC.
Expected format per line:
A,<angle>,<range>,<quality>,<flag>
"""
try:
ranges = Bridge.call("get_range")
# Ensure everything is a numpy array
ranges = np.array(ranges, dtype=np.int32)
return ranges
except Exception as e:
# print(f"Error fetching LIDAR data: {e}")
return None
#def main():
t = 0
zone_angles = compute_zone_angles()
while(True):
ranges = fetch_range()
if ranges is not None:
if np.any(ranges > 0):
points_local = distances_to_points(
ranges,
zone_angles,
CoordinateMethod.ST_LOOKUP
)
# 2. Compute Steering Vector
cmd = planner.compute_steering(points_local)
# 3. Streamlit UI Indicators
if cmd.obstacle_detected:
st.warning(
f"🚨 Obstacle @ {cmd.min_distance_m*100:.0f} mm | Steer: {cmd.steering_angle_deg:.1f}°"
)
else:
st.success("🟢 Clear Path Ahead")
# 4. Render 3D Plot with Steering Line
fig = make_3d_plot(points_local, cmd)
placeholder_plot.plotly_chart(fig, width="stretch", key=t)
# --- Z‑only table ---
z_values = points_local[:, 2]
# Reshape into 8x8 grid
z_grid = z_values.reshape((8, 8))
# Convert to DataFrame with labeled rows/cols
df_z = pd.DataFrame(
z_grid,
columns=[f"C{c}" for c in range(8)],
index=[f"R{r}" for r in range(8)]
)
# Display in Streamlit
placeholder_table.dataframe(df_z, height=400)
# --- Table ---
#df = pd.DataFrame(points_local, columns=["X", "Y", "Z"])
#placeholder_table.dataframe(df, height=700, key=t)
if not auto_refresh:
break
time.sleep(refresh_rate)
if t>1000000:
t=0
t=t+1
#if __name__ == "__main__":
# main()
App.run()
