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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ add_executable(hybridapi
src/labsland/simulations/watertanksimulation.cpp
src/deusto/door.cpp
src/deusto/watertankDeusto.cpp
src/deusto/watertankDeustoTemperature.cpp
src/deusto/wiperDeusto.cpp
src/deusto/wiper2BitDeusto.cpp
src/rhlab/butterfly.cpp
src/rhlab/matrix.cpp
src/rhlab/morse.cpp
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body { padding: 0; margin: 0 }
#unity-container { position: absolute }
#unity-container.unity-desktop { left: 50%; top: 50%; transform: translate(-50%, -50%) }
#unity-container.unity-mobile { width: 100%; height: 100% }
#unity-canvas { background: #231F20 }
.unity-mobile #unity-canvas { width: 100%; height: 100% }
#unity-loading-bar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none }
#unity-logo { width: 154px; height: 130px; background: url('unity-logo-dark.png') no-repeat center }
#unity-progress-bar-empty { width: 141px; height: 18px; margin-top: 10px; margin-left: 6.5px; background: url('progress-bar-empty-dark.png') no-repeat center }
#unity-progress-bar-full { width: 0%; height: 18px; margin-top: 10px; background: url('progress-bar-full-dark.png') no-repeat center }
#unity-footer { position: relative }
.unity-mobile #unity-footer { display: none }
#unity-webgl-logo { float:left; width: 204px; height: 38px; background: url('webgl-logo.png') no-repeat center }
#unity-build-title { float: right; margin-right: 10px; line-height: 38px; font-family: arial; font-size: 18px }
#unity-fullscreen-button { float: right; width: 38px; height: 38px; background: url('fullscreen-button.png') no-repeat center }
#unity-warning { position: absolute; left: 50%; top: 5%; transform: translate(-50%); background: white; padding: 10px; display: none }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body { padding: 0; margin: 0 }
#unity-container { position: absolute }
#unity-container.unity-desktop { left: 50%; top: 50%; transform: translate(-50%, -50%) }
#unity-container.unity-mobile { width: 100%; height: 100% }
#unity-canvas { background: #231F20 }
.unity-mobile #unity-canvas { width: 100%; height: 100% }
#unity-loading-bar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none }
#unity-logo { width: 154px; height: 130px; background: url('unity-logo-dark.png') no-repeat center }
#unity-progress-bar-empty { width: 141px; height: 18px; margin-top: 10px; margin-left: 6.5px; background: url('progress-bar-empty-dark.png') no-repeat center }
#unity-progress-bar-full { width: 0%; height: 18px; margin-top: 10px; background: url('progress-bar-full-dark.png') no-repeat center }
#unity-footer { position: relative }
.unity-mobile #unity-footer { display: none }
#unity-webgl-logo { float:left; width: 204px; height: 38px; background: url('webgl-logo.png') no-repeat center }
#unity-build-title { float: right; margin-right: 10px; line-height: 38px; font-family: arial; font-size: 18px }
#unity-fullscreen-button { float: right; width: 38px; height: 38px; background: url('fullscreen-button.png') no-repeat center }
#unity-warning { position: absolute; left: 50%; top: 5%; transform: translate(-50%); background: white; padding: 10px; display: none }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body { padding: 0; margin: 0 }
#unity-container { position: absolute }
#unity-container.unity-desktop { left: 50%; top: 50%; transform: translate(-50%, -50%) }
#unity-container.unity-mobile { width: 100%; height: 100% }
#unity-canvas { background: #231F20 }
.unity-mobile #unity-canvas { width: 100%; height: 100% }
#unity-loading-bar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none }
#unity-logo { width: 154px; height: 130px; background: url('unity-logo-dark.png') no-repeat center }
#unity-progress-bar-empty { width: 141px; height: 18px; margin-top: 10px; margin-left: 6.5px; background: url('progress-bar-empty-dark.png') no-repeat center }
#unity-progress-bar-full { width: 0%; height: 18px; margin-top: 10px; background: url('progress-bar-full-dark.png') no-repeat center }
#unity-footer { position: relative }
.unity-mobile #unity-footer { display: none }
#unity-webgl-logo { float:left; width: 204px; height: 38px; background: url('webgl-logo.png') no-repeat center }
#unity-build-title { float: right; margin-right: 10px; line-height: 38px; font-family: arial; font-size: 18px }
#unity-fullscreen-button { float: right; width: 38px; height: 38px; background: url('fullscreen-button.png') no-repeat center }
#unity-warning { position: absolute; left: 50%; top: 5%; transform: translate(-50%); background: white; padding: 10px; display: none }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion server/simulations/watertankDeusto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ iframe:
height: 700
gpios:
sim2dut:
labels: [ lowSensor, midSensor, highSensor, pump1Hot, pump2Hot ]
labels: [ lowSensor, midSensor, highSensor ]
dut2sim:
labels: [ pump1Bit0, pump1Bit1, pump2Bit0, pump2Bit1 ]
10 changes: 10 additions & 0 deletions server/simulations/watertankDeustoTemperature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Watertank
description: This is a watertank simulation
iframe:
url: watertankDeustoTemperature/index.html
height: 700
gpios:
sim2dut:
labels: [ lowSensor, midSensor, highSensor, pump1Hot, pump2Hot ]
dut2sim:
labels: [ pump1Bit0, pump1Bit1, pump2Bit0, pump2Bit1 ]
10 changes: 10 additions & 0 deletions server/simulations/wiper2BitDeusto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Wiper
description: This is a wiper simulation
iframe:
url: wiper2BitDeusto/index.html
height: 700
gpios:
sim2dut:
labels: [ rainSensor, rightSenson, leftSensor, mButton, pButton]
dut2sim:
labels: [ move1, move2 ]
10 changes: 10 additions & 0 deletions server/simulations/wiperDeusto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Wiper
description: This is a wiper simulation
iframe:
url: wiperDeusto/index.html
height: 700
gpios:
sim2dut:
labels: [ rainSensor, rightSenson, leftSensor, mButton, pButton ]
dut2sim:
labels: [ move ]
9 changes: 9 additions & 0 deletions src-stdcpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "rhlab/morse.h"
#include "deusto/door.h"
#include "deusto/watertankDeusto.h"
#include "deusto/watertankDeustoTemperature.h"
#include "deusto/wiperDeusto.h"
#include "deusto/wiper2BitDeusto.h"
#include "labsland/simulations/utils/communicatorfiles.h"
#include "labsland/simulations/targetdevicefiles.h"
#include "labsland/utils/timemanagerstd.h"
Expand Down Expand Up @@ -116,6 +119,12 @@ int main(int argc, char * argv[]) {
runner = new ConcreteSimulationRunner<DoorSimulation, DoorData, DoorRequest>(configuration, mode);
} else if (simulation == "watertankDeusto") {
runner = new ConcreteSimulationRunner<WatertankDeustoSimulation, WatertankDeustoData, WatertankDeustoRequest>(configuration, mode);
} else if (simulation == "watertankDeustoTemperature") {
runner = new ConcreteSimulationRunner<WatertankDeustoTemperatureSimulation, WatertankDeustoTemperatureData, WatertankDeustoTemperatureRequest>(configuration, mode);
}else if (simulation == "wiperDeusto") {
runner = new ConcreteSimulationRunner<WiperDeustoSimulation, WiperDeustoData, WiperDeustoRequest>(configuration, mode);
}else if (simulation == "wiper2BitDeusto") {
runner = new ConcreteSimulationRunner<Wiper2BitDeustoSimulation, Wiper2BitDeustoData, Wiper2BitDeustoRequest>(configuration, mode);
} else if (simulation == "morse") {
runner = new ConcreteSimulationRunner< RHLab::Morse::MorseSimulation, RHLab::Morse::MorseData, RHLab::Morse::MorseRequest>(configuration, mode);
}
Expand Down
55 changes: 12 additions & 43 deletions src/deusto/watertankDeusto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
void WatertankDeustoSimulation::initialize() {

this->targetDevice->initializeSimulation(
{"lowSensorActive", "midSensorActive", "highSensorActive", "pump1Hot", "pump2Hot"},
{"lowSensorActive", "midSensorActive", "highSensorActive"},
{"pump1Bit0","pump1Bit1", "pump2Bit0", "pump2Bit1"}
);

Expand All @@ -25,7 +25,6 @@
setReportWhenMarked(true);
}

int error[4][3] = {{ 0, 1, 0 },{ 1, 0, 0 },{ 1, 0, 1 },{ 1, 1, 0 }};
void WatertankDeustoSimulation::update(double delta) {

this->log() << "Updating simulation. Delta: " << delta << std::endl;
Expand All @@ -40,16 +39,6 @@

double addedWater = 0;

if (mState.pump1Temperature>=85) mState.pump1Hot = true;
else mState.pump1Hot = false;
if (mState.pump2Temperature>=85) mState.pump2Hot = true;
else mState.pump2Hot = false;

if (mState.pump1Temperature>=100) mState.pump1Broken = true;
else mState.pump1Broken = false;
if (mState.pump2Temperature>=100) mState.pump2Broken = true;
else mState.pump2Broken = false;

mState.pump1ActiveBit0 = this->targetDevice->getGpio("pump1Bit0");
mState.pump1ActiveBit1 = this->targetDevice->getGpio("pump1Bit1");

Expand All @@ -58,37 +47,19 @@

this->log() << "Pumps: pump1: " << mState.pump1ActiveBit0 << mState.pump1ActiveBit1 << "; pump2: " << mState.pump2ActiveBit0 << mState.pump2ActiveBit1 << std::endl;

if(mState.pump1ActiveBit0 || mState.pump1ActiveBit1) {
if(mState.pump1Temperature<100) mState.pump1Temperature += 3 * delta;
else mState.pump1Temperature = 100;

if (!mState.pump1Broken) {
if (mState.pump1ActiveBit0 == 1 && mState.pump1ActiveBit1 == 1) {
addedWater += 2 * PUMP1_FLOWRATE * delta;
} else {
addedWater += PUMP1_FLOWRATE * delta;
}
}
}else{
if(mState.pump1Temperature>0) mState.pump1Temperature -= 6 * delta;
else mState.pump1Temperature = 0;

if (mState.pump1ActiveBit0 == 1 && mState.pump1ActiveBit1 == 1) {
addedWater += 2 * PUMP1_FLOWRATE * delta;
} else if(mState.pump1ActiveBit0 == 0 && mState.pump1ActiveBit1 == 1){
addedWater += PUMP1_FLOWRATE * delta;
}

if(mState.pump2ActiveBit0 || mState.pump2ActiveBit1) {
if(mState.pump2Temperature<100) mState.pump2Temperature += 3 * delta;
else mState.pump2Temperature = 100;

if (!mState.pump2Broken) {
if (mState.pump2ActiveBit0 == 1 && mState.pump2ActiveBit1 == 1) {
addedWater += 2 * PUMP2_FLOWRATE * delta;
} else {
addedWater += PUMP2_FLOWRATE * delta;
}
}
}else{
if(mState.pump2Temperature>0) mState.pump2Temperature -= 6 * delta;
else mState.pump2Temperature = 0;

if (mState.pump2ActiveBit0 == 1 && mState.pump2ActiveBit1 == 1) {
addedWater += 2 * PUMP2_FLOWRATE * delta;
} else if(mState.pump2ActiveBit0 == 0 && mState.pump2ActiveBit1 == 1){
addedWater += PUMP2_FLOWRATE * delta;
}


float removedWater = 0;
removedWater = mCurrentDemandFlowrate * delta;
Expand Down Expand Up @@ -130,8 +101,6 @@
this->targetDevice->setGpio("lowSensorActive", mState.lowSensorActive);
this->targetDevice->setGpio("midSensorActive", mState.midSensorActive);
this->targetDevice->setGpio("highSensorActive", mState.highSensorActive);
this->targetDevice->setGpio("pump1Hot", mState.pump1Hot);
this->targetDevice->setGpio("pump2Hot", mState.pump2Hot);

this->log() << "of: " << request.outputFlow << "; err: " << request.makeError << "; res: " << request.resetError << std::endl;

Expand Down
14 changes: 5 additions & 9 deletions src/deusto/watertankDeusto.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
bool lowSensorActive;
bool midSensorActive;
bool highSensorActive;
bool pump1Hot;
bool pump2Hot;
bool pump1Broken;
bool pump2Broken;

std::string serialize() const {
std::stringstream stream;
stream << level << "&" << totalVolume << "&" << volume << "&" << pump1ActiveBit0 << pump1ActiveBit1 << "&" << pump2ActiveBit0 << pump2ActiveBit1 << "&" <<
pump1Temperature << "&" << pump2Temperature << "&" << currentLoad << "&" << lowSensorActive << "&" <<
midSensorActive << "&" << highSensorActive << "&"<< pump1Hot << "&" << pump2Hot << "&" <<
pump1Broken << "&" << pump2Broken << "&";
stream << level << "&" << pump1ActiveBit0 << pump1ActiveBit1 << "&" << pump2ActiveBit0 << pump2ActiveBit1 << "&" <<
pump1Temperature << "&" << pump2Temperature << "&" << lowSensorActive << "&" <<
midSensorActive << "&" << highSensorActive << "&";
return stream.str();
}
};
Expand Down Expand Up @@ -68,7 +63,8 @@
const float PUMP2_FLOWRATE = 2000;

float mCurrentDemandFlowrate = 0;


int error[4][3] = {{ 0, 1, 0 },{ 1, 0, 0 },{ 1, 0, 1 },{ 1, 1, 0 }};
bool makeError = false;
bool resetError = false;
bool isBroken = false;
Expand Down
142 changes: 142 additions & 0 deletions src/deusto/watertankDeustoTemperature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include <string>
#include <iostream>
#include <cmath>
#include "watertankDeustoTemperature.h"


void WatertankDeustoTemperatureSimulation::initialize() {

this->targetDevice->initializeSimulation(
{"lowSensorActive", "midSensorActive", "highSensorActive", "pump1Hot", "pump2Hot"},
{"pump1Bit0","pump1Bit1", "pump2Bit0", "pump2Bit1"}
);

float radius = WATERTANK_DIAMETER / 2;
mState.totalVolume = M_PI * radius * radius * WATERTANK_HEIGHT * 1000;

mState.volume = mState.totalVolume / 2;
mState.level = 0.9;

mState.pump1ActiveBit0 = false;
mState.pump1ActiveBit1 = false;
mState.pump2ActiveBit0 = false;
mState.pump2ActiveBit1 = false;

setReportWhenMarked(true);
}

void WatertankDeustoTemperatureSimulation::update(double delta) {

this->log() << "Updating simulation. Delta: " << delta << std::endl;

WatertankDeustoTemperatureRequest request;
bool requestWasRead = readRequest(request);
if (requestWasRead) {
mCurrentDemandFlowrate = request.outputFlow;
makeError = request.makeError;
resetError = request.resetError;
}

double addedWater = 0;

if (mState.pump1Temperature>=90) mState.pump1Hot = true;
else if (mState.pump1Hot && mState.pump1Temperature<=30)mState.pump1Hot = false;
if (mState.pump2Temperature>=90) mState.pump2Hot = true;
else if(mState.pump2Hot && mState.pump2Temperature<=30) mState.pump2Hot = false;

if (mState.pump1Temperature>=100) mState.pump1Broken = true;
else mState.pump1Broken = false;
if (mState.pump2Temperature>=100) mState.pump2Broken = true;
else mState.pump2Broken = false;

mState.pump1ActiveBit0 = this->targetDevice->getGpio("pump1Bit0");
mState.pump1ActiveBit1 = this->targetDevice->getGpio("pump1Bit1");

mState.pump2ActiveBit0 = this->targetDevice->getGpio("pump2Bit0");
mState.pump2ActiveBit1 = this->targetDevice->getGpio("pump2Bit1");

this->log() << "Pumps: pump1: " << mState.pump1ActiveBit0 << mState.pump1ActiveBit1 << "; pump2: " << mState.pump2ActiveBit0 << mState.pump2ActiveBit1 << std::endl;

if(mState.pump1ActiveBit0 || mState.pump1ActiveBit1) {
if(mState.pump1Temperature<100) mState.pump1Temperature += 3 * delta;
else mState.pump1Temperature = 100;

if (!mState.pump1Broken) {
if (mState.pump1ActiveBit0 == 1 && mState.pump1ActiveBit1 == 1) {
addedWater += 2 * PUMP1_FLOWRATE * delta;
} else if(mState.pump1ActiveBit0 == 0 && mState.pump1ActiveBit1 == 1){
addedWater += PUMP1_FLOWRATE * delta;
}
}
}else{
if(mState.pump1Temperature>0) mState.pump1Temperature -= 6 * delta;
else mState.pump1Temperature = 0;
}

if(mState.pump2ActiveBit0 || mState.pump2ActiveBit1) {
if(mState.pump2Temperature<100) mState.pump2Temperature += 3 * delta;
else mState.pump2Temperature = 100;

if (!mState.pump2Broken) {
if (mState.pump2ActiveBit0 == 1 && mState.pump2ActiveBit1 == 1) {
addedWater += 2 * PUMP2_FLOWRATE * delta;
} else if(mState.pump2ActiveBit0 == 0 && mState.pump2ActiveBit1 == 1){
addedWater += PUMP2_FLOWRATE * delta;
}
}
}else{
if(mState.pump2Temperature>0) mState.pump2Temperature -= 6 * delta;
else mState.pump2Temperature = 0;
}

float removedWater = 0;
removedWater = mCurrentDemandFlowrate * delta;

this->log() << "Old volume: " << mState.volume << "; adding: " << addedWater << "; removing (flow rate=" << mCurrentDemandFlowrate << "): " << removedWater << std::endl;

mState.volume = mState.volume + addedWater - removedWater;
if (mState.volume < 0) {
mState.volume = 0;
}
if (mState.volume > mState.totalVolume) {
mState.volume = mState.totalVolume;
}

mState.level = mState.volume / mState.totalVolume;

if(resetError && isBroken){
isBroken = false;
}
if(makeError && !isBroken){

isBroken = true;
int randomError = rand() % 4;

mState.lowSensorActive = error[randomError][2];
mState.midSensorActive = error[randomError][1];
mState.highSensorActive = error[randomError][0];
}

this->log() << "New volume: " << mState.volume << "; which is level=" << mState.level << std::endl;
if(!isBroken)
{
mState.lowSensorActive = mState.level >= 0.20;
mState.midSensorActive = mState.level >= 0.50;
mState.highSensorActive = mState.level >= 0.80;
}
this->log() << "Sensors: Low (0.2): " << mState.lowSensorActive << "; Mid (0.5): " << mState.midSensorActive << "; High (0.8): " << mState.highSensorActive << std::endl;

this->targetDevice->setGpio("lowSensorActive", mState.lowSensorActive);
this->targetDevice->setGpio("midSensorActive", mState.midSensorActive);
this->targetDevice->setGpio("highSensorActive", mState.highSensorActive);
this->targetDevice->setGpio("pump1Hot", mState.pump1Hot);
this->targetDevice->setGpio("pump2Hot", mState.pump2Hot);

this->log() << "of: " << request.outputFlow << "; err: " << request.makeError << "; res: " << request.resetError << std::endl;

requestReportState();
}




Loading