Skip to content

python: add the position confidence ellipse for a cam - #575

Closed
tigroo wants to merge 2 commits into
masterfrom
position_ellipse_confidence
Closed

python: add the position confidence ellipse for a cam#575
tigroo wants to merge 2 commits into
masterfrom
position_ellipse_confidence

Conversation

@tigroo

@tigroo tigroo commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Changes

  • IoT3 SDK:
    • mobility: implement the cam version 2.4.0
  • applications:
    • vehicle:add the position confidence ellipse
    • vehicle: use the cam version 2.4.0

Close #573

Close #574

Test

How to test

Note: in the following, lines starting with $ are to be executed on your
machine, as a non-root user;
lines starting with (docker)$ are to be executed in the Docker container;
lines starting with (docker)🐍 $ are to be executed in the Docker container,
in the python venv.

  1. Prepare a test environment:

    1. be sure to have unrestricted access to test.mosquitto.org (IPv4 and IPv6)

    2. be sure to have an MQTT broker that listens locally on port 1883,
      with no credentials and no ACL; if not, run your own:

      $ mosquitto
    3. in another terminal, prepare a collector implementing
      the OpenTelemetry API, on localhost. If you don't have one,
      you may use an existing one, like:

       $ docker container run \
           --rm \
           -p 16686:16686 \
           -p 4318:4318 \
           jaegertracing/all-in-one:1.58
      

      then open a browser on the Jaegger UI
      (or that of your own collector if you have one):

      http://localhost:16686/
      
    4. in another terminal, start a fake gpsd using Docker (gpsfake is not available in Ubuntu packages).
      This docker provides gpsd-compatible JSON on port 2948 with RTK data (major=0.01m, minor=0.008m, orient=30°):

      $ docker run -d --name gpsfake -p 2948:2947 \
          --entrypoint python3 \
          gpsfake -c "
      import socket, json, time, threading
      from datetime import datetime
       
      def create_tpv(lat, lon, alt=61.7, eph=0.5):
      return {'class':'TPV','device':'/dev/ttyUSB0','status':2,'mode':3,
      'time':datetime.utcnow().isoformat()+'Z','lat':lat,'lon':lon,
      'altHAE':alt,'eph':eph,'epv':eph*2,'track':31.66,'speed':0.02}
       
      def create_gst(major=0.01, minor=0.008, orient=30.0):
      return {'class':'GST','device':'/dev/ttyUSB0',
      'time':datetime.utcnow().isoformat()+'Z',
      'major':major,'minor':minor,'orient':orient,'rms':0.01}
       
      def create_att():
      return {'class':'ATT','device':'/dev/ttyUSB0',
      'time':datetime.utcnow().isoformat()+'Z',
      'heading':31.66,'pitch':0,'roll':0,'acc_len':0,'magheading':31.66}
       
      s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
      s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
      s.bind(('0.0.0.0',2947)); s.listen(1)
      while True:
      conn,addr=s.accept()
      threading.Thread(target=lambda c=conn: (
      c.send(b'{\"class\":\"DEVICES\",\"devices\":[]}\n'),
      [c.send((json.dumps(create_tpv(53.3613,6.5056))+'\n').encode()) or
      c.send((json.dumps(create_gst()))+'\n').encode() or
      c.send((json.dumps(create_att()))+'\n').encode() or
      time.sleep(0.1) for _ in range(100)
      ), daemon=True).start()
      "
    5. in another terminal, start a container with Python 3.11
      and the necessary packages.
      The socat command exposes the MQTT broker listening
      on localhost:1883 (see 1.2., above), inside the
      container listening on the UNIX socket /tmp/mqtt.socket:

      $ docker container run \
      --detach \
      --name iot3 \
      --rm \
      -ti \
      --network host \
      -e http_proxy \
      -e https_proxy \
      -e no_proxy \
      --user $(id -u):$(id -u) \
      --mount type=bind,source=$(pwd),destination=$(pwd) \
      --workdir $(pwd) \
      python:3.11.17-slim-trixie \
      /bin/bash -il
      
           $ docker container exec -u 0:0 iot3 apt update
           $ docker container exec -u 0:0 iot3 apt install -y git build-essential curl socat
           $ docker container exec -u 0:0 iot3 install -d -m 0755 /run/zoneinfo
           $ docker container exec -u 0:0 iot3 curl -o /run/zoneinfo/leap-seconds.list 'https://data.iana.org/time-zones/data/leap-seconds.list'
           $ docker container exec -d iot3 socat UNIX-LISTEN:/tmp/mqtt.socket,fork TCP4:localhost:1883
      
           $ docker container attach iot3
    6. prepare a Python 3.11 environment, with tests dependencies
      and packages' dependencies.
      We install the packages dependencies manually,
      and do not rely on pip to do so, because our Python packages depend
      one on the others by git hash, as they are not published on PyPi yet,
      so installing one of our packages may overwrite another:

      (docker)$ python3.11 -m venv /tmp/venv
      (docker)$ . /tmp/venv/bin/activate
      (docker)🐍 $ pip --disable-pip-version-check --no-cache-dir install \
                      -r python/requirements-tests.txt \
                      $(sed -r -e '/.*"(.+(==|>=|<=).+)".*/!d; s//\1/; s/ //g;' \
                        python/*/pyproject.toml
                       )
  2. Build the Python packages:

    (docker)🐍 $ for pkg in python/*/; do
                    python -m build -w "${pkg}" || break
                 done
  3. Install the Python packages:

    (docker)🐍 $ pip --disable-pip-version-check --no-cache-dir \
                        install --no-deps python/*/dist/*.whl
  4. Run the IoT3 Core SDK tests:

    (docker)🐍 ./python/iot3/tests/test-iot3-core
    (docker)🐍 ./python/iot3/tests/test-iot3-core-all
    (docker)🐍 ./python/iot3/tests/test-iot3-core-mqtt
    (docker)🐍 ./python/iot3/tests/test-iot3-core-otel
    (docker)🐍 ./python/iot3/tests/test-iot3-mobility
    (docker)🐍 ./python/iot3/tests/test-iot3-mobility-gnss
    (docker)🐍 ./python/iot3/tests/test-iot3-mobility-message

Expected results

  1. The test environment is ready
  2. The packages were all built successfully
  3. The packages were all installed successfully
  4. The tests all succeed:
    • test-iot3-mobility-message outputs:

      CAM version is 2.4.0...
      CAM with RTK data from fake gpsd (centimeter-level precision)...
        RTK confidence ellipse: semi_major=2cm, semi_minor=1cm, orient=300daG
        RTK altitude confidence: 1
      CAM with nothing available...
      ...
      

@tigroo tigroo self-assigned this Jul 29, 2026
@tigroo tigroo added the Python Python code label Jul 29, 2026
@tigroo tigroo added this to Kanban Jul 29, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Kanban Jul 29, 2026
@tigroo
tigroo force-pushed the position_ellipse_confidence branch from 81086c2 to 8f01c33 Compare July 31, 2026 10:27
tigroo added 2 commits July 31, 2026 12:30
Use the CAM version 2.4.0.

Signed-off-by: Frédéric Gardes <frederic.gardes@orange.com>
Fix the failing denm test on some contexts.

Signed-off-by: Frédéric Gardes <frederic.gardes@orange.com>
@tigroo
tigroo force-pushed the position_ellipse_confidence branch from 8f01c33 to 5ffb869 Compare July 31, 2026 10:30
@tigroo tigroo moved this from Backlog to In progress in Kanban Jul 31, 2026
@tigroo
tigroo requested a review from ymorin-orange July 31, 2026 10:47
@tigroo
tigroo marked this pull request as ready for review July 31, 2026 10:47

@ymorin-orange ymorin-orange left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split the huge commits into separate, atomic, and self-contained changes, each with its own rationale and explanation in the commit log.

"""
tai_time = leapseconds.utc_to_tai(
datetime.datetime.utcfromtimestamp(unix_time)
datetime.datetime.fromtimestamp(unix_time, datetime.timezone.utc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add to the commit log that utcfromtimestamp() is deprecated since python 3.12, and should be replaced by calling fromtimestamp() with UTC as timezone.

@tigroo
tigroo marked this pull request as draft August 4, 2026 08:29
@ymorin-orange

Copy link
Copy Markdown
Member

As discussed IRL, I'll take on me to:

  1. migrate its-vehicle to use the SDK
  2. split the provided code as appropriate

@ymorin-orange

Copy link
Copy Markdown
Member

I suggest we close this MR, after I opened #581. I'll let you do so if you agree.

@tigroo tigroo closed this Aug 10, 2026
@github-project-automation github-project-automation Bot moved this from In progress to Done in Kanban Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Python Python code

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Send Cam position confidence Send Cam 2.4.0

2 participants