ESP32-CAM based on the map of the exploration trolley project ( open source code )

Time:2024-1-30

        Preface:This article is a handfulESP32-CAM Practical Project——ESP32-CAM Mapping Exploration VehicleThis project only utilizesESP32-CAMat the heart ofMCUThe realization of the trolley projectimage transmissionplanning and controlincorporation. The chassis drive wheels of the graphic transfer trolley use theMcNamee Wheelcollocation4 N20 motorswithTC118SDriver circuitry. The upper computer, on the other hand, utilizesAPP inventor(Wxbit Graphics)Perform the programming to realize that theUDP network protocolThe upper computer commands are sent down to control the movement of the cart. In this paper, we will takeESP32-CAMFor the realization of the core control board asSolution kinematics of the McNamee wheelwithLAN image transferrealization, the project can be developed twice. (Code and information at the end of the article open source!

Experimental hardware:ESP32-CAM; Driver PCB (TC118S); GA12-N20 motor × 4; McNamee wheel × 4; Cart 3D printer

Hardware Physical Drawing:

ESP32-CAM based on the map of the exploration trolley project ( open source code )

ESP32-CAM based on the map of the exploration trolley project ( open source code )

Rendering:

ESP32-CAM based on the map of the exploration trolley project ( open source code )

ESP32-CAM based on the map of the exploration trolley project ( open source code )

I. Introduction and use of ESP32-CAM

        ESP32-CAMisAxiom (brand)Latest release of small sizeCamera Module. The module can work independently as a minimal system with a size of only27*40.5*4.5mmThe deep sleep current is as low as6mA. Compared toK210OpenMVWith a range of MCUs such as the ESP32-CAM, the ESP32-CAM can be considered the mostquality-price ratioThe map transfer module is up.

Due to the excellent performance and price advantage of ESP32-CAM, ESP32-CAM is widely used inVarious IoT occasionsApplicable toHome Smart DevicesIndustrial Wireless Controlwireless monitoringQR wireless identificationWireless Positioning System (WPS) signalsAs well as other IoT applications, it is an ideal solution for IoT applications (all major foreign forums and Github have cool DIY designs by various gods, interested parties to learn more).

Special Notes:

(1)Readers and friends who use normal or first-timeESP32CAM Browsing Webcam Website IPIf the video appears to beLower FPS lagIt is recommended to check if the power supply is reasonable, the ESP32CAM needs at least5V power supply

(2) Amgen OriginalThe ESP32CAM is used with less heat generation.Taobao SellingThe majority of them heat up badly (a common phenomenon) and generally do not affect the use.

ESP32-CAM based on the map of the exploration trolley project ( open source code )

Technical Documentation:ESP32-CAM Camera Development Board | ai-thinker.com

II. McNamee Wheel

2.1 What is the McNamee Wheel

The project’s mapping trolley usesMcNamee WheelAs drive wheels, they allow for higher degrees of freedom of movement than conventional drive wheels. Omni-directional movement is often a necessary function in competition robots and robots for special types of work. “Omni-directional movement” means that the robot can move in any direction within a plane and rotate at the same time. In order to realize omnidirectional movement, robots in general use the“Omni Wheelor“Mecanum Wheel.These two special wheels. One of them, the McNamee wheel is shown in the picture:

ESP32-CAM based on the map of the exploration trolley project ( open source code )

The McNamee Wheel consists of two main parts:wheelandRoller.wheelIt’s the whole wheel.Main BracketrollThen it is mounted on the hubdrum-shaped object. The hub shaft of the McNamee wheel is in line with the roller rotating shaft of the45° Angle. In theory, this angle can be any value, and different wheels can be made based on different angles, but the most commonly used is the45°

The kinematics of the McNamee wheel is analyzed for your convenience. Here put aside the tedious and complicated derivation formula, and directly give you the kinematic decomposition to clarify its ingenious principle. Here we first take a single McNamee wheel as an example, it is known that a single McNamee wheel can be decomposed intoaxis rightandvertical axis forwardof the velocity component, as shown below:

ESP32-CAM based on the map of the exploration trolley project ( open source code )

By analogy, we substitute this for a 4-wheeled cart and show it in the figure below. When all four wheels areturn forwardof the time.AB seriescanMutually offsetting axial velocitiesOnly theForward speedThe chassis isstraight ahead, won’t run out of steam (of course, the advance is the individual wheels of theRPM differenceIt’s not very big, otherwise there’sSlightly offset(Also normal).

ESP32-CAM based on the map of the exploration trolley project ( open source code )

Based on the kinematic specificity of the wheat wheelA1, B1, B2, A2 (1 for the first and 2 for the second)Multi-degree-of-freedom control is possible with proper actuationThe details are as follows (Wheels are mounted the same way as below, O-rectangle (O-rectangle)):

movement direction

A1

B1

B2

A2

Forward FF

moving forward

moving forward

moving forward

moving forward

Backwards BB

backward

backward

backward

backward

left lateral LL

moving forward

backward

backward

moving forward

Right Transverse RR

backward

moving forward

moving forward

backward

Upper left LF

moving forward

cessation

cessation

moving forward

Upper right RF

cessation

moving forward

moving forward

cessation

Lower left LB

cessation

backward

backward

cessation

Lower right RB

backward

cessation

cessation

backward

LL

moving forward

backward

moving forward

backward

Right rr

backward

moving forward

backward

moving forward

2.2 Installation of the McNamee Wheel

McNamee wheels are installed in a certain way due to the uniqueness of their structure. McNamee wheels are generally used in groups of four, two left-handed wheels and two right-handed wheels, with the left-handed wheels and right-handed wheels in chiral symmetry. CommonInstallationThere is:X-squareX-rectangleO-squareO-rectangle. Where X and O denote the shapes formed by the rollers in contact with the ground of the four wheels; square and rectangle refer to the shapes enclosed by the points of contact of the four wheels with the ground.

The wheat wheels of this project’s graphic transfer trolley use theO-rectangleinstallation method, the specific installation is shown in the following figure, reproducing the reader of this project friends can refer to. AdoptingThis mounting methodfor those of you who can just apply theWheat wheel kinematics from the authorsThe code, for a little debugging can be applied to your own project cart.

ESP32-CAM based on the map of the exploration trolley project ( open source code )

Detailed parsing reference:McNamee Wheel (Universal Wheel) Principle of Motion – Xiaopeng STEM (xpstem.com)

Additional additions:Why is the McNamee Wheel so amazingly flexible but not widely available?

(1)、Based on the McNamee Wheel’s need to be inFlat landThe wheel can only be utilized accurately and efficiently, and the control is easily lost if the wheel is hanging in the air;

(2)、The use of McNamee wheels will reduce the efficiency of the car and result in a waste of resources;

(3)、Because of the structural characteristics, it is not conducive to climbing slopes and crossing obstacles, and is more suitable for use on flat ground, which greatly limits the application scenarios;

III. Code and Parsing

3.1 Code base framework

The basic framework of the project can be seen in theSample Tutorials for ArduinoThe subsequent project code can be modified and deleted on this basis. After importing the ESP32 project library correctly, readers should create the basic framework of the project according to the following figure:

ESP32-CAM based on the map of the exploration trolley project ( open source code )

3.2 Core Code and Analysis

3.2.1 Library File Introduction and Variable Definition

#include "esp_camera.h"
#include <WiFi.h>
#include <AsyncUDP.h>
#include<Arduino.h>
#include "camera_pins.h" //camera model pin configuration

#define CAMERA_MODEL_AI_THINKER //Select ESP32CAM from AnTrust.

AsyncUDP udp; //UDP network protocol imported
AsyncUDP Rudp;
const char* ssid = "**********";        //WIFI name
const char* password = "**********";    //WIFI password
char rBuff[18]; //UDP receive buffer
void startCameraServer(); //camera video streaming service function
String inputString;                // String variable

3.2.2 McNamee Wheel Drive Codes

The 4 McNamee wheels of the project trolley are connected using 4 N20 motors, in order to ensure that the deceleration of each motor can be kept as consistent as possible.Motor speed can be adjusted with pwm, to ensure the stability of the wheat wheel trolley. Readers can set it up according to their actual situationpwm valueThe same is true for the drive port pins.

void setpin_pwm(uint8_t Pinport,uint8_t pwmchannel,uint8_t pwmcnt)
{
  ledcAttachPin(Pinport, pwmchannel);   
  ledcSetup(pwmchannel, 1000, 8);
  ledcWrite(pwmchannel, pwmcnt);
}

#define motopwm 110
#define right_back  {ledcDetachPin(15); setpin_pwm(14,1, motopwm); DigitalWrite (15, 0); } //digitalWrite Specifies the high and low level for a pin number
#define right_forward {ledcDetachPin(14);setpin_pwm(15,1,motopwm);digitalWrite(14,0);}
#define right_stop {ledcDetachPin(14);ledcDetachPin(15);digitalWrite(15,0);digitalWrite(14,0);}


#define right2_back  {ledcDetachPin(13);setpin_pwm(12,2,motopwm);digitalWrite(13,0);}
#define right2_forward {ledcDetachPin(12);setpin_pwm(13,2,motopwm);digitalWrite(12,0);}
#define right2_stop {ledcDetachPin(12);ledcDetachPin(13);digitalWrite(13,0);digitalWrite(12,0);}

#define left_back {ledcDetachPin(4);setpin_pwm(2,3,motopwm); digitalWrite(4,0);}
#define left_forward   {ledcDetachPin(2);setpin_pwm(4,3,motopwm); digitalWrite(2,0);}
#define left_stop {ledcDetachPin(4);ledcDetachPin(2);digitalWrite(2,0); digitalWrite(4,0);}

#define left2_forward {ledcDetachPin(33);setpin_pwm(32,4,motopwm); digitalWrite(33,0);}
#define left2_back  {ledcDetachPin(32);setpin_pwm(33,4,motopwm); digitalWrite(32,0);}
#define left2_stop {ledcDetachPin(32);ledcDetachPin(33);digitalWrite(32,0); digitalWrite(33,0);}

3.2.3 Startup Functions

arduino programming programming habits void setup () function as a startup function, similar to the initial init () function. The paragraph function to open the print serial port (baud rate of 115200, convenient and the host computer debugging related information and output IP address), set the camera parameters, set the McNamee wheel pin as the output pin.

Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();

//Camera parameterization
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.frame_size = FRAMESIZE_UXGA;
  config.pixel_format = PIXFORMAT_JPEG; // for streaming purposes
  config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  config.fb_location = CAMERA_FB_IN_PSRAM;
  config.jpeg_quality = 12;
  config.fb_count = 1;

  WiFi.begin(ssid, password); //connect to the hotspot service
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  startCameraServer(); //start camera service

  Serial.print("Camera Ready! Use 'http://");
  Serial.print(WiFi.localIP());
  Serial.println("' to connect");

//McNamee wheel drive pin set to output
  pinMode(4, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(33, OUTPUT);

3.2.4 UDP Network Protocol Control Wheel of Fortune Code

ESP32CAMremoteport 10011.The trolley listens to the 10011 for data transmission via the UDP protocol, and if data exists, it utilizes thePacket Rpacketto save the real-time data sent from the host computer. Put the obtained data into theAccepts the array rBuffIn theif statementMake a judgment that the current desired mode of wheat wheel movement (Exercise in combination with the above table)。

while (!Rudp.listen(10011)) //Wait for the local udp listening port to be set successfully to receive the data sent from the upper end.
{
    Serial.println("waiting");    
}

Rudp.onPacket([](AsyncUDPPacket Rpacket) 
{// Register a packet receive event on port 10011 to receive data asynchronously for receiving data sent from the host computer.

   Serial.println("Camera data ");
   if(LedFlash) //Identify that the program is running normally by LED blinking
   {
    LedFlash = 0;    
   }
   else
   {
    LedFlash=1;
   }
  
    for (int i = 0; i < Rpacket.length(); i++)
    {
      rBuff[i] = (char) * (Rpacket.data() + i);
    }
    inputString = String(rBuff);
    if (inputString.indexOf("are you here") != -1)
    {
         
         if (udp.connect(Rpacket.remoteIP(), 10000)) //check if the network connection exists,it depends on whether the host computer is connected or not,here the condition is that if there is a connection then it will be processed,otherwise go to the next loop.
         {
           udp.print("ok,it is me"); 
           //udp.write(fb->buf, max_packet_byte); //send the image in packets
         }
        
    }
//Use the cached array of values obtained from the commands sent over UDP to select the movement of the Wheel.
    if ((rBuff[0]=='F')&&(rBuff[1]=='F'))// before
    {
       Serial.print("FF/r/n");
       left_forward;
       left2_forward
       right_forward;
       right2_forward;
    }
    if ((rBuff[0]=='R')&&(rBuff[1]=='F'))//right up
    {
       Serial.print("RF/r/n");
       right2_forward;
       left2_stop;
       left_stop;
       right_forward
    }
    if ((rBuff[0]=='L')&&(rBuff[1]=='F'))//top left
    {
       Serial.print("LF/r/n");
       right2_stop;
       left_forward;
       left2_forward;
       right_stop;
    }
    if ((rBuff[0]=='R')&&(rBuff[1]=='B'))//right down
    {
       Serial.print("RB/r/n");
       right_stop;
       left_back;
       left2_back;
       right2_stop;
    }
     if ((rBuff[0]=='L')&&(rBuff[1]=='B'))//Left down
    {
       Serial.print("LB/r/n");
       right_back;
       left2_stop;
       left_stop;
       right2_back
    }
     if ((rBuff[0]=='r')&&(rBuff[1]=='r'))// Turn right
    {
       Serial.print("rr/r/n");
       left_back;
       left2_forward;
       right_forward;
       right2_back       
    }
     if ((rBuff[0]=='l')&&(rBuff[1]=='l'))// Turn left
    {
       Serial.print("ll/r/n");
       left_forward;
       left2_back;
       right_back;
       right2_forward;       
    }
     if ((rBuff[0]=='R')&&(rBuff[1]=='R'))// Horizontal right
    {
       Serial.print("RR/r/n");
       left_back;
       left2_back;
       right_forward;
       right2_forward;

    }
    
    if ((rBuff[0]=='L')&&(rBuff[1]=='L'))// Left horizontal
    {
       Serial.print("LL/r/n");
       left_forward;
       left2_forward;
       right_back;
       right2_back;       
    }
    if ((rBuff[0]=='B')&&(rBuff[1]=='B'))//backward
    {
       Serial.print("BB/r/n");
       left_back;
       right_back;
       left2_back;
       right2_back;
    }
      if ((rBuff[0]=='S')&&(rBuff[1]=='S'))//stops
    {
       Serial.print("SS/r/n");
       left_stop;
       right_stop;
       left2_stop;
       right2_stop;
    }

3.2.5 Loop Master Code

// Prevent reconnecting to the network after an interrupted network connection timeout
void loop() {
  unsigned long currentMillis = millis(); //get the current machine running time
// Timer to check if WIFI is connected, reconnect if not
  if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval)) {
    WiFi.disconnect();
    WiFi.reconnect();
    previousMillis = currentMillis;
  }

}

iv. work of the higher authority

4.1 Introduction to APP Inventor

        App Inventoris a Google-developedMobile Programming SoftwareGoogle App Inventor. Google launched a tool called Google App Inventor software, Google App Inventor users can use the tool to use Google’s Android series of software to develop their own cell phone to use any application.

        App InventorIt is a quick start mobile app programming software based on graphical programming, which is quite easy to get started. With the includedOnline Debugging AssistantIt can easily help developers to realize simple app creation.App InvntorThere are many versions available, and their general interface is as follows:

ESP32-CAM based on the map of the exploration trolley project ( open source code )

Users can select from the leftComponent PanelSelect the component elements you need in the work panel’s cell phone and place them in the appropriate positions(There are many versions of APP Inventor, and the paid version offers a richer set of component elements). Of course, APP Inventor also providesExpansion Pack InterfaceThe user can implement the custom component function by importing the expansion pack.

Recommended APP Inventor Address:

(1) WxBit (Chinese version of APP Inventor, chargeable):WxBit Graphical Programming

(2) APP Inventor2 beta (free):MIT App Inventor

4.2 Upper computer source code and analysis

4.2.1 Selection of host computer components

ESP32-CAM based on the map of the exploration trolley project ( open source code )

(1) Spherical sprite assembly + rocker assembly:Rocker buttons designed to enable control of the McNamee wheel of the cart;

(2) Web browser box component:Display the obtained camera video streams from the ESP32CAM LAN (which can be browsed and read directly);

(3) Refresh the video button assembly:Prevent the video stream from being disconnected due to unstable network connection, use this button to refresh the video stream in the web browsing box again;

(4) Left-hand button + right-hand button assembly:Long press to realize the left and right rotation of the cart’s McNamee wheel;

(5) Timer assembly:It is used to read whether the rocker mechanism is reset to its original position at all times, helping to realize dynamic and continuous control of the trolley;

(6) UDP listening and sending components:Extension packages are required to send down cart control commands from the host computer using the UDP network protocol (UDP listening to video streams can be used with or without similar effect.);

4.2.2 Upper computer logic design

App InventorThe advantage is that you can go directly through the logic design to linkage programming to realize the production of APP, and with its version of the continuous updating, its functions and upper limit is more and more powerful (It’s still a bit limited compared to the regular ones)。

(1) Set global variables and screen initialization settings:Setting the timer to trigger once every 20ms; initial position of the joystick and ball sprite; sending a message to the cart port using the UDP network protocol (test); opening the ESP32CAM’s IP address page in a web browser and reading the video stream;

ESP32-CAM based on the map of the exploration trolley project ( open source code )

(2) Set up the logic for the 3 button components:The Video Refresh button opens the video stream again; the Rotate Left and Rotate Right buttons use the UDP protocol to send specified commands to the host computer (RemoteHost is the IP address of ESP32CAM, RemotePort port number: 10011);The steering flag needs to be set to position 1 when pressed, and set to 0 when released to avoid conflict with the joystick control.

ESP32-CAM based on the map of the exploration trolley project ( open source code )

(3) Logic setting of the rocker unit:Includes displacements after pressing and releasing and rotation angles;

ESP32-CAM based on the map of the exploration trolley project ( open source code )

(4) Logic setup for rocker control of the McNamee wheel:Depends largely onRocker AngleIf you want to stop, you need to see if the steering flag is set to 0;

ESP32-CAM based on the map of the exploration trolley project ( open source code )

4.3 Upper computer effect diagram

ESP32-CAM based on the map of the exploration trolley project ( open source code )

V. Project effects

ESP32CAM Mapping Trolley

VI. Code open source

Code Address: Based on the ESP32CAM map transmission exploration trolley code (including APPInventor production APP upper) – Embedded Documentation Resources – Wenku

If the points are not enough friends, point wave attention, comment area to leave an e-mail, the author gratuitous source code and follow-up questions and answers. Please pay attention to a wave of it!

 

 

 

Recommended Today

DML statements in SQL

preamble Previously we have explained DDL statements in SQL statements. Today we will continue with the DML statement of SQL. DML is the Data Manipulation Language.Used to add, delete, and change data operations on the tables in the library.。 1. Add data to the specified field(INSERT) 2. Modify data(UPDATE) 3. Delete data(DELETE) catalogs preamble I. […]