collapse

Welcome!



Welcome to Robot Rebels, an online robot maker community.

Register today to post your projects, ask questions, share knowledge and meet like-minded people from around the world.


The RobotRebel.org Community

Author Topic: ESP32 - Stepper - LIDAR - Platform  (Read 1409 times)

Gareth

  • Member
  • ****
  • Posts: 38
ESP32 - Stepper - LIDAR - Platform
« on: July 13, 2018, 04:28:46 AM »
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
*rover.png (1186.93 kB . 1032x581 - viewed 179 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
*Gui.png (9.22 kB . 306x452 - viewed 162 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.
« Last Edit: August 29, 2018, 05:50:24 AM by Gareth »

jinx

  • calling from free Europe
  • Sr. Member
  • *****
  • Posts: 444
Re: ESP32 - Stepper - LIDAR - Platform
« Reply #1 on: July 13, 2018, 01:33:15 PM »
keep it coming Gareth. you got a link to the esp32 ( time to dust off the wallet)
I build bots

Gareth

  • Member
  • ****
  • Posts: 38
Re: ESP32 - Stepper - LIDAR - Platform
« Reply #2 on: July 13, 2018, 04:19:01 PM »
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

  • Member
  • *
  • Posts: 43
Re: ESP32 - Stepper - LIDAR - Platform
« Reply #3 on: July 13, 2018, 10:03:12 PM »
Really nice to somebody building something that is not a 3D printer  :) (not that I have anything against 3D printers).

jinx

  • calling from free Europe
  • Sr. Member
  • *****
  • Posts: 444
Re: ESP32 - Stepper - LIDAR - Platform
« Reply #4 on: July 14, 2018, 02:49:04 AM »
Quote
Really nice to somebody building something that is not a 3D printer  :) (not that I have anything against 3D printers).
Am midly offended with that statement >:D..... but I know what you mean, I look forward to seein your next bot. happy building
« Last Edit: July 14, 2018, 03:02:49 AM by jinx »
I build bots

1 what

  • Member
  • *
  • Posts: 43
Re: ESP32 - Stepper - LIDAR - Platform
« Reply #5 on: July 14, 2018, 07:02:46 AM »
Hi Jinx,
Please do not be offended.
There is no doubt that changes in technology drive development and that coding and bots that were once the domain of Nerds and Professionals are now primary school projects and (hopefully) we'll all be better off in the future for this. I have to declare that my original training was in valve technology (yes I'm that old) so I've lived through one or two paradigm changes.
The capacity for 3D printing to realise innovative design realisation by everyday "makers" and for it to facilitate as yet unimagined electro-mechanical creativity is (IMHO) a very exciting unfolding frontier.
As far as my ongoing "building" is concerned.... It's all "on hold" pending change of residence to an apartment. The plan is to join a "Maker" group when we shift in about 6 months and once again I'll have access to a lab and might have enough grey mater left to dream up some devices to amuse myself with the help of even more powerful magnifying glasses.
Happy building.

jinx

  • calling from free Europe
  • Sr. Member
  • *****
  • Posts: 444
Re: ESP32 - Stepper - LIDAR - Platform
« Reply #6 on: July 15, 2018, 04:58:51 AM »
Quote
Please do not be offended.
not at all bud, am just teasing. I do see there seems to be focus on 3DP with RR which is exacerbated  by the 3D junkies amongst us  :-X .  I personally think it about the best machine a hobbyist robot builder can have around, they aint overly noisy, not really messy either and far better than bashing balsa  :o, there still bashing and filing with 3DP... still its a prototyping production machine/tool which seems to get lost in the hype. best of all though, there becoming ever more affordable.

hope the move goes smoothly,  there aint a maker group close by start one! communities/world needs more of them.   
I build bots

Gareth

  • Member
  • ****
  • Posts: 38
Updates 20180728 :- new Steppers - Perfboard Migration - wheel inserts
« Reply #7 on: July 28, 2018, 09:57:11 AM »
Updates 20180728 :- new Steppers - Perfboard Migration - wheel inserts

