Search algorithm for the pathing: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
Back to: [[PRE2015 2 Groep1]]
Back to: [[PRE2015 2 Groep1]]


In order for the swarm to search an targeted area for objects, an search algorithm is needed. This search algorithm will determine the pathing of the robots, the choices made by the robots will be based on sensory input, primarily from the Ultrasound Sensor. Since the current basic model for the [[NXT robots]] does not have an rotary actuator attached to the Ultrasound Sensor, the robots will only be able to sense a cone infront of them. The current setup for this searching algorithm is given below, where the following basics are set up:
In order for the swarm to search an targeted area for objects, an search algorithm is needed. This search algorithm will determine the pathing of the robots, the choices made by the robots will be based on sensory input, primarily from the Ultrasound Sensor. Since the current basic model for the [[NXT Robots]] does not have an rotary actuator attached to the Ultrasound Sensor, the robots will only be able to sense a cone infront of them. The current setup for this searching algorithm is given below, where the following basics are set up:


* Sensing the distance from object infront of the robot while driving straight. When the distance gets below a certain preset threshold, the robot will enter another state which still needs to be programmed.
* Sensing the distance from object infront of the robot while driving straight. When the distance gets below a certain preset threshold, the robot will enter another state which still needs to be programmed.
Line 7: Line 7:
* Sensing when it it pushing an object, and if needed send out a signal for assistance of the swarm.
* Sensing when it it pushing an object, and if needed send out a signal for assistance of the swarm.


