Have you ever struggled with coding assignments and thought, “Maybe I’m just not suited to be a programmer”? Well, our team is here to give you some motivation to get through your coding hurdles! Thus, our goal for this project is to prove that if even two cats can code, anyone can!
What it does
cats can code is a real time system that receives inputs from two cats using motion sensors and a wifi module, and generates unique, deterministic and error-free code based on cat movements!
How we built it
cats can code uses an ESP32 as our project's microcontroller and WiFi module, making use of multiple HC-SR04 Ultrasonic Sensors to detect the movement of the cats. The ESP32 connects to an MQTT broker and publishes a message over the sensor topic whenever a cat triggers an ultrasonic sensor by moving near it. Then, these inputs are received and processed by the backend. The Flask backend subscribes to a MQTT topic to receive inputs from the sensors, and continually updates the code based on the received inputs. The frontend calls the API and receives the generated code. The code generation algorithm is deterministic, so the same inputs (sequence of movements) will always generate the same code. The code generated should also be error-free and can be run! This was implemented using data structures such as stacks and directed graphs where each possible state of the code is represented at a node and each input would determine the next edge selected to move to the next state of the code. This ensures that we produce only "compilable" code while allowing for several different possibilities based on different inputs. It also allows the generated code to be deterministic.
Challenges we ran into
- Finding a way to make sure the cats trigger the sensors frequently enough: We decided to solve this by limiting the area of the sensors to a particular room and putting the cats in the room for the demo.
- Integrating all components of the project (the sensors, wifi module, frontend and backend). We had to conduct research to find out what was compatible with what to make sure that all components work together seamlessly. For example, once the MQTT was set up on the ESP32 (Wifi module), we had to find a way to enable the Flask backend to receive messages. Especially because this was our first time using Flask AND MQTT functionality!
- Getting the most important hardware component to cooperate: The cats. This was done through coaxing/baiting them with delicious cat snacks.
- Writing code to generate code was challenging as we wanted to make sure the code generated was error-free! We had to make sure the code (that we wrote) was well designed and could output as many possibilities as possible while remaining correct. We also had to account for things like indentation, variable types, variable names, state, scope, etc.
- As our code was dependent on a current state, we had to ensure that the state was consistent even if the server had multiple parallel instances.
Accomplishments that we're proud of
- Finding free and workable libraries/broker for the project as many were paid
- Overcoming all the challenges we faced above by splitting up the work and then coming together to piece everything together
- Writing a lot of code (for both hardware and software)
- Setting up the sensor system neatly and workably
- Cooperating with cats who just want to nap
What we learned
- Learnt MQTT for the first time and integrating it with ESP32
- Learnt Flask for the first time
- Using data structures & algos IRL
What's next for cats can code
With the success of a prototype of such a small scale. Imagine the possibilities cats can code can achieve. We plan to scale cats can code on a larger level, both by adding more features and improving the usability of our current interface.
- Allow users to cast votes on what themes they would like to see the cats code.
- Instead of using Ultrasonic Sensors, we can use Computer Vision to detect the cats. This will ensure that there will be no external interferences when cats can code is running.
- Use Markov chains to generate code that looks useful instead of using equal weighted probabilities