ZeroMax

  • Badass when not suffering from IBS
  • Member
  • *
  • Posts: 117
  • Do you want ants? Because that's how you get ants.
    • DON'T LOOK AT MY ART!
Re: ESP32 - Stepper - LIDAR - Platform
« Reply #8 on: August 25, 2018, 06:48:32 PM »
Quote
Really nice to somebody building something that is not a 3D printer  :) (not that I have anything against 3D printers).
Am midly offended with that statement >:D..... but I know what you mean, I look forward to seein your next bot. happy building
I teased these botheads about the same thing back before our Canadian conquerers kicked us out of our old sandbox. They don’t mind.  Now If you really want to get them going, just post a long essay about how Makerbot is the ultimate tool, why would anybody make their own, etc...

As always, exemplary work G!
DROP * FROM* WHERE 1=1
SUDO RM /DEV/

 

* Search


* Recent Topics

removable magnetic print surface by jinx
[October 12, 2018, 03:13:37 AM]


QTC - quantum tunneling composite. Can we make our own sensors? by OddBot
[October 10, 2018, 12:47:01 PM]


[ Firmware ] Klipper - the cool firmware for 3d Printers by tinhead
[October 03, 2018, 12:29:14 PM]


Raspberry Pi / Python eBook - free for the next 11 hours! by jinx
[September 27, 2018, 03:18:15 AM]


Gordon McComb Passes by jinx
[September 18, 2018, 02:12:53 AM]


sdsds by jinx
[September 16, 2018, 04:11:16 AM]


1B1 -- RAN Stack by Protowrxs
[September 12, 2018, 05:35:59 PM]


Picture Topic by Underwooz
[September 05, 2018, 12:27:28 AM]


ESP32 - Stepper - LIDAR - Platform by ZeroMax
[August 25, 2018, 06:48:32 PM]


NASA bot by ossipee
[August 05, 2018, 06:52:36 PM]


Android Adware by Pittmanz
[July 24, 2018, 12:40:23 AM]


Greetings! by Pittmanz
[July 24, 2018, 12:39:20 AM]


Sloooow progress on the I3 clone by KingBeetle
[July 16, 2018, 04:20:59 AM]


MKS Gen L 1.0 by jinx
[July 15, 2018, 03:55:57 AM]


Motor rewinding machine by 1 what
[July 10, 2018, 06:03:46 PM]

* Recent Posts

removable magnetic print surface by jinx
[October 12, 2018, 03:13:37 AM]


Re: QTC - quantum tunneling composite. Can we make our own sensors? by OddBot
[October 10, 2018, 12:47:01 PM]


Re: QTC - quantum tunneling composite. Can we make our own sensors? by OddBot
[October 10, 2018, 12:32:20 PM]


Re: QTC - quantum tunneling composite. Can we make our own sensors? by MEgg
[October 08, 2018, 03:53:25 PM]


Re: QTC - quantum tunneling composite. Can we make our own sensors? by OddBot
[October 07, 2018, 04:28:33 AM]


Re: QTC - quantum tunneling composite. Can we make our own sensors? by Bajdi
[October 07, 2018, 04:10:20 AM]


QTC - quantum tunneling composite. Can we make our own sensors? by OddBot
[October 07, 2018, 12:53:49 AM]


Re: [ Firmware ] Klipper - the cool firmware for 3d Printers by tinhead
[October 03, 2018, 12:29:14 PM]


Re: [ Firmware ] Klipper - the cool firmware for 3d Printers by Elloel
[October 03, 2018, 12:15:36 PM]


Re: Raspberry Pi / Python eBook - free for the next 11 hours! by jinx
[September 27, 2018, 03:18:15 AM]


Re: Raspberry Pi / Python eBook - free for the next 11 hours! by MEgg
[September 26, 2018, 04:00:49 PM]


Re: Gordon McComb Passes by jinx
[September 18, 2018, 02:12:53 AM]


Gordon McComb Passes by erco
[September 17, 2018, 10:00:37 PM]


Re: sdsds by jinx
[September 16, 2018, 04:11:16 AM]


sdsds by sdsds
[September 15, 2018, 03:55:20 PM]