Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 77 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Enes100ArduinoLibrary

An Arduino library for use in the ENES100 course to allow Arduino boards to communicate with the ENES100 Vision System
via ESP8266 Wi-Fi modules.
via ESP8266 Wi-Fi modules. Also supports usage of Arduino IDE with in-built Wi-Fi modules on the ESP-32 through WebSockets implementation.

## Download and Installation <a name="download"></a>

Expand All @@ -13,14 +13,18 @@ the [Arduino website](https://www.arduino.cc/en/Main/Software).
**If you have an older version of the library on your computer, you _must_ delete it before adding a newer version.**
Failure to do this may cause file conflicts, and it is not guaranteed that the library will work properly.

**If using an in-built Wi-Fi module, you must download:**
ArduinoWebSockets - Gil Maimon,
ArduinoJson - Benoit Blanchon

## Setup<a name="setup"></a>

Communication with the Vision System is done using ESP8266 WiFi-enabled microcontrollers. Wi-Fi modules are available
for
checkout through a Teaching Fellow. The Wi-Fi module has 4 pins:

| Pin | Description | Connect to... |
|-----|-----------------|---------------------|
| --- | --------------- | ------------------- |
| GND | Ground | Common ground |
| VCC | Voltage supply | +5 V |
| TX | Serial transmit | Arduino digital pin |
Expand All @@ -40,6 +44,9 @@ Allowed Pins:

## Usage

**MAKE SURE THE CORRECT .HPP FILE IS INCLUDED IN Enes100.h**
(uncomment either `VisionSystemClient.hpp` for external Wi-Fi module and `WSVisionSystemClient.hpp` for internal Wi-Fi modules)

To use the library, you have to direct the compiler to include it in your code. Go to **Sketch > Include Library >
ENES100**, or add it manually by typing
`#include "Enes100.h"` at the very top of your file.
Expand All @@ -48,20 +55,20 @@ ENES100**, or add it manually by typing

Format:

```Enes100.begin(const char* teamName, byte teamType, int markerId, int wifiModuleTX, int wifiModuleRX)```
`Enes100.begin(const char* teamName, byte teamType, int markerId, int wifiModuleTX, int wifiModuleRX)`

Initializes the ENES100 library and establishes communication with the Vision System.

The `wifiModuleTX` and `wifiModuleRX` described below refer to the digital pins that will be connected to the __Tx__ and
__Rx__ of the
__Wi-Fi module__.
The `wifiModuleTX` and `wifiModuleRX` described below refer to the digital pins that will be connected to the **Tx** and
**Rx** of the
**Wi-Fi module**.

* teamName: Name of the team that will show up in the Vision System
* teamType: Type of mission your team is running.
* Valid Mission Types: `CRASH_SITE`, `DATA`, `MATERIAL`, `FIRE`, `WATER`, `SEED`
* markerID: ID of your Aruco Marker
* wifiModuleTX: Digital Pin that will be connected to the __Tx pin on the Wi-Fi module__.
* wifiModuleRX: Digital Pin that will be connected to the __Rx pin on the Wi-Fi module__.
- teamName: Name of the team that will show up in the Vision System
- teamType: Type of mission your team is running.
- Valid Mission Types: `CRASH_SITE`, `DATA`, `MATERIAL`, `FIRE`, `WATER`, `SEED`
- markerID: ID of your Aruco Marker
- wifiModuleTX: Digital Pin that will be connected to the **Tx pin on the Wi-Fi module**.
- wifiModuleRX: Digital Pin that will be connected to the **Rx pin on the Wi-Fi module**.

Boards have limitations around what pins can be connected to Wi-Fi module TX.
Allowed Pins:
Expand All @@ -75,6 +82,10 @@ Allowed Pins:
- Romeo V1 - Same as Uno
- Romeo V2 - Same as Leonardo



**If using the ESP-32, simply omit the wifiModuleTX and wifiModuleRX parameters.**

#### **NOTE**: Want to call begin multiple times?

There are some of you who will wish to use begin in combination with the isConnected method to 'reconnect' if needed.
Expand All @@ -93,7 +104,7 @@ void setup() {
//Connect digital pin 8 to the Tx pin of the wifi module.
//Connect digital pin 9 to the Rx pin of the wifi module.
Enes100.begin("It's lit", FIRE, 3, 8, 9);

// Some other setup code...
}
```
Expand All @@ -102,17 +113,17 @@ void setup() {

The Aruco Marker has 4 values

* x: x-coordinate of the Aruco Marker (from 0.0 to 4.0)
* y: y-coordinate of the Aruco Marker (From 0.0 to 2.0)
* theta: angle of the Aruco Marker (from -pi radians to pi radians)
* visibility: whether the ArUco marker is visible (true or false)
- x: x-coordinate of the Aruco Marker (from 0.0 to 4.0)
- y: y-coordinate of the Aruco Marker (From 0.0 to 2.0)
- theta: angle of the Aruco Marker (from -pi radians to pi radians)
- visibility: whether the ArUco marker is visible (true or false)

These values can be queried by calling the following functions:

* `Enes100.getX()`
* `Enes100.getY()`
* `Enes100.getTheta()`
* `Enes100.isVisible()`
- `Enes100.getX()`
- `Enes100.getY()`
- `Enes100.getTheta()`
- `Enes100.isVisible()`

Enes100.get variants will make sure you get the latest data available to you about your OTV's location. The first time
getX is
Expand Down Expand Up @@ -149,7 +160,7 @@ Sends a message to the vision system with a new line. Any messages sent after wi
println'

```arduino
//These two lines will output
//These two lines will output
// "Hello World!
// Hello World!"
Enes100.println("Hello World!")
Expand All @@ -163,8 +174,8 @@ for that for specifics on types.

Sends value for a mission objective.

* type: what type of mission call you are sending
* message: mission value associated with the mission type.
- type: what type of mission call you are sending
- message: mission value associated with the mission type.

**NOTE:** Some of the values passed as arguments in the examples below are **C++ preprocessor definitions** (#define),
defined in `Enes100.h`.
Expand All @@ -176,103 +187,104 @@ For the valid mission calls below, the value `i` will denote an integer value.

Valid calls for **CRASH_SITE**:

* `Enes100.mission(LENGTH, i);` *i is in millimeters*
* `Enes100.mission(HEIGHT, i);` *i is in millimeters*
* `Enes100.mission(DIRECTION, NORMAL_X);` *the normal of the exposed panels points in the positive and negative x
direction*
* `Enes100.mission(DIRECTION, NORMAL_Y);` *the normal of the exposed panels points in the positive and negative y
direction*
- `Enes100.mission(LENGTH, i);` _i is in millimeters_
- `Enes100.mission(HEIGHT, i);` _i is in millimeters_
- `Enes100.mission(DIRECTION, NORMAL_X);` _the normal of the exposed panels points in the positive and negative x
direction_
- `Enes100.mission(DIRECTION, NORMAL_Y);` _the normal of the exposed panels points in the positive and negative y
direction_

Valid calls for **DATA**:

* `Enes100.mission(CYCLE, i);` *i is the duty cycle percent (ex. 10, 30, 50, 70, 90)*
* `Enes100.mission(MAGNETISM, MAGNETIC);`
* `Enes100.mission(MAGNETISM, NOT_MAGNETIC);`
- `Enes100.mission(CYCLE, i);` _i is the duty cycle percent (ex. 10, 30, 50, 70, 90)_
- `Enes100.mission(MAGNETISM, MAGNETIC);`
- `Enes100.mission(MAGNETISM, NOT_MAGNETIC);`

Valid calls for **MATERIAL**:

* `Enes100.mission(WEIGHT, HEAVY);`
* `Enes100.mission(WEIGHT, MEDIUM);`
* `Enes100.mission(WEIGHT, LIGHT);`
* `Enes100.mission(MATERIAL_TYPE, FOAM);`
* `Enes100.mission(MATERIAL_TYPE, PLASTIC);`
- `Enes100.mission(WEIGHT, HEAVY);`
- `Enes100.mission(WEIGHT, MEDIUM);`
- `Enes100.mission(WEIGHT, LIGHT);`
- `Enes100.mission(MATERIAL_TYPE, FOAM);`
- `Enes100.mission(MATERIAL_TYPE, PLASTIC);`

Valid calls for **FIRE**:

* `Enes100.mission(NUM_CANDLES, i);` *i is an integer (0, 1, 2, 3, 4, 5)*
* `Enes100.mission(TOPOGRAPHY, TOP_A);`
* `Enes100.mission(TOPOGRAPHY, TOP_B);`
* `Enes100.mission(TOPOGRAPHY, TOP_C);`
- `Enes100.mission(NUM_CANDLES, i);` _i is an integer (0, 1, 2, 3, 4, 5)_
- `Enes100.mission(TOPOGRAPHY, TOP_A);`
- `Enes100.mission(TOPOGRAPHY, TOP_B);`
- `Enes100.mission(TOPOGRAPHY, TOP_C);`

Valid calls for **WATER**:

* `Enes100.mission(DEPTH, i);` *i is in mm*
* `Enes100.mission(WATER_TYPE, FRESH_UNPOLLUTED);`
* `Enes100.mission(WATER_TYPE, FRESH_POLLUTED);`
* `Enes100.mission(WATER_TYPE, SALT_UNPOLLUTED);`
* `Enes100.mission(WATER_TYPE, SALT_POLLUTED);`
- `Enes100.mission(DEPTH, i);` _i is in mm_
- `Enes100.mission(WATER_TYPE, FRESH_UNPOLLUTED);`
- `Enes100.mission(WATER_TYPE, FRESH_POLLUTED);`
- `Enes100.mission(WATER_TYPE, SALT_UNPOLLUTED);`
- `Enes100.mission(WATER_TYPE, SALT_POLLUTED);`

Valid calls for **SEED**:

* `Enes100.mission(LOCATION, plot);` *where plot is a single character A, B, C, or D*

- `Enes100.mission(LOCATION, plot);` _where plot is a single character A, B, C, or D_

## Machine Learning Functions

### About

The ESPCAM will be mounted to your OTV and act as your wifi module, with the added capabilities of camera vision. Note, this is not the overhead vision system above the arena - this is a development board provided that has a camera on it that will put on your otv.
The ESPCAM will be mounted to your OTV and act as your wifi module, with the added capabilities of camera vision. Note, this is not the overhead vision system above the arena - this is a development board provided that has a camera on it that will put on your otv.

### <span>int Enes100.MLGetPrediction(int modelIndex)<a name="ml_pred"></a>

Sends current image from the ESPCAM to the Vision System to get processed by your team's machine learning model with the provided index. Models must have been uploaded to the [ENES100 Model Uploader](https://enes100.umd.edu/uploadmodel) with the index requested beforehand to use this function. The function uses your team name (from the Enes100.begin() statement) to find your model. As such, **make sure your team name matches the model name exactly**.

Example:
If your ML model contained the categories: **Thumbs Up**, **Thumbs Down**, **Thumb Sideways** in an array in that order,
calling `Enes100.MLGetPrediction()` would return `0` if **Thumbs Up** is predicted, `1` if **Thumbs Down** is predicted, and `2` if **Thumb Sideways** is predicted.
If your ML model contained the categories: **Thumbs Up**, **Thumbs Down**, **Thumb Sideways** in an array in that order,
calling `Enes100.MLGetPrediction()` would return `0` if **Thumbs Up** is predicted, `1` if **Thumbs Down** is predicted, and `2` if **Thumb Sideways** is predicted.

## Example Code and Debugging<a name="ex"></a>

Example code for each type of mission is included with the library. To view examples, open Arduino IDE and go to *
*File > Examples > ENES100**. (You must restart the IDE after installing the library for the examples to show.)
Example code for each type of mission is included with the library. To view examples, open Arduino IDE and go to \*
\*File > Examples > ENES100\*\*. (You must restart the IDE after installing the library for the examples to show.)

## Product Demonstration Procedures<a name="prod"></a>

During the product demonstration, messages sent using `print()` and `println()` will not be shown on the Vision System
console. The console will only print out the values that you send using `mission()`.

## For Simulator
## For Simulator

The function calls to get the Aurco values are a little bit different than what they will be when you code for your otv
but they are functionally the same.
The function calls to get the Aurco values are a little bit different than what they will be when you code for your otv
but they are functionally the same.

```arduino
void setup() {
// Your begin statement with arbitrary values
Enes100.begin("It's lit", FIRE, 3, 8, 9);
Enes100.begin("It's lit", FIRE, 3, 8, 9);
}
```

Once this is called you will use the function

`Enes100.updateLocation()`

Calling this will allow you to access the values of aurco marker by writing
the following

* `Enes100.location.x`
* `Enes100.location.y`
* `Enes100.location.theta`
- `Enes100.location.x`
- `Enes100.location.y`
- `Enes100.location.theta`

```arduino
void loop() {
// This code will continuously print out the x cordinate
// This code will continuously print out the x cordinate
Enes100.updateLocation();
Enes100.println(Enes100.location.x);
setBothMotors(25);

}
```

#### **Common Issues**:

If you get an error **AxiosError: Network Error** remove the 's' from the
https link in url and reload the simulator
If you get an error **AxiosError: Network Error** remove the 's' from the
https link in url and reload the simulator
1 change: 1 addition & 0 deletions src/Enes100.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define Enes100_h

#include "VisionSystemClient.hpp"
// #include "WSVisionSystemClient.hpp"

#define CRASH_SITE 0
#define DATA 1
Expand Down
Loading