Coding
not done
path includes 02 Coding.md
Libs
File Functions Arguments robo.h default_constructor _servo_id
and aAdafruit_PWMServoDriver
robo-movements.h - -
Program Flow
Here is a quick program functional flow , from the microcontroller perspective
- Initializes the wifi
- Initializes the Servo Motors to previous position
- Check if they are in their initial positions ?
- Servo motors does not support checking of angle. So im gonna use a server for that.
graph TB A[Initializes the Wifi] & AA[Initializes the Server Endpoints] --> Main_Thread B[Retrive Data from the Server] --> C C[Servo Object] --> Main_Thread D[API End Points] --> Main_Thread
sequenceDiagram participant PCA9685 participant ESP32 participant Flask API participant SQLite DB %% ESP32 ESP32 -->> ESP32: Initialize -> Boot,WiFi STA .. ESP32->>PCA9685: Initialize I2C (i2c_addr) %% GET Request ESP32->>Flask API: GET /robots?id=$id Flask API->>SQLite DB: Query all robots SQLite DB-->>Flask API: Return robots data Flask API-->>ESP32: JSON response with robots %% POST Request ESP32 ->>Flask API: POST /robots {name, type} Flask API->>SQLite DB: Insert new robot SQLite DB-->>Flask API: Confirm insertion Flask API-->>ESP32: JSON response (201 Created)
There are 3 main Hardware componets that will effect the programming
- PCA9685 -> For Driving the motor
- ESP32 -> Main Controller
- Raspberry Pi -> For hosting the server
PCA9685
This is the PCA9685 driver #sampleCode , here is its order
- Create
driver_object
- param:
i2c_addr
- param:
Adafruit_PWMServoDriver board1 = Adafruit_PWMServoDriver(0x40);
// Adafruit_PWMServoDriver.cpp Adafruit_PWMServoDriver(); Adafruit_PWMServoDriver(const uint8_t addr); Adafruit_PWMServoDriver(const uint8_t addr, TwoWire &i2c);
There are 3 defenitions
Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(const uint8_t addr) : _i2caddr(addr), _i2c(&Wire) {} /*! * @brief Instantiates a new PCA9685 PWM driver chip with the I2C address on a * TwoWire interface * @param addr The 7-bit I2C address to locate this chip, default is 0x40 * @param i2c A reference to a 'TwoWire' object that we'll use to communicate
- Initialize the board
Servo
There is mainly x things
1. Servo Properties
Blank
Blank
Why
We already know to the ideal values of all the features of Servo, but those are ideal values and , we need to find out the actual value of those , for example some servos can't do full 180.
These are the ideal charaterestics
But we have to make sure it our self .
Database
Movements
Software
Going to use platformio for development and cpp as the programming language , vscode as the editor(ide).
Adafruit_PWMServoDriver board1 = Adafruit_PWMServoDriver(CONTROLLER_I2C_ADDR);
Robo la1(PIN_LA1, board1);
Robo la2(PIN_LA2, board1);
Robo la3(PIN_LA3, board1);
Robo ra1(PIN_RA1, board1);
Robo ra2(PIN_RA2, board1);
Robo ra3(PIN_RA3, board1);
Robo lh(PIN_LH, board1);
Robo rh(PIN_RH, board1);
Robo ll1(PIN_LL1, board1);
Robo ll2(PIN_LL2, board1);
Robo ll3(PIN_LL3, board1);
Robo rl1(PIN_RL1, board1);
Robo rl2(PIN_RL2, board1);
Robo rl3(PIN_RL3, board1);
Robo lf(PIN_LF, board1);
Robo rf(PIN_RF, board1);