Robot Projects > Rolling

ESP32 - Stepper - LIDAR - Platform

(1/2) > >>

Gareth:
Thought it may be of interest to document a rover platform using Stepper Motors as drive linked to an ESP32 sporting a Web gui to control movement and display Sensor data.
It will map with LIDAR, the LIDAR will be a home brew system ....still on order....

Its still early stages, however at least the mechanics and Gui are functional.
Basic Platform :-

rover.png (1186.93 kB . 1032x581 - viewed 1226 times)
This consists of a 3D printed chassis (back-end still in blender) holding two stepper motors , you might notice the training wheels (springy 3D coils to keep it upright and allow platform to function in temporary mode).
Its controlled with an ESP32 with A4988 Stepper motor drivers.

#include <WiFi.h>

const char* ssid     = "Robot";
const char* password = "Rebels";
int num=4;
int stepper=15;
int sliderint=0;
int gridx=0; int gridy=0;
int nemaA,nemaB;

WiFiServer server(80);

void setup()
{
    Serial.begin(115200);
 pinMode(16, OUTPUT);      pinMode(17, OUTPUT);      pinMode(18, OUTPUT);    pinMode(19, OUTPUT);   

    // We start by connecting to a WiFi network

    Serial.println();    Serial.print("Connecting to ");    Serial.println(ssid);    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {  delay(100);   Serial.print("."); }

    Serial.println("");    Serial.println("WiFi connected");    Serial.println("IP address: ");    Serial.println(WiFi.localIP());   
    server.begin();
}

void loop(){
  String currentLine = "";   
  String slidera = "blahblahblah";  sliderint=250;  // random string content probably not needed...

 WiFiClient client = server.available();   // listen for incoming clients
 
  if (client) {                             // if you get a client
   // Serial.println("new client");           // print a message out the serial port
               // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        digitalWrite(13, HIGH);
        char c = client.read();             // read a byte, then
       // Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character
          if (currentLine.length() == 0) {
         
            client.println("<!DOCTYPE html>");
            client.print("<html><head><style>div { width: 250px; height: 250px; border: 1px solid black;}</style></head>");         
            client.print("<body><div onmousedown='showCoords(event)' ></div><p id='demo'></p>");
            client.print("<script>function showCoords(event) {");
            client.print("var x = event.clientX;");
            client.print("var y = event.clientY*250;");
            client.print("var coor =  x +  y;");   
client.print("document.getElementById('demo').innerHTML = location.href= coor+'end';}</script> ");
            client.print("</body></html>");
            client.println();
            // break out of the while loop:
            break;
          } else {  currentLine = "";   }
        } else if (c != '\r') { currentLine += c;  }

        }

         if (currentLine.startsWith("GET") && currentLine.endsWith("end")) { slidera[0]=currentLine[5];slidera[1]=currentLine[6];slidera[2]=currentLine[7];slidera[3]=currentLine[8];slidera[4]=currentLine[9];slidera[5]=0;sliderint=slidera.toInt();Serial.print(currentLine );Serial.print(">");Serial.print(sliderint);gridy=sliderint/250;gridx=sliderint-(gridy*250);Serial.print(" x>");Serial.print(gridx);Serial.print(" y>");Serial.println(gridy); ;}
         
    }
 
    }
    // close the connection:
    client.stop();
   
   if (millis()-nemaA >=(250-gridx)/10)    { MOTOR_A()    ; nemaA=millis();     }
   if (millis()-nemaB >=(250-gridy)/10)    { MOTOR_B()    ; nemaB=millis();      }
  }
 
void MOTOR_A()
{  if (gridx>150) {digitalWrite(16, LOW) ;  digitalWrite(19, HIGH); delayMicroseconds(1000);digitalWrite(19,LOW ); delayMicroseconds(1000);  } 
   if (gridx<150) {digitalWrite(16, HIGH);  digitalWrite(19, HIGH); delayMicroseconds(1000);digitalWrite(19,LOW ); delayMicroseconds(1000);  } 
  }
