Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
0b3b5e8
Adding RT Support to Cadmium V2 - Step 1
jonmenard Aug 10, 2022
9177e6b
Creating a model to run in RT - Step 2
jonmenard Aug 14, 2022
f1b3939
Removing the logger when running in RT - Step 3
jonmenard Aug 16, 2022
8b37524
Adding Support for Asynchronous Events - Step 4
jonmenard Aug 19, 2022
16c7b48
Adding RT-Atomic Models - Step 5
jonmenard Aug 19, 2022
cdfa23c
Copyright formalities
jonmenard Aug 19, 2022
215d200
small fix so rt works with simulating non rt models normally
jonmenard Sep 30, 2022
439c1c1
Merge branch 'devel' into dev-rt
romancardenas Nov 18, 2022
c3a4bae
Separation of concerns
romancardenas Nov 18, 2022
dbae68f
Small change in CMakeLists.txt for release/debug compilation
romancardenas Nov 25, 2022
1fe4800
First working version of RT
romancardenas Feb 14, 2023
af5deb3
OpenMP for MacOS fixed
romancardenas Feb 14, 2023
8dd32c5
Minor changes
romancardenas Feb 15, 2023
94793f2
Added stdout logger for printing on standard out (for mbed it means s…
epecker Apr 17, 2023
fc5322c
Fixed the path to atomic.hpp library in all the atomics for managing …
epecker Apr 17, 2023
6bae973
Removed some printf in mbedclock.hpp used for debugging.
epecker Apr 17, 2023
a42081d
Added Blinky example.
epecker Apr 17, 2023
18e9608
Minor changes, mostly adding comments and removing preprocessor direc…
epecker Apr 18, 2023
8e53595
Moved the atomics for reading/writing gpios with mbed-os to the examp…
epecker Apr 18, 2023
8f34253
Added mbed compile profile for working with cadmium_v2.
epecker Apr 18, 2023
b54b183
Renamed the example Blinky to rt_mbed.
epecker Apr 18, 2023
1fa5a82
Added some missing files for the rt_mbed example.
epecker Apr 18, 2023
1fb1b53
Fixed doxygen documentation on stdout logger.
epecker Jun 10, 2023
1122515
Fixed doxygen documentation on stdout logger.
epecker Jun 10, 2023
b2f8876
In the BEDClockclass renamed some methods and reformated documentation.
epecker Jun 11, 2023
7035b1c
Removed mbed-os as a git submodule and added the mbed-os.lib to manag…
epecker Jun 12, 2023
e25b2ab
Added a README file for the rt_mbed example.
epecker Jun 12, 2023
be7475f
Made waitUntil() method in RealTimeClock class (rt_clock.hpp) return …
epecker Jun 17, 2023
3c2baed
Made waitUntil() method in ChronoClock class (chrono.hpp) return a do…
epecker Jun 17, 2023
ef67bd3
Added changes on method waitUntil() in MBEDClock class to return the …
epecker Jun 17, 2023
0e426e7
use waitUntil return value in RT coordinator
romancardenas Jun 22, 2023
5431af8
No logging
Srijan1972 Jun 27, 2023
c9bb50e
Undefined reference issue
Srijan1972 Jul 4, 2023
90e6346
Using asm delay
Srijan1972 Jul 6, 2023
e5cc5d0
Using timer32
Srijan1972 Jul 10, 2023
9d30a6a
I/O working
Srijan1972 Jul 11, 2023
7db296b
Blinky working
Srijan1972 Jul 12, 2023
76dd538
MSP
Srijan1972 Jul 20, 2023
4d55b5a
MSP README
Srijan1972 Jul 21, 2023
8d52e81
Fixed some issues on mbedclock.hpp.
epecker Aug 3, 2023
e5c8594
Merge branch 'dev-rt2' of https://github.com/Srijan1972/cadmium_v2 in…
epecker Aug 3, 2023
7acd7f5
Added NO_LOGGING macro toavoid including loggers in the main file of …
epecker Aug 6, 2023
a329377
Added NO_LOGGING macro delaration in profile cadmium.json for rt_mbed…
epecker Aug 6, 2023
73f840c
Added NO_LOGGING macro to the atomics for the rt_mbed example.
epecker Aug 6, 2023
e595c8a
Merge pull request #22 from SimulationEverywhere/dev-rt2
romancardenas Aug 10, 2023
2f774c6
NO_LOGGING
Srijan1972 Aug 22, 2023
2171b52
Merge pull request #24 from Srijan1972/dev-rt2
romancardenas Sep 8, 2023
20d6a20
MSP432P401R Support
Srijan1972 Sep 8, 2023
ad09fcb
New example file structure
Jeg27 Sep 16, 2023
3a45183
Delete example/MSP432P401R directory
Jeg27 Sep 16, 2023
bd4c1ee
Merge pull request #25 from Srijan1972/dev-rt2
romancardenas Sep 17, 2023
9cd4640
Delete example/rt_msp432/Example_0_Blank_Template.zip
Jeg27 Sep 26, 2023
f2402f2
Delete example/rt_msp432/Example_2_IO_Testing_Digital.zip
Jeg27 Sep 26, 2023
a083f03
Delete example/rt_msp432/Example_2_IO_Testing_Digital_Diagram.png
Jeg27 Sep 26, 2023
dcee778
Delete example/rt_msp432/Example_3_IO_Testing_Analog.zip
Jeg27 Sep 26, 2023
005928c
Delete example/rt_msp432/Example_3_IO_Testing_Analog_Diagram.png
Jeg27 Sep 26, 2023
46fd0c2
Delete example/rt_msp432/Example_4_Garage_Door_Opener.zip
Jeg27 Sep 26, 2023
2617eae
Delete example/rt_msp432/Example_4_Garage_Door_Opener_Diagram.png
Jeg27 Sep 26, 2023
15db3b3
Delete example/rt_msp432/updateCadmiumLINUXorUBUNTU.sh
Jeg27 Sep 26, 2023
4351a80
Delete example/rt_msp432/updateCadmiumWINDOWS.bat
Jeg27 Sep 26, 2023
9d97efd
Adding files for embedded execution.
Jeg27 Sep 26, 2023
242ddd5
Delete example/rt_msp432/cadmium directory
Jeg27 Oct 5, 2023
d962b6d
Merge pull request #26 from Jeg27/Srijan1972-dev-rt2
romancardenas Oct 5, 2023
9354ce6
Add mbedos submodule. Add IC. fix main_efp. colors to stdout. Add ESPCLK
Sasisekhar Sep 26, 2024
0a056a7
WIP fixing build script
Nov 29, 2024
6922f9b
change installation script
Jan 13, 2025
3cea7df
remove mbedos
Sasisekhar Jan 30, 2025
8098510
add progress to submodule
Sasisekhar Jan 30, 2025
d72ed99
fixing csv logger
Sasisekhar Jan 31, 2025
a3f6547
Making Interrupt Handler generic
Sasisekhar Feb 13, 2025
d48263b
adding input logging
Sasisekhar Feb 13, 2025
defb80d
Fixing logger
Sasisekhar Feb 18, 2025
590101e
Modify esp_clock for std::variant<> async input
Sasisekhar Feb 23, 2025
800d475
Fix power domain errors in clock
Sasisekhar Feb 23, 2025
a3936bc
Merge pull request #33 from Sasisekhar/dev-rt
romancardenas Mar 7, 2025
d83c98b
ESPclock backwards compatible; fix celldevs examples 'model'
Sasisekhar Mar 17, 2025
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
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ project(cadmium)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

add_library(cadmium INTERFACE)
target_include_directories(cadmium INTERFACE include/ json/include)

Expand All @@ -16,8 +22,26 @@ foreach(exampleSrc ${Examples})
target_link_libraries(${exampleName} cadmium)
endforeach(exampleSrc)

if(APPLE)
# Apple Clang does not pack OpenMP. We must install it via HomeBrew and link it manually
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
endif()
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
if (APPLE)
# HomeBrew leaves a symlink to the installed version of OpenMP in these directories
include_directories("/usr/local/opt/libomp/include")
link_directories("/usr/local/opt/libomp/lib")
endif()
FILE(GLOB Examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} example/*/parallel_main_*.cpp)
foreach(exampleSrc ${Examples})
get_filename_component(exampleName ${exampleSrc} NAME_WE)
Expand Down
34 changes: 33 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
#! /bin/bash

# Function to add the CADMIUM variable to the environment
add_cadmium_env() {
# Check if CADMIUM is already set in .bashrc
if ! grep -Fxq "export CADMIUM=$(pwd)" ~/.bashrc; then
echo "export CADMIUM=$(pwd)" >> ~/.bashrc
echo "The CADMIUM variable has been set to $(pwd) in ~/.bashrc."
else
echo "The CADMIUM variable is already set in ~/.bashrc."
fi

# Source the updated .bashrc
source ~/.bashrc
}

echo Downloading all the dependencies...
git submodule update --init --recursive
sudo apt install build-essential make cmake git
git pull
git submodule update --init --recursive --progress
mkdir build
cd build || exit
cmake ..
make all
cd ..
echo Compilation done. All the examples are in the bin folder

cd include
# Prompt the user for confirmation
echo "Do you want to add cadmium ($(pwd)) to the PATH? (yes/no)"
read -r response

# Check the response and take action
if [[ "$response" =~ ^[Yy][Ee][Ss]$ || "$response" =~ ^[Yy]$ ]]; then
add_cadmium_env
elif [[ "$response" =~ ^[Nn][Oo]$ || "$response" =~ ^[Nn]$ ]]; then
echo "Operation canceled. The $(pwd) was not added to PATH."
else
echo "Invalid response. Please run the script again and respond with 'yes' or 'no'."
fi
14 changes: 6 additions & 8 deletions celldevs_examples.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
echo Running asymmetric Cell-DEVS example...
cd example/celldevs_asymm_sir || exit
../../bin/main_asymm_sir config.json
cd ../..
echo Simulation done. Results are available in example/celldevs_asymm_sir/log.csv
cd example/celldevs_sir || exit
../../bin/main_asymm_sir asymm_config.json
echo Simulation done. Results are available in example/celldevs_sir/log_asymm_sir.csv

echo Running classic Cell-DEVS example...
cd example/celldevs_grid_sir || exit
../../bin/main_grid_sir config.json
echo Running grid Cell-DEVS example...
../../bin/main_grid_sir grid_config.json
cd ../..
echo Simulation done. Results are available in example/celldevs_grid_sir/log.csv
echo Simulation done. Results are available in example/celldevs_sir/log_grid_sir.csv
21 changes: 21 additions & 0 deletions example/_blinky/_main_blinky.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cadmium/core/logger/csv.hpp>
#include <cadmium/core/simulation/root_coordinator.hpp>
#include <limits>
#include "blinkySystem.hpp"

using namespace cadmium::example::blinkySystem;

int main(int argc, char *argv[]) {
// First, we parse the arguments
std::ifstream file;


auto model = std::make_shared<blinkySystem>("blinkySystem");
auto rootCoordinator = cadmium::RootCoordinator(model);
auto logger = std::make_shared<cadmium::CSVLogger>("log_blinkySystem.csv", ",");
rootCoordinator.setLogger(logger);
rootCoordinator.start();
rootCoordinator.simulate(std::numeric_limits<double>::infinity());
rootCoordinator.stop();
return 0;
}
21 changes: 21 additions & 0 deletions example/_rtModel/_main_rt_model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cadmium/core/logger/csv.hpp>
#include <cadmium/core/simulation/root_coordinator.hpp>
#include <limits>
#include "covidSupervisorySystem.hpp"

using namespace cadmium::example::covidSupervisorySystem;

int main(int argc, char *argv[]) {
// First, we parse the arguments
std::ifstream file;


auto model = std::make_shared<covidSupervisorySystem>("covidSupervisorySystem");
auto rootCoordinator = cadmium::RootCoordinator(model);
auto logger = std::make_shared<cadmium::CSVLogger>("log_covidSupervisorySystem.csv", ",");
rootCoordinator.setLogger(logger);
rootCoordinator.start();
rootCoordinator.simulate(std::numeric_limits<double>::infinity());
rootCoordinator.stop();
return 0;
}
104 changes: 104 additions & 0 deletions example/_rtModel/include/c02SensorController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#ifndef _C02_SENSOR_HPP__
#define _C02_SENSOR_HPP__

#include <cadmium/core/modeling/atomic.hpp>
#include <iostream>

namespace cadmium::example::covidSupervisorySystem {
//! Class for representing the Processor DEVS model state.
struct C02SensorControllerState {
double sigma;
double c02;
//! Processor state constructor. By default, the processor is idling.
C02SensorControllerState(): sigma(0), c02(1.00) {}
};

/**
* Insertion operator for ProcessorState objects. It only displays the value of sigma.
* @param out output stream.
* @param s state to be represented in the output stream.
* @return output stream with sigma already inserted.
*/
std::ostream& operator<<(std::ostream &out, const C02SensorControllerState& state) {
out << "C02 Level:," << state.c02;
return out;
}

//! Atomic DEVS model of a Job processor.
class C02SensorController : public Atomic<C02SensorControllerState> {
private:
const float MIN_CO2_VOLTAGE = 0.5; //!< Time required by the Processor model to process one Job.
public:
Port<bool> c02In; //!< Input Port for receiving new Job objects.
Port<bool> c02Safe; //!< Output Port for sending processed Job objects.

/**
* Constructor function.
* @param id ID of the new Processor model object.
*/
C02SensorController(const std::string& id): Atomic<C02SensorControllerState>(id, C02SensorControllerState()) {
c02In = addInPort<bool>("c02In");
c02Safe = addOutPort<bool>("c02Safe");
}

/**
* It updates the ProcessorState::clock, clears the ProcessorState::Job being processed, and passivates.
* @param state reference to the current state of the model.
*/
void internalTransition(C02SensorControllerState& state) const override {
state.sigma = std::numeric_limits<double>::infinity();
}

/**
* Updates ProcessorState::clock and ProcessorState::sigma.
* If it is idling and gets a new Job via the Processor::inGenerated port, it starts processing it.
* @param state reference to the current model state.
* @param e time elapsed since the last state transition function was triggered.
* @param x reference to the model input port set.
*/
void externalTransition(C02SensorControllerState& state, double e) const override {

if(!c02In->empty()){
state.sigma = 0;
if(c02In->getBag().back()){
state.c02 = 1;
}else{
state.c02 = 0;
}

return;
}

state.sigma = std::numeric_limits<double>::infinity();


}

/**
* It outputs the already processed ProcessorState::Job via the Processor::outProcessed port.
* @param state reference to the current model state.
* @param y reference to the atomic model output port set.
*/
void output(const C02SensorControllerState& state) const override {

bool safe = false;

if(state.c02 > MIN_CO2_VOLTAGE){
safe = true;
}
c02Safe->addMessage(safe);

}

/**
* It returns the value of ProcessorState::sigma.
* @param state reference to the current model state.
* @return the sigma value.
*/
[[nodiscard]] double timeAdvance(const C02SensorControllerState& state) const override {
return state.sigma;
}
};
} //namespace cadmium::example::covidSupervisorySystem

