diff --git a/_includes/thumbnail.html b/_includes/thumbnail.html index e95b120..56d6a1a 100644 --- a/_includes/thumbnail.html +++ b/_includes/thumbnail.html @@ -1,6 +1,6 @@
- {{include.alt}}
\ No newline at end of file diff --git a/assets/css/index.css b/assets/css/index.css index 432b82b..5639661 100644 --- a/assets/css/index.css +++ b/assets/css/index.css @@ -433,4 +433,16 @@ table { color: #141619; background-color: #d3d3d4; border-color: #bcbebf; +} + +.alert p { + margin-bottom: 0 !important; +} + +.language-plaintext { + border: none !important; + background-color: #ebebeb; + margin: 0; + padding: 2px 6px !important; + border-radius: 4px; } \ No newline at end of file diff --git a/assets/images/java-robot/github-token.png b/assets/images/java-robot/github-token.png new file mode 100644 index 0000000..8b6625e Binary files /dev/null and b/assets/images/java-robot/github-token.png differ diff --git a/assets/images/java-robot/virtual-robot-states.jpg b/assets/images/java-robot/virtual-robot-states.jpg new file mode 100644 index 0000000..c4e24b4 Binary files /dev/null and b/assets/images/java-robot/virtual-robot-states.jpg differ diff --git a/docs/robots/virtual/v1/firmware/0_intro.md b/docs/robots/virtual/v1/firmware/0_intro.md deleted file mode 100644 index a21e9fc..0000000 --- a/docs/robots/virtual/v1/firmware/0_intro.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -layout: default -title: Firmware -parent: Virtual Robots -has_children: true -permalink: robots/virtual/v1/firmware/ - ---- - -## Virtual Robot Firmware - -[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) - ---- - - -Autogenerated Documentation can be found on [https://pera-swarm.ce.pdn.ac.lk/robot-library-java/](https://pera-swarm.ce.pdn.ac.lk/robot-library-java/) diff --git a/docs/robots/virtual/v1/firmware/1_setup-guide.md b/docs/robots/virtual/v1/firmware/1_setup-guide.md deleted file mode 100644 index 7cf69fc..0000000 --- a/docs/robots/virtual/v1/firmware/1_setup-guide.md +++ /dev/null @@ -1,82 +0,0 @@ ---- -layout: default -parent: Firmware -grand_parent: Virtual Robots -title: Setup Guide -nav_order: 1 -permalink: robots/virtual/v1/firmware/setup-guide/ - -gh_link: docs/robots/virtual/v1/firmware/1_setup-guide.md ---- - -# Setup Guide -{: .no_toc } - -##### Table of content -{: .no_toc } -- TOC -{:toc} - ----- -## Getting Started - -### What is Maven ? - -Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. Using maven we can build and manage any Java based project. - -### Why Maven was used ? - -Since this repository is based on OOP concepts and have a few dependencies on ready made libraries, it was required to have a proper project management and dependency management tool. It will help to build the project easily. - - -## Getting started with Java Library - -If you need to update the core functionalities, while the robot implementations, you need to fork and clone the repository, [github.com/Pera-Swarm/robot-library-java](https://github.com/Pera-Swarm/robot-library-java){:target="_blank"} first. Then you need to install the dependencies and compile the project with your changes. - -It is recommended to use a IDE like **Visual Studio Code** / **IntelliJ IDEA**, since it will help you to install dependencies easily. - -- Download the repository from [github.com/Pera-Swarm/robot-library-java](https://github.com/Pera-Swarm/robot-library-java){:target="_blank"} -- Once you download the repository, you need to copy the 'src/resources/config/sample_mqtt.properties' file and create 'src/resources/config/sample_mqtt.properties'. - -- You need to update the following values with the values of the **MQTT Broker** you are using. - -```bash -server=127.0.0.1 -port=1883 -username=user -password=pass -channel=v1 -``` - -- Install Packages and Dependencies using **mvn install** command -- Compile using **mvn compile** command -- You can open the 'src/main/java/swarm/Swarm.java' file and run it using the **Run** or **Debug** option in the IDE to initiate the running of the implementation. - - -Auto-generated full documentation can be found in [http://pera-swarm.ce.pdn.ac.lk/robot-library-java/](http://pera-swarm.ce.pdn.ac.lk/robot-library-java/). - -{% include alert.html message="It is assumed that you already installed *Java JRE* and *Maven Build Tool*." type="alert-primary" type="alert-warning" %} - -## Getting started with pre-build environment - -If you are interested in only the robot functionalities, not the core functionalities, you can start with the *pre-build / pre-compiled* JAR file. - -You need to fork and clone the repository, [github.com/Pera-Swarm/java-robot](https://github.com/Pera-Swarm/java-robot){:target="_blank"} and implement the *Robot Class* as provided examples. - - -{% include alert.html message="Remaining Under Construction" type="alert-primary" %} - - -Additionally, you can import the latest version of the Java Library from Maven Package Regisotry, by adding the below XML code into your pom.xml. Replace the text, **VERSION** with the latest release can be found in [here](https://github.com/Pera-Swarm/robot-library-java/packages/) - -```xml - - pera.swarm - java-robot - {{ VERSION }} - -``` - -## Additional Readings - -- [Maven - Environment Setup](https://www.tutorialspoint.com/maven/maven_environment_setup.htm){:target="_blank"} diff --git a/docs/robots/virtual/v1/firmware/2_swarm-class.md b/docs/robots/virtual/v1/firmware/2_swarm-class.md deleted file mode 100644 index a11faf0..0000000 --- a/docs/robots/virtual/v1/firmware/2_swarm-class.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -layout: default -parent: Firmware -grand_parent: Virtual Robots -title: Swarm Class Overview -nav_order: 3 -permalink: robots/virtual/v1/firmware/swarm-class/ - -gh_link: docs/robots/virtual/v1/firmware/2_swarm-class.md ---- - -# Swarm Class -{: .no_toc } - -{% include alert.html message="Under Construction" type="alert-primary" %} - -##### Table of content -{: .no_toc } -- TOC -{:toc} - ---- - -## Introduction - - -## Create an Experiment diff --git a/docs/robots/virtual/v1/firmware/4_virtual-robot.md b/docs/robots/virtual/v1/firmware/4_virtual-robot.md deleted file mode 100644 index 5dbd596..0000000 --- a/docs/robots/virtual/v1/firmware/4_virtual-robot.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -layout: default -parent: Firmware -grand_parent: Virtual Robots -title: Implement a Virtual Robot -nav_order: 4 -permalink: robots/virtual/v1/firmware/virtual-robot-class/ - -gh_link: docs/robots/virtual/v1/firmware/4_virtual-robot.md ---- - -# Implement a Virtual Robot -{: .no_toc } - -{% include alert.html message="Under Construction" type="alert-primary" %} - -##### Table of content -{: .no_toc } -- TOC -{:toc} - ---- - -## Introduction - - - -## Virtual Robot State Machine - - - -## Virtual Robot Interrupts - - diff --git a/docs/robots/virtual/v1/java/0_intro.md b/docs/robots/virtual/v1/java/0_intro.md new file mode 100644 index 0000000..bdd7c43 --- /dev/null +++ b/docs/robots/virtual/v1/java/0_intro.md @@ -0,0 +1,17 @@ +--- +layout: default +title: Java Robot +parent: Virtual Robots +has_children: true +permalink: robots/virtual/v1/java/ + +--- + +# Virtual Robot - Java Implementation + +[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) [![Java CI with Maven](https://github.com/Pera-Swarm/java-robot/actions/workflows/java-ci.yml/badge.svg)](https://github.com/Pera-Swarm/java-robot/actions/workflows/java-ci.yml) + +--- + + +Autogenerated Documentation can be found on [https://pera-swarm.ce.pdn.ac.lk/robot-library-java/](https://pera-swarm.ce.pdn.ac.lk/robot-library-java/) diff --git a/docs/robots/virtual/v1/java/1_setup-guide.md b/docs/robots/virtual/v1/java/1_setup-guide.md new file mode 100644 index 0000000..726bd63 --- /dev/null +++ b/docs/robots/virtual/v1/java/1_setup-guide.md @@ -0,0 +1,89 @@ +--- +layout: default +parent: Java Robot +grand_parent: Virtual Robots +title: Java Robot +nav_order: 1 +permalink: robots/virtual/v1/java/setup-guide/ + +gh_link: docs/robots/virtual/v1/java/1_setup-guide.md +--- + +# Setup Guide for the Java Robot +{: .no_toc } + +This will guide you to set up the Java Robot implementation of the Pera-Swarm virtual robots, by importing necessary dependencies, doing the configurations, and implementing your own first virtual robot instance. + +##### Table of content +{: .no_toc } +- TOC +{:toc} + +---- + +## Getting started + +If you are interested in only the robot functionalities and applications, not the core functionalities, you can start with the *pre-build* Java Library of the Virtual Robot library, and write your Virtual Robots. + + +## Environment Setup + +- You need to fork and/or clone the repository, [Pera-Swarm/java-robot](https://github.com/Pera-Swarm/java-robot){:target="_blank"}. + +- Create a file named `mqtt.properties` in the path, `./src/resources/config/` as follows, and provide your MQTT broker's configurations. You can select any channel, as same as your simulation server runs on. + +```xml +server=127.0.0.1 +port=1883 +username=user +password=pass +channel="v1" +``` + +- Next, need to obtain a GitHub _Personal Access Token_ with the scope of `read:packages`, by following [this](https://github.com/settings/tokens/new) URL. Create it with a preferable expiration time and a Note. You need to copy this and save it somewhere to be used in the next step. + +{% include thumbnail.html src="/docs/assets/images/java-robot/github-token.png" alt="GitHub token" %} + +- As the next step, create a file named `settings.xml` in the root directory of the repository, by copying `settings.sample.xml`. + +- Update **{GITHUB_USERNAME}** with your GitHub username and **{GITHUB_TOKEN}** with the Personal Access Token you obtained in the previous step. + +```xml + + github + {GITHUB_USERNAME} + {GITHUB_TOKEN} + +``` + +{% include alert.html message="Please note that this **settings.xml** file should not be committed into the git history, since it contains a secret value." type="alert-danger" %} + +- Next, run the following command to run the `mvn install`. It will download the necessary dependencies from _Maven Central Repository_ and _GitHub Package Repository_. + +```bash +mvn -s ./settings.xml -B install --file pom.xml +``` + +### Run using IDE + +- You can open the `src/main/java/swarm/App.java` file and run it using the **Run** or **Debug** option in the IDE to initiate the running of the implementation. + +- If you are using VSCode IDE, you can select the **Run and Debug** tool, and start using 'Run a Swarm'. + +### Run using Command Line + +- Compile the packages and assembly with all the dependencies, using `mvn compile assembly:single` + +```bash +mvn clean compile assembly:single -s settings.xml +``` + +- Run the code implementation using `java -jar [jar_file_path]` + +```bash +java -jar target/java-robot-node-1.0-SNAPSHOT-jar-with-dependencies.jar +``` + +## Additional Readings + +- [Maven - Environment Setup](https://www.tutorialspoint.com/maven/maven_environment_setup.htm){:target="_blank"} diff --git a/docs/robots/virtual/v1/java/2_setup-guide-library.md b/docs/robots/virtual/v1/java/2_setup-guide-library.md new file mode 100644 index 0000000..157c15d --- /dev/null +++ b/docs/robots/virtual/v1/java/2_setup-guide-library.md @@ -0,0 +1,88 @@ +--- +layout: default +parent: Java Robot +grand_parent: Virtual Robots +title: Java Robot Library +nav_order: 2 +permalink: robots/virtual/v1/java/setup-guide-library/ + +gh_link: docs/robots/virtual/v1/java/2_setup-guide-library.md +--- + +# Setup Guide for the Java Robot Library +{: .no_toc } + +The **Java Robot Library** is the core of the Java Robots, which is implemented on Java, based on OOP concepts, and build using the Maven build system. It will be also available through Maven Package Repository maintained by GitHub from [here](https://github.com/Pera-Swarm/robot-library-java/packages). + +This will guide you to setup the core library of the Pera-Swarm virtual robots, by importing the necessary dependencies, and doing the configurations. + +##### Table of content +{: .no_toc } +- TOC +{:toc} + +---- + +## Getting started + +If you need to update the core functionalities, while the robot implementations, you need to fork and clone the repository, [Pera-Swarm/robot-library-java](https://github.com/Pera-Swarm/robot-library-java){:target="_blank"} first. Then you need to install the dependencies and compile the project with your changes, and later work on a release. + +It is recommended to use an IDE like **Visual Studio Code** / **IntelliJ IDEA**, since it will help you to install dependencies easily. + +- Download the repository from [Pera-Swarm/robot-library-java](https://github.com/Pera-Swarm/robot-library-java){:target="_blank"} + +- Once you download the repository, you need to copy the `src/resources/config/sample_mqtt.properties` file and create `src/resources/config/sample_mqtt.properties`. + +- You need to update the following values with the values of the **MQTT Broker** you are using. + +```bash +server=127.0.0.1 +port=1883 +username=user +password=pass +channel=v1 +``` + +- Install Packages and Dependencies using **mvn install** command +- Compile using **mvn compile** command +- You can open the `src/main/java/swarm/App.java` file and run it using the **Run** or **Debug** option in the IDE to initiate the running of the implementation. + + +Auto-generated full documentation of the available _Class_ and _Methods_ can be found at [http://pera-swarm.ce.pdn.ac.lk/robot-library-java/](http://pera-swarm.ce.pdn.ac.lk/robot-library-java/). + +{% include alert.html message="It is assumed that you already installed _Java Runtime Environment_ and _Maven Build Tool_." type="alert-primary" type="alert-warning" %} + +## Publishing a new version + +- You need to update the version of the package in the **./pom.xml** file, with the version you hope to release. + +```xml +pera.swarm +java-robot +1.0.0 +``` + +- Next, you can prepare the release via GitHub from [here](https://github.com/Pera-Swarm/robot-library-java/releases). The release process will be done automatically via [Maven Publish](https://github.com/Pera-Swarm/robot-library-java/blob/main/.github/workflows/maven-publish.yml) GitHub CI Action workflow at a release. + +- Next, you can use the following code block to use the Java Library on your Maven Projects. Replace the <version>1.0.0</version> with the version you want to use. (Please note that to use this Maven library, you need to Authenticate with a GitHub token. Further info is available [here]({{ '/robots/virtual/v1/java/setup-guide/' | relative_url }}).) + +```xml + + pera.swarm + java-robot + 1.0.0 + +``` + + +## Additional Readings + +### What is Maven ? + +Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. Using maven we can build and manage any Java based project. + +### Why Maven was used ? + +Since this repository is based on OOP concepts and have a few dependencies on ready made libraries, it was required to have a proper project management and dependency management tool. It will help to build the project easily. + +- [Maven - Environment Setup](https://www.tutorialspoint.com/maven/maven_environment_setup.htm){:target="_blank"} diff --git a/docs/robots/virtual/v1/java/3_virtual-robot.md b/docs/robots/virtual/v1/java/3_virtual-robot.md new file mode 100644 index 0000000..8b268b7 --- /dev/null +++ b/docs/robots/virtual/v1/java/3_virtual-robot.md @@ -0,0 +1,143 @@ +--- +layout: default +parent: Java Robot +grand_parent: Virtual Robots +title: Implement a Virtual Robot +nav_order: 3 +permalink: robots/virtual/v1/firmware/virtual-robot-class/ + +gh_link: docs/robots/virtual/v1/java/3_virtual-robot.md +--- + +# Implement a Virtual Robot +{: .no_toc } + +##### Table of content +{: .no_toc } +- TOC +{:toc} + +--- + +## Getting started + +You need to fork and/or clone the repository, [Pera-Swarm/java-robot](https://github.com/Pera-Swarm/java-robot){:target="_blank"} into your environment, and setup by following the instructions on [Java Robot]({{ '/robots/virtual/v1/java/setup-guide/' | relative_url }}). + +You can create a new implementation of a Virtual Robot on the directory `src/main/java/Robots`, with the following template. Rename **MyTestRobot** with the name of your Virtual Robot. + +```java +package Robots.samples; + +import swarm.robot.VirtualRobot; + +public class SampleRobot extends VirtualRobot { + + public SampleRobot(int id, double x, double y, double heading) { + super(id, x, y, heading); + } + + public void setup() { + System.out.println("My Test Robot"); + super.setup(); + } + + public void loop() throws Exception { + super.loop(); + + if (state == robotState.RUN) { + System.out.println("Run"); + + } else if (state == robotState.WAIT) { + System.out.println("Waiting"); + + } else if (state == robotState.BEGIN) { + System.out.println("Begin"); + + } + } + + @Override + public void communicationInterrupt(String msg) { + System.out.println("communicationInterrupt on " + id + " with msg:" + msg); + } + +} +``` + +More sample Virtual Robot implementations are available in [/src/main/java/Robots/samples/](https://github.com/Pera-Swarm/java-robot/tree/main/src/main/java/Robots/samples) of the repository + + +## Virtual Robot State Machine + +The virtual robot will change the state of it according to the following **Finite State Machine**. + +{% include thumbnail.html src="/docs/assets/images/java-robot/virtual-robot-states.jpg" alt="Robot State Machine Model of the Robot" %} + + +### Default state changes + +- **setup()**: This is the `public void setup()` method, which will be called once at the beginning of the robot initiation. +- **loop()**: The rest of the states can be programmed within the `public void loop()` method. + - **START** signal will change the state into the `robotState.RUN` + - **STOP** signal will change the state into the `robotState.WAIT` + - **RESET** signal will change the state into the `robotState.BEGIN` + + +Followings are the functions that will do the state changes. For any robot (either Physical or Virtual), the state changes can be done in the algorithm itself, or triggered via the [Sandbox Tool](https://pera-swarm.ce.pdn.ac.lk/sandbox/). + +- **start()** Can be triggered using a `START` signal/message +- **stop()** Can be triggered using a `STOP` signal/message +- **reset()** Can be triggered using a `RESET` signal/message + + +### Communication Interrupt + +Apart from the main 3 states, the Virtual Robots can receive interrupts. For now, there is only one interrupt type, known as `communicationInterrupt` is there. It can be occurred at the end of the loop() iteration cycle. + +This method can be used to handle the incoming messages as _interrupts_ within `public void communicationInterrupt(String msg)`. + +```java +public void communicationInterrupt(String msg) { + System.out.println("communicationInterrupt on " + id + " with msg:" + msg); +} +``` + +### Override state changes + +You can override the state changes by using the following Methods with `@Override` within the Robot Class. + + +```java +@Override +public void start() { + System.out.println("pattern start on " + id); + state = robotState.RUN; +} +``` + +```java +@Override +public void stop() { + System.out.println("pattern stop on " + id); + state = robotState.WAIT; +} +``` + +```java +@Override +public void reset() { + System.out.println("pattern reset on " + id); + state = robotState.BEGIN; +} +``` + +## Run a Virtual Robot + +1. First, you need to start the [Pera-Swarm Mixed Reality Simulator](https://github.com/Pera-Swarm/swarm-simulator) or select a `channel` of a running simulator. +2. Next, you need to configure the `App.java` file in the folder, `/src/main/java/`, by creating one or more Virtual Robot Objects using the Class you implemented, by defining the start coordinates and heading directions of each Virtual Robot object. A detailed guide can be found on [here]({{ '/robots/virtual/v1/java/swarm-class/' | relative_url }}). +3. Running instructions can be found on the [Java Robot]({{'/robots/virtual/v1/java/setup-guide/' | relative_url}}). + + +## Additional Readings + +- Autogenerated Documentation for the Java Robot can be found on [https://pera-swarm.ce.pdn.ac.lk/robot-library-java/](https://pera-swarm.ce.pdn.ac.lk/robot-library-java/) \ No newline at end of file diff --git a/docs/robots/virtual/v1/firmware/3_robot-class.md b/docs/robots/virtual/v1/java/4_robot-class.md similarity index 86% rename from docs/robots/virtual/v1/firmware/3_robot-class.md rename to docs/robots/virtual/v1/java/4_robot-class.md index dd66516..27aca03 100644 --- a/docs/robots/virtual/v1/firmware/3_robot-class.md +++ b/docs/robots/virtual/v1/java/4_robot-class.md @@ -1,17 +1,19 @@ --- layout: default -parent: Firmware +parent: Java Robot grand_parent: Virtual Robots -title: Robot Class Overview -nav_order: 3 +title: Robot Class +nav_order: 4 permalink: robots/virtual/v1/firmware/robot-class/ -gh_link: docs/robots/virtual/v1/firmware/3_robot-class.md +gh_link: docs/robots/virtual/v1/java/3_robot-class.md --- # Robot Class {: .no_toc } +This will guide the basic Methods available for a Java Virtual Robot implementations. + ##### Table of content {: .no_toc } - TOC @@ -65,62 +67,6 @@ Double Example Code - - -{% highlight java %} -package robotImplementations; -import swarm.robot.VirtualRobot; -public class ObstacleAvoidRobot extends VirtualRobot { - - public ObstacleAvoidRobot(int id, double x, double y, double heading) { - super(id, x, y, heading); - } - - public void setup() { - super.setup(); - } - - public void loop() throws Exception { - super.loop(); - - if(state==robotState.RUN) { - double dist = distSensor.getDistance(); - - if (dist < 15) { - - // Generate a random number in [-1000,1000] range - // if even, rotate CW, otherwise rotate CCW an angle depends on the random number - int random = -1000 + ((int) ((Math.random() * 2000))); - int sign = (random % 2 == 0) ? 1 : -1; - - System.out.println("\t Wall detected, go back and rotate " + ((sign > 0) ? "CW" : "CCW")); - - // Go back a little - motion.move(-100, -100, 900); - - // rotate - int loopCount = 0; // to avoid infinity loop - while (distSensor.getDistance() < 35 && loopCount < 5) { - motion.rotate(50 * sign, 1000); - loopCount++; - } - // TODO: This is a temp update to restrict the robot into arena - // if (coordinates.getX() >= 90) coordinates.setX(85); - // if (coordinates.getX() <= -90) coordinates.setX(-85); - // if (coordinates.getY() >= 90) coordinates.setY(85); - // if (coordinates.getY() <= -90) coordinates.setY(-85); - - // rotate a little - motion.rotate(50 * sign, 500); - - } else { - motion.move(100, 100, 1000); - } - } - } -} -{% endhighlight %} - ### ProximitySensor(Robot robot, RobotMqttClient m) diff --git a/docs/robots/virtual/v1/java/5_swarm-class.md b/docs/robots/virtual/v1/java/5_swarm-class.md new file mode 100644 index 0000000..f8bb438 --- /dev/null +++ b/docs/robots/virtual/v1/java/5_swarm-class.md @@ -0,0 +1,114 @@ +--- +layout: default +parent: Java Robot +grand_parent: Virtual Robots +title: Swarm Class +nav_order: 5 +permalink: robots/virtual/v1/java/swarm-class/ + +gh_link: docs/robots/virtual/v1/java/4_swarm-class.md +--- + +# Swarm Class +{: .no_toc } + +This Swarm class is now renamed as `App`, according to the standard naming convention for Java programs. The file can be found on `/src/main/java/App.java`. + +##### Table of content +{: .no_toc } +- TOC +{:toc} + +--- + +## Introduction + +This class is similar to most of the standard Java classes that will be used as an entry point to a program. The structure is as below: + +```java +import swarm.configs.MQTTSettings; +import swarm.robot.VirtualRobot; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +import Robots.samples.SampleRobot; + +public class App { + + public static void main(String[] args) { + + try { + // COMPLETE THIS BEFORE RUN + // Read config properties from the file, src/resources/config/mqtt.properties + // If it isn't there, please make one, as given sample in the + // 'sample_mqtt.properties' file + + File configFile = new File("src/resources/config/mqtt.properties"); + FileReader reader = new FileReader(configFile); + Properties props = new Properties(); + props.load(reader); + + MQTTSettings.server = props.getProperty("server"); + MQTTSettings.port = Integer.parseInt(props.getProperty("port", "1883")); + MQTTSettings.userName = props.getProperty("username"); + MQTTSettings.password = props.getProperty("password"); + MQTTSettings.channel = props.getProperty("channel", "v1"); + reader.close(); + + VirtualRobot robot = new SampleRobot(10, -52, 32, 45); + new Thread(robot).start(); + + } catch (FileNotFoundException ex) { + // file does not exist + System.out.println("File Not Found !!!"); + + } catch (IOException ex) { + // I/O error + System.out.println("IO Error !!!"); + } + } + +} +``` + +### Create an Experiment + +#### With a single robot + +- First, it will try to load the configuration file, and apply the configuration values into the `MQTTSettings` class. These config values will define the MQTT broker need to be used for communicate with the simulator application. + +- You can use a code snippet like following to initiate a single Virtual Robot instance. Insted of `SampleRobot`, you can use your own implementation. + +```java +int id = 0; // an uniquire identifier for each robot +int x = 10; // starting x coordinate +int y = 20; // starting y coordinate +int heading = 45; // heading direction in degrees + +VirtualRobot robot = new SampleRobot(id, x, y, heading); +new Thread(robot).start(); +``` + +#### With a group of robot + +- You can write a code snippet like below for start a group of robots. However, initiating multiple robots can cause to the simulation performance, since robots are working on different threads. + +```java +int[] robotList = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + +int startX = 0; +int startY = 0; +int startHeading = 90; + +Robot[] vr = new VirtualRobot[robotList.length]; + +for (int i = 0; i < robotList.length; i++) { + vr[i] = new SampleRobot(robotList[i], startX + 40 * i, startY + 50 * i, + startHeading + 10 * i); + new Thread(vr[i]).start(); +} +``` \ No newline at end of file