The way MINIBOT is currently setup isn't ideal. There are several modes I have it setup to operate in that are sort of clashing with each other.
Currently, the arduino pro mini that reads all the sensors and drives the bot has 3 modes:
- Manual: In this mode the bot will not drive on it's own, it waits for serial data from the ESP32. If data is received it checks for control commands for driving, etc.
- Autonomous: In this mode, the bot will drive around randomly. If it comes close to an obstruction, it will turn until it has a clear path in front and keep driving. After 30 turns it will go into sleep mode.
- Sleeping: The bot goes into deepsleep, wakes every 8 seconds checks for incoming serial data or activity from the motion sensor. If the motion sensor is triggered it goes back into Autonomous mode.
While the Arduino is doing the above, the ESP32 wakes from deepsleep every 5 min. upon waking it sends a command to arduino requesting sensor readings. If the battery voltage from that data is less than 3 volts, or it doesnt receive that data in a set amount of time, it goes back into deepsleep for another 5 min. The ESP32 at this point has 2 modes as well. It saves what mode it is in in the RTC memory so it can remember when it wakes up.
When first powered up, after doing battery check, it initially creates an AP. If no client connects to that AP in a set amount of time, it sets the flag to the second mode, then sleeps. If a client does connect. The bot can be controlled via a web browser, and video stream viewed.
The ESP second mode, upon waking, it asks for battery voltage, then it gets data back and if all is okay there, it connects to the secondary WiFi LAN i setup, takes a photo, and uploads it to the raspberry pi that is connected to that LAN via ethernet cable. I am successfully able to access all these photos from anywhere via tailscale.
After reading all this you may notice where there may be some issues here...
1st, if the Arduino is asleep when the ESP wakes up, it will time out waiting for serial data, just wasting battery.
2nd, the timing has to be just right after turning it on and connecting to AP to enter manual mode. Then once disconnecting, the bot has to be power cycled again to reenter manual mode.
3rd, I am not sure why, but after the bot goes into sleeping mode, it has been having issues after waking up. Or it doesnt want to wake up.
To solve these problems I need to rethink what is controlling what...
I think the best angle to go at this is remove the AP mode. I was going to do that anyway because I want to manually control the bot through the Pi via tailscale. Then I need to rethink how the bot is waking up. I think instead of the ESP32 sleeping for 5 min, having the arduino be the one to wake it will be a better idea. I will need to solder a control wire between the two devices to use as an interrupt on the ESP.
Now the question is how to switch between manual and autonomous mode?
my idea is to have the manual control page be hosted on the Pi. The bot will connect to this page when it wakes, and if a flag is set for manual control, it will start streaming video and accept commands. if that flag isnt set, it will do the photo upload, then go back to sleep like normal. This might sound kind of annoying, because to control the bot, I would access that page, check manual then have to wait until the Arduino wakes the esp. If I still have its sleep time at 5 minutes that would be the annoying part. The longer the wait, the longer battery life the bot will have.
So I definitively have some refactoring to do. This all involves writing code on the Arduino, the Esp32 and the Pi server. All this just in case I want to remotely control the bot...
I could make it a lot easier for myself, just hand control of the esp to arduino for taking and uploading photos and forget about the manual mode... but what's the fun in that lol?
This was a long ramble, but that's where I am at with MINIBOT. Have just been figuring it out as I go so that's why the WiFi connections and serial communication is so convoluted...
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.