Disingenuously Used Some Fuzzy Math for Accessing Fuzzy Math Again a Calculate a
FLDrone with PICK-Upward and DELIVERY ability
PS. You could play with the Chopper and the low-cal-light-green Target-Goal area (meet Image three). The more you reduce the size, the more the chopper has to maneuver:
- either Up or Down till the setting MIN/MAX values for the GOAL (Y axis) are matched
- either Correct or LEFT till the setting MIN/MAX values for the TARGET (X centrality) are matched
- and information technology's quite funny to look the chopper maneuvers into its position.
Instance: FLUAC.java
Java:
individual double ..., MIN = -0.1, MAX = 0.1; // by 0 it could take "hours" to become the positions done Equally I have challenged you to amend the FLUAC to a MULTI-ROLE FLUAC I have hoped that some of you guys have tried...But it seems to me that nobody has dared to do that because the downloading counter for chopper.nix is Null. Well, then I show you. Nosotros can utilise a customized Button, or a ToggleButton or a RadioButton to materialize the two modes PICK-Upwards and Delivery . Permit have the RadioButton for fun. RadioButton and Push share the same base: the ButtonBase . With this sameness nosotros need only slightly modify the method setStyle() equally post-obit and then we tin can
reuse itfor the RadioButton.
Java:
... // RadioButton MODE = new RadioButton("PICK-Upwards"); // create a RadioButton MODE.setSelected(mode); MODE.setOnMouseReleased(eastward -> { if (bussy) return; mode = Fashion.isSelected(); Mode.setText(way?"PICK-Upwards":"Delivery"); // toggle the label reset( ); draw( ); }); // HBox hBox = new HBox(xx); hBox.setAlignment(Pos.CENTER); hBox.getChildren().addAll(Offset, MODE, Domicile); // insert the RadioButton ... // either inline styling or via file css.css if (css == naught || !(new java.io.File(css)).exists()) { setStyle(MODE); // <--prepare Styling setStyle(Habitation); setStyle(START); scene.getRoot().setStyle(vStyle); } else scene.getStylesheets().add together(css); stage.setScene(scene); stage.bear witness(); } ... // for the inline settings //private void setStyle(Push simply) { // commentized this line private void setStyle(ButtonBase but) { but.setStyle(bStyle); merely.styleProperty().demark(Bindings.when(but .hoverProperty()) .then(hover) .otherwise(bStyle)); } After the basic styling work we have to modify three methods:
- fuzzy() - to set the cargo pick-upwards earlier going to deliver to the client (site)
- checkPosition() - do the reverse works of PICK-Upwards
- draw() - arrange to the delivery scene
and Hither is the complete FLDrone.java
Java:
// Java import java.util.ArrayList; // JavaFX import javafx.application.*; import javafx.stage.*; import javafx.scene.*; import javafx.scene.layout.*; import javafx.scene.control.*; import javafx.geometry.*; import javafx.scene.sail.*; import javafx.scene.pigment.Color; import javafx.scene.image.Image; import javafx.beans.binding.Bindings; // FuzzyLogic import fuzzylogic.FuzzyEngine; // // FuzzyLogic Controlled Unmanned Aeriform Chopper // Joe Nartca (C) // public class FLDrone extends Application { public void start(Phase stage) { // check for external script or run the predefined script/FLChopper.txt Application.Parameters params = getParameters(); java.util.List<String> pList = params.getRaw(); // String tmp = cipher; if (pList.size() > 0) tmp = pList.become(0); if (tmp != null) { if (tmp.endsWith(".css")) css = tmp; else script = tmp; } if (pList.size() > 1) { tmp = pList.become(one); if (tmp.endsWith(".css")) css = tmp; else script = tmp; } engine = new FuzzyEngine(this, "FLUAC"); stage.setTitle("FuzzyLogic Controlled Aerial Chopper -JoeNartca (C)-"); scopter = new Image(getClass().getResourceAsStream("scopter.jpg")); Canvas screen = new Sail(580, 500); gc = screen.getGraphicsContext2D(); // set MouseListener screen.setOnMouseReleased(e -> { if (bussy) return; reset(); double X = eastward.getX(), Y = e.getY(); if (X > (cargoX-10) || X < ten || Y < DY || Y > scopterY) { dwelling = -one; depict( ); return; } home = 0; cX = X; cY = Y; if (mode) { loadXY(10, Y); } else { delivery = 0; dX = X; dY = Y; } draw( ); }); // init the scene reset(); draw( ); Showtime = new Button("Offset"); START.setOnAction(a -> { if (mode && betaY == 0) return; ON = !ON; bussy = ON; if (ON) { fuzzy(); START.setText("STOP"); HOME.setDisable(true); } else { START.setText("Kickoff"); HOME.setDisable(false); home = -one; // suspension } }); HOME = new Push button("Abode"); HOME.setOnAction(a -> { reset(); describe( ); }); // RadioButton MODE = new RadioButton("PICK-UP"); Manner.setSelected(mode); // default: Pick-UP MODE.setOnMouseReleased(e -> { if (bussy) return; mode = MODE.isSelected(); MODE.setText(mode?"PICK-UP":"DELIVERY"); reset( ); draw( ); }); // HBox hBox = new HBox(twenty); hBox.setAlignment(Pos.CENTER); hBox.getChildren().addAll(START, Manner, HOME); // VBox root = new VBox(10); root.setAlignment(Pos.CENTER); root.setPadding(new Insets(5,v,5,5)); root.getChildren().addAll(screen, hBox); Scene scene = new Scene(root, 590, 590); // either inline styling or via file css.css if (css == null || !(new java.io.File(css)).exists()) { setStyle(MODE); setStyle(HOME); setStyle(Start); scene.getRoot().setStyle(vStyle); } else scene.getStylesheets().add(css); phase.setScene(scene); stage.bear witness(); } // clean up before terminated public void end() { Platform.exit(); System.go out(0); } // FuzzyEngine Thread private void fuzzy() { if (betaY > 0 || !fashion) (new Thread() { public void run() { speed = 0; bussy = true; if (!fashion) { cX = cargoX; cY = cargoY; Commencement.setDisable(truthful); loadXY(cX, cY); } last double iX = cX, iY = cY; try { engine.execute(script); } take hold of (Exception ex) { ex.printStackTrace(); System.exit(0); } // prevent the "Not on FX application thread" exception Platform.runLater(() -> { if (domicile > 1) { reset(); ON = imitation; Kickoff.setDisable(false); Start.setText("Get-go"); Dwelling.setDisable(faux); } else { // it'southward End habitation = 0; bussy = imitation; sX = scopterX; sY = scopterY; if (!fashion) { delivery = 0; cX = cargoX; cY = cargoY; loadXY(cX, cY); } else loadXY(ix, iY); } }); } }).get-go(); } // private void computeDelta( ) { double x = sX - betaX; double y = sY - betaY; // Y-Axis Velocity if (x == 0) y = speed; else y = speed*Math.sin(Math.atan(y/x)); deltaY += y; sY += y; //X-Axis Velocity if (y == 0) x = speed; else ten = speed*Math.cos(Math.atan(y/x)); deltaX += x; sX += x; draw( ); } // private void checkPosition() throws Exception { if (deltaY > MIN && deltaY < MAX && deltaX > MIN && deltaX < MAX) { if (fashion) { // selection-up cargo if (home > 0) { // maneuver to parking lot cX = sX+DX; cY = sY+DY; START.setDisable(true); coffee.util.concurrent.TimeUnit.MILLISECONDS.sleep(chiliad); loadXY(scopterX+DX, scopterY+DY); ++habitation; } else { // temporarily disable Commencement.setDisable(true); java.util.concurrent.TimeUnit.MILLISECONDS.sleep(1000); loadXY(cargoX, cargoY); // Habitation Coordinates START.setDisable(simulated); // enable the Finish ++home; } } else { // deliver cargo if (home > 0) { ++domicile; cX = sX+DX; cY = sY+DY; Starting time.setDisable(true); loadXY(scopterX+DX, scopterY+DY); } else { // temporarily disable Outset.setDisable(true); java.util.concurrent.TimeUnit.MILLISECONDS.sleep(1000); if (delivery > 0) { // render dwelling loadXY(cargoX, cargoY); ++home; } else { // to client cX = dX; cY = dY; loadXY(cX, cY); } Starting time.setDisable(fake); // enable the STOP ++delivery; } } } coffee.util.concurrent.TimeUnit.MILLISECONDS.slumber(xl); } // private void reset() { dwelling house = 0; speed = 0; cX = cargoX; cY = cargoY; dX = dY = 0; commitment = 0; sX = scopterX; sY = scopterY; bussy = false; } // load relative Scopter to Cargo individual void loadXY(double 10, double Y) { speed = 0; betaY = Y-DY; betaX = Ten-DX; deltaY = sY - betaY; deltaX = sX - betaX; engine.clearEngine(); } // paint the Canvass individual void draw( ) { gc.setFill(Colour.BLACK); gc.fillRect(0,0,580,580); gc.setFill(Color.RED); gc.drawImage(scopter, sX, sY); if (style) { // pick-up mode if (home > one) { // chopper domicile gc.fillOval(cX, cY, xv, 15); } else if (home > 0) { // cargo domicile gc.fillOval(sX+DX, sY+DY, 15, xv); } else { // on fetching cargo if (domicile < 0) { // outbound gc.setStroke(Colour.RED); gc.fillOval(cargoX, cargoY, fifteen, 15); gc.strokeText("Invalid Cargo Location.", 200, 250); } else gc.fillOval(cX, cY, xv, 15); } } else { // delivery mode if (home > 0) { // chopper dwelling house gc.fillOval(dX, dY, 15, 15); } else { // on fetching cargo if (home < 0) { // outbound gc.setStroke(Color.Carmine); gc.fillOval(cargoX, cargoY, 15, 15); gc.strokeText("Invalid Cargo Location.", 200, 250); } else { if (commitment > 0) { gc.fillOval(sX+DX, sY+DY, xv, 15); } else gc.fillOval(cargoX, cargoY, 15, 15); } } if (dX > 0) { gc.setFill(Color.WHITE); gc.fillOval(dX+five, dY+5, five, v); } } gc.setLineWidth(ane); gc.setStroke(Color.Yellowish); gc.strokeText("FuzzyLogic Controlled Aerial Chopper - Joe Nartca (C) -", 124, 15); gc.strokeText(Cord.format("Speed %3.2f, Chopper %three.2f / %3.2f (cargo %3.2f / %iii.2f)", speed, sX, sY, cX, cY), 108, 30); gc.setStroke(Color.CYAN); gc.strokeText(Cord.format("Distance to TARGET and GOAL %3.2f / %iii.2f", deltaX, deltaY),5, 495); } // for the inline settings private void setStyle(ButtonBase but) { but.setStyle(bStyle); but.styleProperty().demark(Bindings.when(but .hoverProperty()) .then(hover) .otherwise(bStyle)); } // private Prototype scopter; private double dX, dY; private Button START, Dwelling house; individual FuzzyEngine engine; individual GraphicsContext gc; private double betaY, betaX, domicile; individual int DX = 23, DY = 35, commitment = 0; individual String script = "script/FLUAC.txt", css; private volatile boolean ON = faux, bussy = false, mode = true; private double cX, cY, sX,sY,deltaX,deltaY,speed,MIN = -0.8d,MAX = 0.8d; private double cargoX = 485, cargoY = 482, scopterX = 516, scopterY = 455; private String hover = "-fx-background-color: #afeeee;"; // paleturquoise private String vStyle = "-fx-background-colour: burlywood;-fx-font-size: 11pt;-fx-base: silver;"; private Cord bStyle = "-fx-groundwork-color:linear-slope(#f0ff35, #a9ff00),"+ " radial-gradient(center 50% -40%, radius 200%, #b8ee36 45%, #80c800 50%);"+ "-fx-groundwork-radius: 6, 5;-fx-groundwork-insets: 0, 1;"+ "-fx-outcome: dropshadow(iii-laissez passer-box ,rgba(0,0,0,0.iv) , 5, 0.0 , 0 , 1);"+ "-fx-text-fill: #395306;"; } Every bit you see, the modification tin can be washed WITHOUT having to bear on the FuzzyLogic algorithm. Information technology's the (virtual) Machine Learning repository and the knowledge is: to bring or to pick upwards a cargo from location A to location B. Again, information technology'southward but the human perception that PICK-Upwards is somehow different to DELIVERY, but in the reality information technology's the same work.
The delivery scene is...
Joe
Source: https://www.congdongjava.com/forum/threads/artificial-intelligence-machine-learning-fuzzy-logic-with-javafx.22782/
0 Response to "Disingenuously Used Some Fuzzy Math for Accessing Fuzzy Math Again a Calculate a"
Post a Comment