Skip to content

Commit

Permalink
Added changes to Homepage & Lane_Detection: It Works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhav-Hariani committed Apr 12, 2024
1 parent 49a334f commit ba26d43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion ros2/UI/ 🚗 Homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def runner():
I'm detailing all immediate tasks here: Please allocate amongst yourselves.
I have taken the liberty of building a bespoke ros2 publisher and subscriber system (was not trivial), that should provide a solid framework.
However, it will get extremely tedious to build a proper UI if you don't exploit some of the advantages of python.
Read about list comprehension and get good.
Read about list comprehension and get good. ''')
st.divider()
st.header("Tasks")
st.markdown( '''
#1: Connecting all datastreams from the lane_detection algorithm into here.
Everything that is cv.imshow() is rendered in that, in a clean and effective manner.
#2: Parametrizing all constants in that: anything that had a slider should be here, and it should be published.
Expand Down
30 changes: 15 additions & 15 deletions ros2/UI/pages/🛣 Lane_Detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,30 @@ def __init__(self):
self._frame_containers = None
super().__init__('Streamlit_Image_Handler')
self._bridge = CvBridge()

self.imgData_subscriber = self.create_subscription(
Image,
'/camera/image',
self.camData_callback,
lambda msg: self.camData_callback(msg,(self._frame_containers[0][0], self._frame_containers[0][1])),
qos_profile_sensor_data)

self.hsvData_subscriber = self.create_subscription(
Image,
'/camera/image_hsv',
self.hsvData_callback,
lambda msg: self.camData_callback(msg,(self._frame_containers[1][0], self._frame_containers[1][1])),
qos_profile_sensor_data)

def tabs(self, tabs):
self._tabs = tabs
# SRC is cv2.VideoCapture FOR NOW: Will need to be tweaked in the future to rossify
self._frame_containers = [tab.empty() for tab in self._tabs]
self._frame_containers = [(tab.empty(),tab.empty()) for tab in self._tabs]

def camData_callback(self, msg_in):
#self._frame_containers[] is a container corresponding to one of the tabs: You can create
def camData_callback(self, msg_in,args):
raw = msg_in
img = self._bridge.imgmsg_to_cv2(raw)
self._frame_containers[0].image(img)
args[0].image(img)
args[1].image(img)

def hsvData_callback(self, msg_in):
raw = msg_in
img = self._bridge.imgmsg_to_cv2(raw)
self._frame_containers[1].image(img)

#This class is your publisher: Flesh it out and integrate accordingly
class Publisher(Node):
Expand Down Expand Up @@ -72,8 +71,8 @@ def demo_publish():
"This should render all of the images related to Lane Detection, and relevant parameters.")
tabs = st.tabs(["Original", "HSV", "Sliding Windows"])


#This hunk initializes the ROS2 nodes without breaking anything :)
#Should not need to be tuoched
if "sub_node" not in st.session_state:
try:
rclpy.init()
Expand All @@ -87,15 +86,16 @@ def demo_publish():
if "pub_node" not in st.session_state:
st.session_state["pub_node"] = Publisher()


st.button("Ros Topic Publisher Demo!",on_click=demo_publish)
# As this is an infinite loop, it should only be run at the end of the file.
#This should also not need to be modified
if render:
while (True):
try:
try:
rclpy.spin_once(st.session_state['sub_node'])
time.sleep(0.01)
except:
st.warning(
"Something went wrong, perhaps tabs were clicked too quickly? Try restarting.")
break
else:
st.button("Ros Topic Publisher Demo!",on_click=demo_publish)

0 comments on commit ba26d43

Please sign in to comment.