Python code does nothing

Hello all. I am using the default sandbox code on the AVR Drone. Below is the file and errors. After running ./start.py run sandbox nothing happens on the Drone.

sandbox.py, but without the comments

from loguru import logger
from bell.avr.mqtt.payloads import AvrFcmVelocityPayload
import random
import time

from bell.avr.mqtt.client import MQTTModule
from bell.avr.mqtt.payloads import AvrPcmSetBaseColorPayload


class Sandbox(MQTTModule):
    def update_led(self) -> None:
        wrgb = tuple(random.randint(0, 255) for _ in range(4))
        self.send_message("avr/pcm/color/set",
                          AvrPcmSetBaseColorPayload(wrgb=wrgb))

    def run(self) -> None:
        super().run_non_blocking()

        while True:
            time.sleep(5)
            self.update_led()


if __name__ == "__main__":
    box = Sandbox()
    box.run()


class Sandbox(MQTTModule):
    def __init__(self) -> None:
        super().__init__()
        self.topic_map = {"avr/fcm/velocity": self.show_velocity}

    def show_velocity(self, payload: AvrFcmVelocityPayload) -> None:
        vx = payload["vX"]
        vy = payload["vY"]
        vz = payload["vZ"]
        v_ms = (vx, vy, vz)
        logger.debug(f"Velocity information: {v_ms} m/s")

    def open_servo(self) -> None:
        self.send_message(
            "avr/pcm/set_servo_open_close",
            {"servo": 0, "action": "open"},
        )


if __name__ == "__main__":
    box = Sandbox()
    box.run()

Console, building and running

avr@drone:~/AVR-2022/VMC$ ./start.py build sandbox
Needing sudo privileges to run docker, re-launching
Running command: docker-compose --project-name avr2022 --file /tmp/docker-compos                                                                                        e-zxw_mwl1.yml build sandbox
/usr/local/lib/python3.6/dist-packages/paramiko/transport.py:33: CryptographyDep                                                                                        recationWarning: Python 3.6 is no longer supported by the Python core team. Ther                                                                                        efore, support for it is deprecated in cryptography and will be removed in a fut                                                                                        ure release.
  from cryptography.hazmat.backends import default_backend
Building sandbox
Sending build context to Docker daemon  15.36kB
Step 1/6 : FROM docker.io/library/python:3.9-buster
 ---> 6d2c69215e52
Step 2/6 : WORKDIR /app
 ---> Using cache
 ---> 5810b2e039f0
Step 3/6 : COPY requirements.txt requirements.txt
 ---> Using cache
 ---> 7123902a229d
Step 4/6 : RUN python -m pip install pip wheel --upgrade &&     python -m pip in                                                                                        stall -r requirements.txt
 ---> Using cache
 ---> a0bc855561c6
Step 5/6 : COPY . .
 ---> c14064f486e3
Step 6/6 : CMD ["python", "sandbox.py"]
 ---> Running in f37eb324a1b8
Removing intermediate container f37eb324a1b8
 ---> 6cee98968ed2
Successfully built 6cee98968ed2
Successfully tagged avr2022_sandbox:latest
avr@drone:~/AVR-2022/VMC$ ./start.py run sandbox
Needing sudo privileges to run docker, re-launching
Running command: docker-compose --project-name avr2022 --file /tmp/docker-compose-ry8txbdh.yml up --remove-orphans --force-recreate sandbox
/usr/local/lib/python3.6/dist-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.hazmat.backends import default_backend
Recreating avr2022_mqtt_1 ... done
Recreating avr2022_sandbox_1 ... done
Attaching to avr2022_sandbox_1
sandbox_1    | 2023-10-28 15:34:06.539 | DEBUG    | bell.avr.mqtt.client:on_connect:292 - Connected with result 0

Has anyone experienced this?

You shouldn’t have two Sandbox classes. Just put your methods in the class they give you, and remove the methods you don’t want, like show_velocity.

1 Like