How to structure semi-complex application?
Posted: Tue Apr 11, 2017 1:02 pm
Hi,
I'm about to piece together my first big ESP32 program, and need some tips as to how I should architect the program.
During the initial phase where I've built my own ESP32 PCB, I've made standalone ESP32 applications for testing the individual parts of my board. (https://github.com/Scalpel78/Ghost/tree/master/ESP32). Now, most of the parts are working, and it's time to start piecing together this into one large application.
I'm wondering how I should structure the pieces so that they communicate in a stable fashion. Things like, when should I use Tasks, and how much work can I do in an ISR, and how should I store state. Let me explain my project, and perhaps someone has some suggestions as to how I should implement this.
The ESP32 is going to be the controller of an autonomous RC-car. The car has IR sensor (up to 16 of them), it has a Startmodule (another kind of IR sensor that triggers a Start/Stop signal), it has a Servo for steering, and a PWM-controllable motorcontroller. In addition it has an accelerometer, and a compass.
I've built a few of these cars before, but then using Arduino. The main flow of the application goes like this;
- Has the Start signal been detected? If yes, set the Drive-state, and continue.
- Query the IR sensors, and calculate which way to turn and what motor speed to use.
- Turn the wheels.
- Adjust motor speed
And so it loops over and over again.
What would be a good way to accomplish the same with ESP32? Should the IR sensors just spin up a separate task? If so, how should that task send the IR sensor readings to the part that calculates steering/motor speed? Should the calculations also be in a separate Task? And then there is the steering and motor-control. Should those be controlled by two additional tasks that get their values from somewhere?
Any tips are welcomed!
I'm about to piece together my first big ESP32 program, and need some tips as to how I should architect the program.
During the initial phase where I've built my own ESP32 PCB, I've made standalone ESP32 applications for testing the individual parts of my board. (https://github.com/Scalpel78/Ghost/tree/master/ESP32). Now, most of the parts are working, and it's time to start piecing together this into one large application.
I'm wondering how I should structure the pieces so that they communicate in a stable fashion. Things like, when should I use Tasks, and how much work can I do in an ISR, and how should I store state. Let me explain my project, and perhaps someone has some suggestions as to how I should implement this.
The ESP32 is going to be the controller of an autonomous RC-car. The car has IR sensor (up to 16 of them), it has a Startmodule (another kind of IR sensor that triggers a Start/Stop signal), it has a Servo for steering, and a PWM-controllable motorcontroller. In addition it has an accelerometer, and a compass.
I've built a few of these cars before, but then using Arduino. The main flow of the application goes like this;
- Has the Start signal been detected? If yes, set the Drive-state, and continue.
- Query the IR sensors, and calculate which way to turn and what motor speed to use.
- Turn the wheels.
- Adjust motor speed
And so it loops over and over again.
What would be a good way to accomplish the same with ESP32? Should the IR sensors just spin up a separate task? If so, how should that task send the IR sensor readings to the part that calculates steering/motor speed? Should the calculations also be in a separate Task? And then there is the steering and motor-control. Should those be controlled by two additional tasks that get their values from somewhere?
Any tips are welcomed!