Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Configure equipment #35

Merged
merged 12 commits into from
Feb 23, 2020
67 changes: 26 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Low-level software for ROV. Takes JSON key:value pairs from [Raspberry Pi](https

To install this code on an Arduino you first need to run the appropriate setup script (in arduino-setup ) to assign an ID to the Arduino. This ID dictates the functionality as follows:

* Ard_T: Control for Thrusters on main ROV body
* Ard_M: Control for any Micro ROV devices
* Ard_O: Control for Thrusters and other output devices on main ROV body
* Ard_I: Sending sensor data back up to surface

After running the setup script, flash arduino-main to the device.
Expand All @@ -27,7 +26,7 @@ You need to install the following libraries in your IDE:

## Expected behaviour

### Arduino T
### Arduino O

This Arduino is for controlling the output devices on the main ROV body.

Expand All @@ -37,51 +36,37 @@ Thrusters are given an ID which describes their position on the ROV. Motors are

| Pin | JSON ID | Description |
|-----|---------|---------------------------------------------|
| 2 | Thr_FP | Forward Port Thruster (front right) |
| 3 | Thr_FS | Forward Starboard Thruster (front left) |
| 4 | Thr_AP | Aft Port Thruster (back left) |
| 5 | Thr_AS | Aft Starboard Thruster (back right) |
| 6 | Thr_TFP | Top Forward Port Thruster (front right) |
| 7 | Thr_TFS | Top Forward Starboard Thruster (front left) |
| 8 | Thr_TAP | Top Aft Port Thruster (back left) |
| 9 | Thr_TAS | Top Aft Starboard Thruster (back right) |
| 10 | Mot_R | Arm Rotation Motor |
| 11 | Mot_G | Arm Gripper Motor |
| 12 | Mot_F | Fish Box Opening Motor |
| 0 | thfp | Forward Port Thruster (front right) |
| 1 | thfs | Forward Starboard Thruster (front left) |
| 2 | thap | Aft Port Thruster (back left) |
| 3 | thas | Aft Starboard Thruster (back right) |
| 4 | tvfp | Top Forward Port Thruster (front right) |
| 5 | tvfs | Top Forward Starboard Thruster (front left) |
| 6 | tvap | Top Aft Port Thruster (back left) |
| 7 | tvas | Top Aft Starboard Thruster (back right) |
| 8 | mg | Arm Gripper Motor |
| 9 | tm | Micro ROV Thruster |
| 10 | mc | Micro ROV return cord |

### Arduino M

This Arduino is for controlling the thruster on the Micro ROV.

Values in the range 1100 to 1900 will be accepted for Thruster or control where 1100 is full reverse, 1500 is stopped, and 1900 is full forward.

Thrusters are given an ID which describes their position on the ROV.

| Pin | JSON ID | Description |
|-----|---------|---------------------------------------------|
| 3 | Thr_M | Micro ROV Thruster |

### Arduino ID
### Arduino I

This Arduino is for reading all the sensors on the ROV.

| JSON ID | Description |
|----------------|----------------------------------------|
| Sen_IMU_X | X Orientation |
| Sen_IMU_Y | Y Orientation |
| Sen_IMU_Z | Z Orientation |
| Sen_IMU_Temp | Internal ROV temperature |
| Sen_IMU_AccX | Linear acceleration X |
| Sen_IMU_AccY | Linear acceleration X |
| Sen_IMU_AccZ | Linear acceleration X |
| Sen_Dep_Pres | External water pressure |
| Sen_Dep_Temp | External temperature |
| Sen_Dep_Dep | Depth |
| Sen_Temp | External temperature (higher accuracy) |
| Sen_PH | External PH |
| Sen_Sonar_Dist | Distance measurement from sonar |
| Sen_Sonar_Conf | Confidence of sonar measurement |
| Sen_Metal | Metal detector strength |
| simux | X Orientation |
| simuy | Y Orientation |
| simuz | Z Orientation |
| simut | Internal ROV temperature |
| simuax | Linear acceleration X |
| simuay | Linear acceleration Y |
| simuaz | Linear acceleration Z |
| sdepp | External water pressure |
| sdept | External temperature |
| sdepd | Depth |
| sdepa | Altitude |



### Ret Codes
Expand Down
23 changes: 7 additions & 16 deletions arduino-main/arduino-main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,15 @@ Communication communication; // Object to allow for communication with the Raspb
/* =======================Setup function======================= */
/* =============Runs once when Arduino is turned on============ */
void setup() {
arduinoID = ARD + String(char(EEPROM.read(0)));
arduinoID = String(char(EEPROM.read(0)));

// initialize serial:
Serial.begin(115200);
communication.sendStatus(4);



// Map inputs and outputs based on which Arduino this is
if (arduinoID == ARD + "T") {
mapper.mapT();
}
else if (arduinoID == ARD + "I"){
mapper.mapI();
}
else if (arduinoID == ARD + "M"){
mapper.mapM();
}
mapper.instantiateMap();

communication.sendAll();
communication.sendStatus(0);
}
Expand All @@ -84,10 +75,10 @@ void loop() {
safetyActive = false; // Switch off auto-off because valid message received

// Act on incoming message accordingly
if(arduinoID== ARD + "T" || arduinoID == ARD + "M"){
if(mapper.thisIsAnOutputArduino()){
handleOutputCommands(root);
}
else if (arduinoID == ARD + "I"){
else if (mapper.thisIsAnInputArduino()){
handleSensorCommands(root);
}
else{
Expand All @@ -101,11 +92,11 @@ void loop() {

// Code to run all the time goes here:

if(arduinoID == ARD + "T" || arduinoID == ARD + "M"){
if(mapper.thisIsAnOutputArduino()){
// This Arduino is for outputting
disableOutputsIfNoMessageReceived(safetyShutoffTimeMs);
}
else if(arduinoID == ARD + "I"){
else if(mapper.thisIsAnInputArduino()){
// Output all sensor data
mapper.sendAllSensors();
}
Expand Down
6 changes: 3 additions & 3 deletions arduino-main/src/communication/communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ void Communication::bufferValue(String device, String incomingValue){

void Communication::sendStatus (int status){
//Hardcoded JSON
Serial.print("{\"deviceID\":\"");
Serial.print("{\""+deviceIdKey+"\":\"");
Serial.print(arduinoID);
Serial.print("\",\"status_");
Serial.print("\",\""+statusKey);
Serial.print(String(char(EEPROM.read(0))));
Serial.print("\":\"");
Serial.print(status);
Serial.println("\"}");
}

void Communication::sendAll(){
Serial.print("{\"deviceID\":\"");
Serial.print("{\""+deviceIdKey+"\":\"");
Serial.print(arduinoID);
Serial.print("\"");
Serial.print(messageContents);
Expand Down
2 changes: 2 additions & 0 deletions arduino-main/src/communication/communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Communication{
int currentPosition; // value of next free space
bool stringComplete = false; // whether a full JSON string has been received
String inputString = ""; // a String to hold incoming data
String statusKey = "s";
String deviceIdKey = "id";
String messageContents = "";

public:
Expand Down
8 changes: 4 additions & 4 deletions arduino-main/src/equipment/input/depth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Depth::Depth(int inputPin, String incomingPartID){
int Depth::getValue() {
if(initialised){
depthSensor.read(); // Read current values
communication.bufferValue(this->partID+"_Pres",String(depthSensor.pressure()));
communication.bufferValue(this->partID+"_Temp",String(depthSensor.temperature()));
communication.bufferValue(this->partID+"_Dep",String(depthSensor.depth()));
communication.bufferValue(this->partID+"_Alt",String(depthSensor.altitude()));
communication.bufferValue(this->partID+"p",String(depthSensor.pressure()));
communication.bufferValue(this->partID+"t",String(depthSensor.temperature()));
communication.bufferValue(this->partID+"d",String(depthSensor.depth()));
communication.bufferValue(this->partID+"a",String(depthSensor.altitude()));

}
else{
Expand Down
14 changes: 7 additions & 7 deletions arduino-main/src/equipment/input/imu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ int IMU::getValue() {
imu.getEvent(&event);
/* Output the floating point data */
// x
communication.bufferValue(this->partID+"_X",String(event.orientation.x));
communication.bufferValue(this->partID+"x",String(event.orientation.x));

// y
communication.bufferValue(this->partID+"_Y",String(event.orientation.y));
communication.bufferValue(this->partID+"x",String(event.orientation.y));

// z
communication.bufferValue(this->partID+"_Z",String(event.orientation.z));
communication.bufferValue(this->partID+"z",String(event.orientation.z));

// Get temperature recorded by IMU
int8_t temp = imu.getTemp();
communication.bufferValue(this->partID+"_Temp",String(temp));
communication.bufferValue(this->partID+"t",String(temp));

// Get acceleration data
imu::Vector<3> euler = imu.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);

communication.bufferValue(this->partID+"_AccX",String(euler.x()));
communication.bufferValue(this->partID+"_AccY",String(euler.y()));
communication.bufferValue(this->partID+"_AccZ",String(euler.z()));
communication.bufferValue(this->partID+"ax",String(euler.x()));
communication.bufferValue(this->partID+"ay",String(euler.y()));
communication.bufferValue(this->partID+"az",String(euler.z()));

}
else{
Expand Down
2 changes: 1 addition & 1 deletion arduino-main/src/util/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ String arduinoID = ""; // JSON ID representing this Arduino (read from long-ter

int safetyShutoffTimeMs = 1000; // Amount of time in ms before everything gets shut off if no message received

String ARD = "Ard_"; // Prefix for Arduino ID
//String ARD = "Ard_"; // Prefix for Arduino ID - deprecated
2 changes: 1 addition & 1 deletion arduino-main/src/util/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ extern String arduinoID;

extern int safetyShutoffTimeMs;

extern String ARD;
//extern String ARD;

#endif /* CONSTANTS_H */
Loading