void MOTOR_B()
{  if (gridy>150) {digitalWrite(16, LOW) ;  digitalWrite(18, HIGH); delayMicroseconds(1000);digitalWrite(18,LOW ); delayMicroseconds(1000);  } 
   if (gridy<150) {digitalWrite(16, HIGH);  digitalWrite(18, HIGH); delayMicroseconds(1000);digitalWrite(18,LOW ); delayMicroseconds(1000);  } 
}


The highlighted regions in above code enables the placing and extraction of variables between Web Gui and ESP32 (its the key part to the project, which is the reason for sharing this info to make it simple/easier for other).

The ESP32 spits out a local IP Address .... (in my case 192.168.178.45)
All you need to do then is use a browser window pointed to this address and the Rover can be controlled by clicking the mouse pointer in the box.
The xy coords give direction and speed. works great.

Gui.png (9.22 kB . 306x452 - viewed 1125 times)
The end idea is to display a graphic in the box with more intuitive GUI and use a second box to display the LIDAR data.

Update :- 20180728
New stepper ...... means new wheels because of different 5mm shaft size
.... as this is the 5th stepper motor I have used, each time printing complete new wheels ... had that eureka moment to just make an oversized hole at centre of wheel and make insert adaptors for the various steppershaft diameters ... bingo-bongo print time goes from 1 hours down to 5 mins/wheel.


As breadboard is not the best solution the circuit has been migrated to perf board :-

and wiring loom worked out neater than anticipated :-

UPdate :- 20180829
Introduced an ESP8266 Mesh network into the equation, this transmits sensor data from the Time of Flight Laser distancing module and the Compass module to the basestation rover.

The latest Plan (software Workio) :-

1.ProMini + TOF + Compass +ESP8266 sits on top of the 360° rotating Stepper motor (can be any speed literally (just limited up to the max that the TOF and compass can read data))
2.The ESP8266(AKA flying stepper ESP)  is linked to a second ESP8266 (AKA Basestation ESP) connected to the Rover mainboard (AKA ESP32Stepper)
3. Because of extensive tests I could not link the flying stepper ESP directly to the ESP32Stepper because of time_ing issues (maybe this changes when I have more experience of Mesh networks)
4. The Mesh network forms a kind of Serial Tube where you can pass sensor data in the form of packets between nodes.
5. The cool concept of this approach is that you can add as many extra nodes (ESP8266/ESP32)'s as you wish... ie. you can set up and talk to multiple rovers on the same mesh network, or have all rovers share data to a central control centre.


In the above image you might pick out the two blue LEDS of the ESP8266's (these flash in sync when mesh network is ?Live'
On the Rotating Stepper you see on top of the rover is the LIDAR / Compass module / Batteries (eventually the promini&ESP8266 with snuggle up together in a PLA cage).

The rational/code_ing direction I will attempt to pull off is this :-
1.The spinning LIDAR will take distance measurement.
2.The spinning Compass Module will take a Heading reading at the same time.
3.This means that I can place the distance reading into and array ie. threesixty[Heading]=Distance;
4.Then on a timed payload loop the array is channelled out onto the Mesh network to be picked up by the basestation.
5.Another nice factor is .... the spinning LIDAR unit can spin at any speed it wishes ( as each distance reading is stamped with a compass heading).

Below some of the data stream packets....
I send the data as first byte is the compass direction followed by a block of 32bytes .... 8 times.

jinx:
keep it coming Gareth. you got a link to the esp32 ( time to dust off the wallet)

Gareth:
Here is a a neat video giving in/outs of the latest modules. It really depends on what extra features might be needed.
I normally go for bare-bone systems - though many of my projects use Oled displays which would be a good addition, instead of digging out spec sheets for connection each time.

1 what:
Really nice to somebody building something that is not a 3D printer  :) (not that I have anything against 3D printers).

jinx:

--- Quote ---Really nice to somebody building something that is not a 3D printer  :) (not that I have anything against 3D printers).

--- End quote ---
Am midly offended with that statement >:D..... but I know what you mean, I look forward to seein your next bot. happy building

Navigation

[0] Message Index

[#] Next page

Go to full version