GithubHelp home page GithubHelp logo

mehecip / mbd Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 166 KB

C++ Model/Node Based Development/Engineering Library

License: Other

CMake 6.69% C++ 93.31%
mbd modelbase node-development dataflow dataflow-programming model-based-development

mbd's Introduction

mbd

C++ Model Based Development/Engineering Library

  • fast: Design with 7 models executed 10.000.000 ticks in 1.55 sec on Ubuntu.
  • easy to use: must implement only 2 methods: update() and is_source() in which you call add_input/add_output and get_input/set_output.
  • portable: Tested on Windows 10(Visual Studio 2019), Debian VM(GCC 8.3) and Raspbian(GCC 4.9).
  • syncronous and asyncronous execution(based on execution order) available with the controller.
Clone and build

Clone and build:

	git clone https://github.com/mehecip/mbd.git
	cd mbd
	cmake -DBUILD_CONTROLLER=On -DBUILD_EXAMPLES=On .
	make f=Makefile

Usage - mbd::model

Implement:

	#include "model.hpp"

	class gain : public model
	{
	public:

		/** Build your model: add inputs, outputs and parameters. */
		gain(const std::string& name, double gain) : model(name)
		{
			model::add_input<double>("In 0", 0.0);
			model::add_output<double>("Out 0", 0.0);

			model::add_param<double>("gain_factor", gain);
		}

		/** Update your model: read inputs/parameters and set outputs/parameters. */
		void update(std::uint64_t tick) override
		{
			const double in = model::get_input<double>(0);
			const double gain = model::get_param<double>("gain_factor");
			
			model::set_output<double>(0, in * gain);
		}

		/** Let the controller know if the model behaves as a source. */
		bool is_source() const override
		{
			return false;
		}
	};
	

Register:

	mbd::lib my_lib("My Lib");
	my_lib.register_model<gain>("Times Pi", 3.1415);
Build - Connect - Run without controller

Build:

	auto gain_ = my_lib.build_model("Times Pi");
	auto src_ = my_lib.build_model("Liniar Source");
	auto sink_ = my_lib.build_model("Sink");

Connect:

	mbd::end_point src_0{src_, 0, port_dir_t::OUT};
	mbd::end_point gain_0{gain_, 0, port_dir_t::IN};

	auto [state, src_to_gain] = connection::build(src_0, gain_0);

	/**************************************************************
		| Liniar Source |0>-------->0| Gain |0>-------->0| Sink | 
	***************************************************************/

Execute (in the correct order):

	for (std::uint64_t i = 0; i < 10; ++i)
	{
		src_->update(i);
		gain_->update(i);
		sink_->update(i);
	}

Usage - mbd::controller

Create the controller:

	#include "controller.hpp"
	
	void message_callback(log_level lvl, const std::string& msg)
	{
		std::cout << level_info(lvl) << ": " << msg << "\n";
	}
	
	mbd::controller cntrl(message_callback);

Add the models:

	cntrl.add_library(my_lib);

	cntrl.add_model("My Lib", "Times Pi");
	cntrl.add_model("My Lib", "Liniar Source");
	cntrl.add_model("My Lib", "Sink");

Connect the models:

	cntrl.connect("Liniar Source", 0, "Times Pi", 0);
	cntrl.connect("Times Pi", 0, "Sink", 0);

	/**************************************************************
		| Liniar Source |0>-------->0| Gain |0>-------->0| Sink | 
	***************************************************************/

Find algebraic loops:

	std::size_t n_loops = cntrl.find_algebraic_loops();

Calculate execution order and run all models:

	// syncronous
	cntrl.run(10'000);
	
	// or asyncronous
	cntrl.run_async(10'000);

Get:

	auto sink_ = cntrl.get<sink>("Sink");
	double value = sink_->read();

ToDO:

Implement mbd::view

mbd's People

Contributors

mehecip avatar mehepi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

mfkiwl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.