#endif //_C02_SENSOR_HPP__
43 changes: 43 additions & 0 deletions example/_rtModel/include/covidSupervisorySystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef CADMIUM_EXAMPLE_COVID_SUPERVISORY_SYSTEM_HPP_
#define CADMIUM_EXAMPLE_COVID_SUPERVISORY_SYSTEM_HPP_

#include <cadmium/core/modeling/coupled.hpp>
#include <cadmium/lib/iestream.hpp>
#include "./digitalInput.hpp"
#include "./c02SensorController.hpp"
#include "./ledController.hpp"
#include "./occupencyController.hpp"

namespace cadmium::example::covidSupervisorySystem {
//! Coupled DEVS model to show how the IEStream atomic model works.
struct covidSupervisorySystem : public Coupled {

/**
* Constructor function for the iestream model.
* @param id ID of the iestream model.
* @param filePath path to the input file to be read.
*/
covidSupervisorySystem(const std::string& id) : Coupled(id) {

auto digitalInput = addComponent<DigitalInput>("digitalInput");
auto iestreamOccIn = addComponent<IEStream<bool>>("iestreamOccIn", "../example/rtModel/occIn.txt");
auto iestreamOccOut = addComponent<IEStream<bool>>("iestreamOccOut", "../example/rtModel/occOut.txt");


auto occupencyController = addComponent<OccupencyController>("occupencyController");
auto ledController = addComponent<LEDController>("ledController");
auto c02SensorController = addComponent<C02SensorController>("c02SensorController");

addCoupling(digitalInput->out, c02SensorController->c02In);
addCoupling(iestreamOccIn->out, occupencyController->personIn);
addCoupling(iestreamOccOut->out, occupencyController->personOut);


addCoupling(occupencyController->personSafe, ledController->occupancyIn);
addCoupling(c02SensorController->c02Safe, ledController->c02In);

}
};
} //namespace cadmium::example::covidSupervisorySystem

