Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your goal in this exercise is to create a Java application using the jFuzzyLogic library that simulates a robot traversing through a course where the

Your goal in this exercise is to create a Java application using the jFuzzyLogic library that simulates a robot traversing through a course where the walls are randomly generated.

Specifications:

Wall Generation: To generate the walls, an application was written for you called PathGenerator.java. This application can be downloaded from the TA site. The purpose of this application is to create a data file where each line contains a left bound and a right bound in integer form. The left bound is at maximum -100 while the right bound is at maximum 100. This means, at the widest, the walls can be 200 units from each other. On the flip side of that coin, the walls can never be closer than 25 units apart. Download this file, compile it, and generate the random walls. Do not change the source code in this file. Your assignment will be graded by the TA randomly generating a wall scenario and testing your fuzzy controller within this domain.

Fuzzy Controller:

For a robot to sense it's environment, it obviously needs some sort of sensors. In this simulation, the data file created by the PathGenerator.java file will be the readings of these imaginary sensors. Your task is to read a left bound and a right bound, apply it to the fuzzy control logic, return a heading, and have your robot make the appropriate corrections. This will repeat until you complete the course. It is suggested that you use 3000 ticks, and hence, have your PathGenerator.java file create a data file with 3000 data vectors. We will only be concerned about the x coordinate of the robot's position. We can also assume that for each tick, the robot can make the appropriate full corrections in positioning.

On the initial start of the course, you must randomly place your robot in-between the first data vectors bounds. This means if the left bound is -53 and the right bound is 27, your robot should start inbetween -53 and 27. On each tick (read of a left and right bound), your robot will compute from the heading returned how far it must move (either right or left) about the x-axis. This means you will only need to compute the cosine of the heading and add that your current position. One caveat though, in Java, Math.cos() takes a radian value, and if you use degrees for your heading output, you will need to do the appropriate transform before computing your heading adjustment.

Your program named, Robot.java, should output to the terminal via stdout (not stderr) a line like the following per tick:

-54 -40.16 -18

The left value, -54, is the left wall, the center value, -40.16, is the robot's position, and the right value, -18, is the right wall.

PathGenerator.java:

/**

Instructions:

Use this file to generate a data set that randomly creates your

path for the fuzzy controlled robot to follow.

Values will be between -100 and 100

Usage: java PathGenerator

*/

import java.io.*;

import java.util.*;

public class PathGenerator{

final static int SIZE = 200;

final static int SEPERATION = 25;

public static void main(String[] args){

/* Because people do not follow instructions */

if(args.length != 2){

System.err.println("Usage: java PathGenerator ");

System.exit((int)(Math.pow(2, (int)(Math.random()*128))));

}

/* Members */

BufferedWriter out = null;

int leftBound, rightBound, currentPosition;

int numTicks = 0;

Random random;

/* Open and read the user supplied file */

try{ out = new BufferedWriter(new FileWriter(args[0])); }

catch (IOException ioe) {

System.err.println("Cannot open file: " + args[0]);

System.exit((int)(Math.pow(2, (int)(Math.random()*128))));

}

/* Parse the int from args, and jic, catch excpetion */

try{ numTicks = Integer.parseInt(args[1]); }

catch (NumberFormatException nfe) {

System.err.println("This is not an integer: " + args[1]);

System.exit((int)(Math.pow(2, (int)(Math.random()*128))));

}

/* Set up an initial start bound */

random = new Random();

leftBound = random.nextInt(SIZE) - SIZE/2;

leftBound = (leftBound >= SIZE/2 - SEPERATION) ? SIZE/2 - SEPERATION : leftBound;

rightBound = random.nextInt(SIZE) - SIZE/2;

rightBound = (rightBound - SEPERATION <= leftBound) ? leftBound + SEPERATION : rightBound;

/* Now write current tick, then retick, then detick */

for(int i = 0; i < numTicks; i++){

/* Write to file */

try{ out.write(leftBound + " " + rightBound + " "); }

catch (IOException ioe){

System.err.println("Error writing to file");

System.exit((int)(Math.pow(2, (int)(Math.random()*128))));

}

/* Choose a new leftbound */

leftBound = (random.nextInt(SIZE) % 2 == 0) ?

leftBound - (random.nextInt(SIZE) % 4) :

leftBound + (random.nextInt(SIZE) % 4);

/* Choose a new rightbound */

rightBound = (random.nextInt() % 2 == 0) ?

rightBound - (random.nextInt(SIZE) % 4) :

rightBound + (random.nextInt(SIZE) % 4);

/* Restrict those sizes */

leftBound = (leftBound <= -SIZE/2) ? -SIZE/2 : (leftBound + SEPERATION >= rightBound) ? rightBound - SEPERATION : leftBound;

rightBound = (rightBound >= SIZE/2) ? SIZE/2 : (rightBound - SEPERATION <= leftBound) ? leftBound + SEPERATION : rightBound;

}

/* Clean up and exit nicely */

try{ out.close(); }

catch (IOException ioe){

System.err.println("Error closing file");

System.exit((int)(Math.pow(2, (int)(Math.random()*128))));

}

System.exit(0/(int)(Math.pow(2, (int)(Math.random()*128))));

}

}

I don't fully understand jFuzzyLogic if someone could walk me through how to do this.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions