Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
TedSjoblom committed May 4, 2023
1 parent 53bf7da commit c9871cc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
25 changes: 22 additions & 3 deletions docker-compose.point-rot-nup.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: '3'
services:

point-rotation:
point-rotation-0:
build: .
container_name: cw-point-rot-nup
container_name: cw-point-rot-nup-0
image: cw-point-rot-nup
restart: unless-stopped
network_mode: "host"
environment:
Expand All @@ -15,4 +16,22 @@ services:
- MQTT_TOPIC_IN_HEADING=CROWSNEST/SEAHORSE/GNSS/0/JSON
- MQTT_TOPIC_OUT_RADAR_NORTHUP=CROWSNEST/SEAHORSE/RADAR/0/NUP
- MQTT_TOPIC_OUT_LIDAR_NORTHUP=CROWSNEST/SEAHORSE/LIDAR/0/NUP

- CORR_HEADING=-10

point-rotation-1:
depends_on:
- point-rotation-0
image: cw-point-rot-nup
container_name: cw-point-rot-nup-1
restart: unless-stopped
network_mode: "host"
environment:
- MQTT_CLIENT_ID=platfrom-dev-local
- MQTT_BROKER_HOST=localhost
- MQTT_BROKER_PORT=1883
- MQTT_TOPIC_IN_RADAR_SWEEP=CROWSNEST/SEAHORSE/RADAR/1/SWEEP
- MQTT_TOPIC_IN_LIDAR_SWEEP=CROWSNEST/SEAHORSE/LIDAR/1/POINTCLOUD
- MQTT_TOPIC_IN_HEADING=CROWSNEST/SEAHORSE/GNSS/0/JSON
- MQTT_TOPIC_OUT_RADAR_NORTHUP=CROWSNEST/SEAHORSE/RADAR/1/NUP
- MQTT_TOPIC_OUT_LIDAR_NORTHUP=CROWSNEST/SEAHORSE/LIDAR/1/NUP
- CORR_HEADING=-10
27 changes: 20 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
MQTT_TOPIC_IN_RADAR_SWEEP: str = env("MQTT_TOPIC_IN_RADAR_SWEEP", "CROWSNEST/SEAHORSE/RADAR/0/SWEEP")
MQTT_TOPIC_IN_LIDAR_SWEEP: str = env("MQTT_TOPIC_IN_LIDAR_SWEEP", "CROWSNEST/SEAHORSE/LIDAR/0/POINTCLOUD")
MQTT_TOPIC_IN_HEADING: str = env("MQTT_TOPIC_IN_HEADING", "CROWSNEST/SEAHORSE/GNSS/0/JSON")
CORR_HEADING: int = env("CORR_HEADING", 0)
CORR_HEADING: int = env.int("CORR_HEADING", 0)
MQTT_TOPIC_OUT_RADAR_NORTHUP: str = env("MQTT_TOPIC_OUT_RADAR_NORTHUP", "CROWSNEST/SEAHORSE/RADAR/0/NUP")
MQTT_TOPIC_OUT_LIDAR_NORTHUP: str = env("MQTT_TOPIC_OUT_LIDAR_NORTHUP", "CROWSNEST/SEAHORSE/LIDAR/0/NUP")


# Setup logger
LOG_LEVEL = env.log_level("LOG_LEVEL", logging.WARNING)
LOG_LEVEL = env.log_level("LOG_LEVEL", logging.INFO)
# log_level = env.log_level("LOG_LEVEL")
logging.basicConfig(level=LOG_LEVEL)
logging.captureWarnings(True)
warnings.filterwarnings("once")
Expand Down Expand Up @@ -93,13 +94,19 @@ def on_message(client, userdata, message):
payload = json.loads(msg)
topic = message.topic

LOGGER.info(message.topic)
LOGGER.debug(message.topic)

if "message" in payload:
msg = payload["message"]

if topic == MQTT_TOPIC_IN_HEADING:
corrected_heading = CORR_HEADING + float(msg["heading"])
LOGGER.debug("Heading message: %s", msg["heading"])
LOGGER.debug("Heading tyep: %s", type(msg["heading"]))
LOGGER.debug("Heading CORR: %s", type(CORR_HEADING))
LOGGER.debug("Heading CORR: %s", CORR_HEADING)

heading = float(msg["heading"])
corrected_heading = CORR_HEADING + heading

# Check that heading is within 0-360 after correction
if corrected_heading < 360:
Expand Down Expand Up @@ -184,9 +191,15 @@ def rotate_points_azimuth(input_stream):
source_heading = Stream()

# MQTT publish stream
pipe_heading = source_heading.latest()
# combined = source.latest().zip(pipe_heading)
combined = source.latest().zip_latest(pipe_heading)

# Original with latest() to slow
# pipe_heading = source_heading.latest()
# combined = source.latest().zip_latest(pipe_heading)

# New version with only zip_latest looks to be managing it
pipe_heading = source_heading
combined = source.zip_latest(pipe_heading)

combined.map(rotate_points_azimuth).map(to_brefv_raw).sink(to_mqtt)

LOGGER.info("Connecting to MQTT broker...")
Expand Down

0 comments on commit c9871cc

Please sign in to comment.