#endif //CADMIUM_EXAMPLE_COVID_SUPERVISORY_SYSTEM_HPP_
72 changes: 72 additions & 0 deletions example/_rtModel/include/digitPin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Jon Menard
* ARSLab - Carleton University
*
* Digital Input:
* Model to interface with a digital Input pin for Embedded Cadmium.
*/



#ifndef RT_DIGITALPIN_HPP
#define RT_DIGITALPIN_HPP



#include <iostream>
#include <optional>

#include <thread>
#include <mutex>
#include <chrono>
#include <windows.h>
#include <stdio.h>
#include <string.h>


using namespace std;
namespace cadmium {

class DigitalPin {
mutable std::mutex input_mutex;
mutable bool keyPressed;

public:
DigitalPin(){
std::unique_lock<std::mutex> mutex_lock(input_mutex, std::defer_lock);
mutex_lock.lock();
keyPressed = false;
// _keyCode = keyCode;
mutex_lock.unlock();
std::thread(&DigitalPin::listen, this).detach();
};

bool checkPin(){
bool pin;
std::unique_lock<std::mutex> mutex_lock(input_mutex, std::defer_lock);
mutex_lock.lock();
pin = keyPressed;
keyPressed = false;

mutex_lock.unlock();

return pin;
}

void listen(){
std::unique_lock<std::mutex> mutex_lock(input_mutex, std::defer_lock);
string str;
while(1){
getline(cin, str);
if(str == ""){
mutex_lock.lock();
keyPressed = true;
mutex_lock.unlock();
}
}
}

};
} // namespace cadmium

#endif // RT_DIGITALPIN_HPP
Loading