public class HelloWorld {
package com.mydomain;
    /**
    * @param args
import lejos.nxt.Button;
    */
import lejos.nxt.Motor;
public static int  speed = 1000;
import lejos.util.Delay;
public static int state = 1;
import lejos.nxt.SensorPort;
    public static void main(String[] args) {
//import lejos.nxt.TouchSensor;
   
import lejos.nxt.*;
   
    // New local variables for sensor usage
    UltrasonicSensor sonic    =  new UltrasonicSensor(SensorPort.S2);
public class HelloWorld {
    //TouchSensor touchleft      =  new TouchSensor(SensorPort.S1);
    /**
    //TouchSensor touchright    =  new TouchSensor(SensorPort.S4);
      * @param args
   
      */
    // Standard Starting Protocol
public static int  speed = 1000;
        System.out.println("Hello World!");
public static int state = 1;
        Button.waitForAnyPress();
    public static void main(String[] args) {
       
   
       
   
        //Search State
    // New local variables for sensor usage
    for (int t = 0; t < 100000000; t++) {
    UltrasonicSensor sonic    =  new UltrasonicSensor(SensorPort.S2);
        switch ( state ) {
    TouchSensor touchleft      =  new TouchSensor(SensorPort.S1);
       
    TouchSensor touchright    =  new TouchSensor(SensorPort.S4);
        case 1: //searching straight
   
        for (int i = 0; i <2000; i++) {
    // Standard Starting Protocol
       
        System.out.println("Hello World!");
        while (sonic.getDistance() > 40) {
        Button.waitForAnyPress();
       
       
        Motor.A.backward();
       
        Motor.A.setSpeed(speed);
        //Search State
        Motor.C.backward();
      for (int t = 0; t < 100000000; t++) {
        Motor.C.setSpeed(speed);
        switch ( state ) {
        }
       
        }
        case 1: //searching straight
       
        for (int i = 0; i <2000; i++) {
        if (sonic.getDistance() < 40) {
       
        state = 3;  
        while (sonic.getDistance() > 40) {
        }
       
        else {
        Motor.A.backward();
        state = 2;
        Motor.A.setSpeed(speed);
        }
        Motor.C.backward();
       
        Motor.C.setSpeed(speed);
       
        }
        break;
        }
       
       
        case 2: //turning right
        if (sonic.getDistance() < 40) {
        for (int i = 0; i <500; i++) {
        state = 3;  
               
        }
        while (sonic.getDistance() > 40) {
        else {
       
        state = 2;
        Motor.A.backward();
        }
        Motor.A.setSpeed(speed);
       
        Motor.C.forward();
       
        Motor.C.setSpeed(speed);
        break;
        }
       
        }
        case 2: //turning right
       
        for (int i = 0; i <500; i++) {
        if (sonic.getDistance() < 40) {
               
            state = 3;  
        while (sonic.getDistance() > 40) {
            }
       
            else {
        Motor.A.backward();
            state = 1;
        Motor.A.setSpeed(speed);
            }
        Motor.C.forward();
       
        Motor.C.setSpeed(speed);
       
        }
        //Found State
        }
        case 3: // pushing
       
       
        if (sonic.getDistance() < 40) {
        Motor.A.backward();
            state = 3;  
        Motor.A.setSpeed(speed);
            }
        Motor.C.backward();
            else {
        Motor.C.setSpeed(speed);
            state = 1;
        Delay.msDelay(3000);
            }
        t = 100000000;
       
        break;
       
        }
        //Found State
 
        case 3: // pushing
    }
for (int i = 0; i<500; i++) {
}
}
while (touch.getTouchRight() > (threshold touch) and (touch.getTouchLeft() > (threshold touch){
       
        Motor.A.backward();
        Motor.A.setSpeed(speed);
        Motor.C.backward();
        Motor.C.setSpeed(speed);
        Delay.msDelay(3000);
        t = 100000000;
}
}
if (touch.getTouchRight() < (threshold touch) and (touch.getTouchLeft() < (threshold touch){
state = 1;
}
        break;
        }
   
    }
}
}

Latest revision as of 16:42, 21 December 2015

Back to: PRE2015 2 Groep1

In order for the swarm to search an targeted area for objects, an search algorithm is needed. This search algorithm will determine the pathing of the robots, the choices made by the robots will be based on sensory input, primarily from the Ultrasound Sensor. Since the current basic model for the NXT Robots does not have an rotary actuator attached to the Ultrasound Sensor, the robots will only be able to sense a cone infront of them. The current setup for this searching algorithm is given below, where the following basics are set up:

  • Sensing the distance from object infront of the robot while driving straight. When the distance gets below a certain preset threshold, the robot will enter another state which still needs to be programmed.
  • Sensing the distance from object infront of the robot while turning left or right.
  • Sensing when it it pushing an object, and if needed send out a signal for assistance of the swarm.
package com.mydomain;

import lejos.nxt.Button;
import lejos.nxt.Motor;
import lejos.util.Delay;
import lejos.nxt.SensorPort;
//import lejos.nxt.TouchSensor;
import lejos.nxt.*;


public class HelloWorld {
    /**
     * @param args
     */
	public static int  speed = 1000;
	public static int state = 1;
    public static void main(String[] args) {
    	
    	
    	// New local variables for sensor usage
    	UltrasonicSensor sonic     =   new UltrasonicSensor(SensorPort.S2);
    	TouchSensor touchleft      =   new TouchSensor(SensorPort.S1);
    	TouchSensor touchright     =   new TouchSensor(SensorPort.S4);
    	
    	// Standard Starting Protocol
        System.out.println("Hello World!");
        Button.waitForAnyPress();
        
        
        //Search State
     for (int t = 0; t < 100000000; t++) {
        switch ( state ) {
        
        	case 1: //searching straight
        		for (int i = 0; i <2000; i++) {
        
        			while (sonic.getDistance() > 40) {
        			
        				Motor.A.backward();
        				Motor.A.setSpeed(speed);
        				Motor.C.backward();
        				Motor.C.setSpeed(speed);
        			}
        		}
        	
        		if (sonic.getDistance() < 40) {
        			state = 3; 
        		}
        		else {
        			state = 2;
        		}
        		
        	
        break;
        
        	case 2: //turning right
        		for (int i = 0; i <500; i++) {
                
        			while (sonic.getDistance() > 40) {
        		
        				Motor.A.backward();
        				Motor.A.setSpeed(speed);
        				Motor.C.forward();
        				Motor.C.setSpeed(speed);
        			}
        		}
        		
        		if (sonic.getDistance() < 40) {
            		state = 3; 
            	}
            	else {
            		state = 1;
            	}
        	
        
        //Found State
        case 3: // pushing
		for (int i = 0; i<500; i++) {

			while (touch.getTouchRight() > (threshold touch) and (touch.getTouchLeft() > (threshold touch){
        	
        			Motor.A.backward();
        			Motor.A.setSpeed(speed);
        			Motor.C.backward();
        			Motor.C.setSpeed(speed);
        			Delay.msDelay(3000);
	        		t = 100000000;
			}
		}
		if (touch.getTouchRight() < (threshold touch) and (touch.getTouchLeft() < (threshold touch){
		state = 1;
	}
        break;
        }
   
    }
}
}