Wall Following/Mapping

   (Thread # 9000 on this I'm sure, been searching for hours now and I need good leads...

I'm going to make a Room mapping/Wall mapping robot,

and while I can find people doing that with ROS and other overpowered laptop systems,

I was really hoping to be able to store an array of 12" x 12" spaces...
I once had a simulator that did exactly what I needed with very simple code

I don't care about dead reckoning or encoders or algorithms for maze solving,
I just want to be able to say "yes that's kind of what my room looks like" and have it know where the laundry basket is this week

and the question is ?

There's a famous saying. "In theory, theory and practice are the same. In practice, they are not.” Some guy called Albert, apparently.

Better to ask in the Project Guidance Subforum.

1 Like

What distance sensor are you using?

From a fixed position it is fairly easy to draw a map of all of the objects that are line-of-sight from that position. If the robot moves, however, you now have to establish where the robot is on the map in order to extend the map. I suspect the simulation, knowing where the simulated robot was at all times, was able to skip that problem.

I was going to do 3-4 ultrasonics and just walk the wall until I got a complete shape

OK, so you have 3 or 4 distance measurements relative to your current position. What's next? You can either turn or move. What do you do next to 'walk the wall'?

This is not what I made this thread for;

I was hoping to get direction to someone who's already done something similar...

I CAN code this myself through trial and error, I was hoping for guidance...

//Purpose is to place a camera/monitoring system, could also drop a package multiple MIKES would allow sound triangulation, should be able to record sound
//Debug should both send serial? messages, AND play sound, AND flash signal light colors
//IDeally it can play .wav files for ACTUAL sound effects, especially LOUD HUMAN VOICE (to pretend it's a person) fake security guard sounds
//BINAURAL sounds/frequencies that come from everywhere? /users head  or... speaker faces DOWN? even drop a spare speaker to hae 2 points of possible noise
//should stop all motion, and filter out BG sound so it only records or alerts on NEW sound (Also filter patterned sounds, like a machine shops stamping press?
//If noo movement detected, shut down the Trail cam that's it's security camera?  thermal camera? dash cam vs gamecam?

//VARIANT 5/12/2021  THis is going to be a wall following room mapper, storing 1'x1' squares in an array I guess?

#include <Servo.h>          //standard library for the servo
#include <NewPing.h>        //for the Ultrasonic sensor function library.                       
                            //L298N motor control pins                    PWM on 3/5/6/9/10/11
#define ENA 1 
#define ENB 2

 const int knockSensor = A0, threshold = 10; int knockSensorRead = 0; //Knock sensor needs 1M ohm resistor inbetween leads
 int PIRsensor = 13, IRsensor=A4, PIRstate = 0;

const int LeftMotorForward = 5, LeftMotorBackward = 7, RightMotorForward = 6, RightMotorBackward = 3;                   //I think only the forwards REALLY need PWM... the 2 reverse can be fullpower
boolean goesForward = false;                                  //What is this used for???
int distanceFront = 100;
/*2 LED SIN FADE */  int ledpin = 10, ledpin2 = 11, ledSINUS1, ledSINUS2, periode = 3000, displace = 500; long time=0; 
NewPing sonar(A0, A1, 200); Servo servo_motor; //trig,echo,maxdistance  FOR some reason these have to be declared OUTSIDE of setup to be referenced in subroutines

void setup() {
  /*&%$#@&%$#@&%$#@&%$#@&%$#@&%$#@ BASE CODE FROM ALL PROGRAMS STARTUP SOUND/LIGHTS/DEBUG %$#@&%$#@&%$#@&%$#@
PWM on PINS 3/5/6/9/10/11*/

Serial.begin(9600);  Serial.println("BASE ROBOT SKETCH 2020");
 Serial.println("PIEZOSPEAKER/KNOCK SENSOR PIN A0, signalLed PIN 13, SINFADE LEDS 10/11   SERVO RUINS PWM on 9/10  TONE ruins 3/11");

//THEN we're also gonna hookup an ultrasonic, the bump sensor(s) and a PIR motion sensor, headlights, Lasers, PCM decoder/RADIO CONTROL

 digitalWrite(ENA,HIGH); digitalWrite(ENB,HIGH);
  pinMode(RightMotorForward, OUTPUT);pinMode(LeftMotorForward, OUTPUT);pinMode(LeftMotorBackward, OUTPUT);pinMode(RightMotorBackward, OUTPUT);  
 servo_motor.attach(9); servo_motor.write(115);                       //Why 115 not 90?   why ping it several times?
  delay(300);  //WHY?
    distanceFront = readPing(); Serial.println(distanceFront);     Serial.println("DISTANCE 1");delay(100);
    distanceFront = readPing(); Serial.println(distanceFront);     Serial.println("DISTANCE 2");delay(100);
    distanceFront = readPing(); Serial.println(distanceFront);     Serial.println("DISTANCE 3");delay(100);
    distanceFront = readPing(); Serial.println(distanceFront);     Serial.println("DISTANCE 4");delay(100);
    /*FLASH LED 3 seconds*/ pinMode(ledpin2, OUTPUT); int i = 0;    for (i = 0; i < 29; i++) {delay(random(50,200));if (i % 2 == 0 )digitalWrite(ledpin2, HIGH); else digitalWrite(ledpin2, LOW);}

void loop() {
/*VOIDLOOP 2 LED SIN FADE */ time = millis();ledSINUS1 = 128+127*cos(2*PI/periode*time);ledSINUS2 = 128+127*cos(2*PI/periode*(displace-time)); analogWrite(ledpin, ledSINUS1);        analogWrite(ledpin2, ledSINUS2);
  int distanceRight = 0, distanceLeft = 0; distanceFront = 0; //Reset distances

// lookLeft ();   // Looks Left (Which it should already be facing after Lookforwards for wall following purposes
 //lookRight ();
// lookForwards ();    //Ret to LEFT after
//Save Map/grid position as Array? or x4 binary? 

//moveForward();  //MOVE 12" at a time Should be ok to move without looking Right, tunnel is unlikely and we're just expecting to follow a wall until CORNER!

//WHen look forwards, if there's an object(Corner)LOG IT,  turn right, rescan all directions and save a variant of that same corner? needs to change heading datatype (NO LONGER FACING NORTH)

 if (distanceFront <= 20){                //if OBJECT DETECTED
     Serial.println("OBJECT DETECTED IN FRONT (FRONT ONLY?)DISTANCE:");Serial.println(distanceFront);
    delay(300);moveBackward(); delay(400);       //I believe this isn't actually a move backwards, just a "BRAKEing movement"
    distanceRight = lookRight();delay(300);                 //Set distance right to LookRIGHT
    distanceLeft = lookLeft();delay(300);
 if (distanceFront >= distanceLeft){                             //If left is EVEN CLOSER THAN FRONT,(***CORNER***) turn right
      Serial.println("Turn RIGHT");turnRight();moveStop();}
             Serial.println("Turn LEFT"); turnLeft();moveStop();}     //else turn left, because  Front is <20, and Left is <20.... there is no movebackward if ALL distances are <20

    moveForward();                           //Base movement is to continue forwards and scan, until object detected
    distanceFront = readPing();   //This is the deafualt movement and reading

//||||||&&&&&&&&&&&||||END OF LOOP|||&&&&&&&&&&&7|||||||||||||&&&&&&&&&&&&&|||||||||||||||||||||||||||&&&&&&&&&&&&&&&||||||||||||||||||||||&&&&&&&&&&&&7||||||||||||||||||

int lookLeft(){servo_motor.write(170);delay(500);int woohoo = readPing();delay(100);servo_motor.write(115);Serial.println("LEFT DISTANCE:");Serial.println(woohoo);return woohoo;delay(100);   //WHYwthfuck is this delay here? instead of the main code body??? this wont ever get used, it returns BEFORE THIS

int lookRight(){  servo_motor.write(50);            //Look left, ping, return forwards, Int lookRight, returns distance
  delay(500);int fuckshit = readPing();                         //Delay is to stop wiggling
  delay(100);                     //this delay should be pointless
  servo_motor.write(115);Serial.println("RIGHT DISTANCE:");Serial.println(fuckshit);return fuckshit;}

int lookForwards(){}

int readPing(){delay(70); int cm = sonar.ping_cm(); if (cm==0){  cm=250;} return cm;} //if reads 0, read as 250, error will show as super high and continue movement

void moveStop(){ 
                  digitalWrite(RightMotorForward, LOW);digitalWrite(LeftMotorForward, LOW);digitalWrite(RightMotorBackward, LOW);digitalWrite(LeftMotorBackward, LOW);}

void moveForward(){      if(!goesForward){goesForward=true; 
  //if  Motion was STOPPED/object detected, (goesForward starts out false) THEN move forwards.... move backwards also sets it to false
    analogWrite (LeftMotorForward, 220);analogWrite(RightMotorForward, 255);digitalWrite(LeftMotorBackward, LOW);digitalWrite(RightMotorBackward, LOW); }}

void moveBackward(){ goesForward=false;     //why bother with the boolean?
  digitalWrite(LeftMotorBackward, HIGH);digitalWrite(RightMotorBackward, HIGH);digitalWrite(LeftMotorForward, LOW);digitalWrite(RightMotorForward, LOW); }

void turnRight(){
  digitalWrite(LeftMotorForward, HIGH);digitalWrite(RightMotorBackward, HIGH);digitalWrite(LeftMotorBackward, LOW);digitalWrite(RightMotorForward, LOW);
  delay(500);                                  //since these use DELAY, it cannot scan sensors while turning
  digitalWrite(LeftMotorForward, HIGH);digitalWrite(RightMotorForward, HIGH);digitalWrite(LeftMotorBackward, LOW);digitalWrite(RightMotorBackward, LOW);}

void turnLeft(){
  digitalWrite(LeftMotorBackward, HIGH);digitalWrite(RightMotorForward, HIGH);digitalWrite(LeftMotorForward, LOW);digitalWrite(RightMotorBackward, LOW);
digitalWrite(LeftMotorForward, HIGH);digitalWrite(RightMotorForward, HIGH);digitalWrite(LeftMotorBackward, LOW);digitalWrite(RightMotorBackward, LOW);}

Current code for obstacle avoidance,
I'll beef it out and add more ultrasonics to "watch" the wall on the follow side,

Stopping every 12" to get grid/data, may need compass so turns don't screw the "map"

I'm currently planning on saving datapoints as boolean Clear/Blocked in each direction for each square, hoping to get a working version on JUST the arduino without SD card

This 'should' be possible with just ONE ultrasonic and servo; for the most basic kitcar sold everywhere... it's crazy noone has a working version of this readily available,
I don't need a graphical output or realtime map or anything, just a grid of x1200 'arrays?'

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.