# Coding in Sandbox Module

**URL:** <https://forum.theavr.org/t/coding-in-sandbox-module/974>\
**Category:** AVR Drone Software\
**Created:** [October 26, 2024, 1:30pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974 "2024-10-26T13:30:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CoastJRA](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/coastjra/32/352_2.png) [@CoastJRA](https://forum.theavr.org/u/CoastJRA)\
**Post date:** [October 26, 2024, 1:30pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/1 "2024-10-26T13:30:12Z")

</div>

We have been trying to get the RGB lights to flash using the sandbox module autonomously. We have been trying to get the code right for many weeks and haven’t succeeded. Please help. We get this error most of the time “TypeError: lights\_green() takes 1 positional argument but 2 were given”

---

<div class="post-metadata">

**Author:** ![Jurassic\_001](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/jurassic_001/32/458_2.png) [@Jurassic\_001](https://forum.theavr.org/u/Jurassic_001)\
**Post date:** [October 26, 2024, 2:31pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/2 "2024-10-26T14:31:57Z")

</div>

Can I see a picture of your code, and maybe I can identify the issue?

---

<div class="post-metadata">

**Author:** ![CoastJRA](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/coastjra/32/352_2.png) [@CoastJRA](https://forum.theavr.org/u/CoastJRA)\
**Post date:** [October 26, 2024, 2:44pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/3 "2024-10-26T14:44:35Z")

</div>

This is what I have now. I keep changing it to try to get it to work.  
 ![Screenshot 2024-10-26 104256](https://canada1.discourse-cdn.com/flex007/uploads/avr/original/1X/628c2b5445180791f1cd539596700747c940f5c5.png)

---

<div class="post-metadata">

**Author:** ![Jurassic\_001](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/jurassic_001/32/458_2.png) [@Jurassic\_001](https://forum.theavr.org/u/Jurassic_001)\
**Post date:** [October 26, 2024, 3:10pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/4 "2024-10-26T15:10:45Z")

</div>

When you call lights\_green, what does that look like? If you call it with any arguments (i.e. self.lights\_green(some\_variable)), then it would throw the error that you’re reporting

---

<div class="post-metadata">

**Author:** ![CoastJRA](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/coastjra/32/352_2.png) [@CoastJRA](https://forum.theavr.org/u/CoastJRA)\
**Post date:** [October 26, 2024, 3:11pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/5 "2024-10-26T15:11:40Z")

</div>

![Screenshot 2024-10-26 111114](https://canada1.discourse-cdn.com/flex007/uploads/avr/original/1X/f772222c2b8f0d36c4bc9d6608b4d4209f66c084.png)

---

<div class="post-metadata">

**Author:** ![Jurassic\_001](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/jurassic_001/32/458_2.png) [@Jurassic\_001](https://forum.theavr.org/u/Jurassic_001)\
**Post date:** [October 26, 2024, 3:40pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/6 "2024-10-26T15:40:22Z")

</div>

Ahh, when you’re sending a payload over the `autonomous/enable` topic, the payload is being treated as an argument of `lights_green()`. That’s kind of a janky way to set the lights, but my suggestion would be to just add `**kwargs` as an argument to the lights\_green function so it can handle the payload

---

<div class="post-metadata">

**Author:** ![CoastJRA](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/coastjra/32/352_2.png) [@CoastJRA](https://forum.theavr.org/u/CoastJRA)\
**Post date:** [October 27, 2024, 11:16pm UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/7 "2024-10-27T23:16:15Z")

</div>

What would be a better way to set the lights? I am totally new to this type of code.

---

<div class="post-metadata">

**Author:** ![Jurassic\_001](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.theavr.org/jurassic_001/32/458_2.png) [@Jurassic\_001](https://forum.theavr.org/u/Jurassic_001)\
**Post date:** [October 28, 2024, 5:49am UTC](https://forum.theavr.org/t/coding-in-sandbox-module/974/8 "2024-10-28T05:49:36Z")

</div>

For the sake of code understanding and future-proofing I would set up MQTT communication in more of a “topic handler” sense, where you have functions dedicated to handling information that is sent over a specified topic via MQTT. Check out this example:

```python
self.topic_map = {
    'avr/autonomous/enable': self.handle_autonomous,
} # assign topics to specified “handlers”, who will handle the data (referred to as “payload”) which is sent over the topic. Think of the topic as a mailing address and the payload as the letter inside of the envelope

# define your handler for the “avr/autonomous/enabled” topic
def handle_autonomous(self, payload: AvrAutonomousEnablePayload) -> None:
    self.autonomous = payload[“enabled”] # an example of how you could handle the data transmitted over the “avr/autonomous/enable” topic
    if self.autonomous:
    # if you’ve clicked the “enable autonomous” button on the GUI, then set the lights to green
        self.lights_green()
    # you could do other stuff here too, like automatically running an auton movement command or zero-ing the NED position        

```

This code is functionally the same (with the caveat that only _enabling_ autonomous will make the LEDs green), but this opens up opportunities for other actions like I’ve mentioned and is cleaner/less error-prone

I’ve been working with the AVR code for the better part of a year, so I’m happy to answer questions about this type of stuff!
