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”
Can I see a picture of your code, and maybe I can identify the issue?
This is what I have now. I keep changing it to try to get it to work.
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
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
What would be a better way to set the lights? I am totally new to this type of code.
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:
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!