sac-base is the base crate of its two child crates sac-control and sac-signal. This crate is still under heavy construction and not finished.
The sac-* crates help to implement signal processing and control systems in a network based approach. Similar to to Simulink as example. The project is designed for a primary usage on embedded systems and is therefore a [no_std] crate. A generic solution such as the used network based approach will never be as fast as a custom system implementation for a specific problem. But it will allow to directly and quickly implement and change systems in code instead of designing it Matlab and exporting it to C. Generation the network and building the topology is relatively expensive. Therefore the crate does all the allocations and setup before the normal operation starts. This base crate is designed in a way that allows the Signal and the Control crate to easily extend it, and allow the operations to be interchangeable between each other. Both the sac-control and the sac-signal are under construction and are not available yet.
The base crate provides the following features: - Network description. - Base node implementation which the operations are based on. - Simple math operations such as adding, subtraction. Generally operations that will be used in both the Signal and Control crates. - Generic elements such as buffers.
The library is built with no_std. Therefore it can be used on embedded systems and while not tested, probably wasm aswell.
The following example, can be build by the code given below:
```rust // // +----+ // | | // +--+ In +----+ // | | | +-----+ // +----+ +---+ | // | Add +----+-------------+ // +----+ +---+ | | | // | | | +-----+ | | +-----+ // +--+ In +----+ | +-----+ | // | | | | Mul +------+---+ // +----+ | +-----+ | | // | +-----+ | +-----+ | // +----+ +--+ | | | // | | | Add | | | // +--+ In +----------------------+ +----+ | // | | | | | // +----+ +-----+ | | // | +-----+ | // | +-----+ | // | | | | // +--------------+ z^1 +--------------+ // | | // +---- + //
use sacbase::network::network::Network; use sacbase::operations::math::add::Add; use sacbase::operations::miscellaneous::buffer::Buffer; use sacbase::operations::math::multiply::Multiply; // Generate the network let mut network = Network::new(); // Generate some operations let add1 = network.addoperation(Add::new()); let mul1 = network.addoperation(Multiply::new()); let add2 = network.addoperation(Add::new()); // Add some inputs let in1 = network.addinput(Buffer::new()); let in2 = network.addinput(Buffer::new()); let in3 = network.addinput(Buffer::new()); // Connect the operations with each other network.addconnection(&in1, &add1).unwrap(); network.addconnection(&in2, &add1).unwrap(); network.addconnection(&add1, &add2).unwrap(); network.addconnection(&in3, &add2).unwrap(); network.addconnection(&add1, &mul1).unwrap(); network.addconnection(&add2, &mul1).unwrap(); // Register the multiplication as an output network.asoutput(&mul1); // Insert a closed loop (Positive feedback loop) network.closeloop(&mul1, &add2); // Generate the network network.build(); // Main loop operation // Update the inputs network.setinputs(| index | { return 5.0; }); // Iterate over the network network.process(); let res = network.getoutputs(); // Update the inputs network.setinputs(| index | { return 10.0; }); // Process twice to let the closed loop propagate network.process(); let res = network.getoutputs(); ```
It is likely that the library does not implement all the operations that will be needed in your application. Implementing a new operation is simple and can be added outside of the library.
As example: Lets say you want to add a new operation that drops every third element. ```rust // we need a possibility to count. So we need to add a count variable to the struct which will // be boxed and moved into the node use sacbase::network::node::Node; use std::any::Any; use sacbase::network::network::Network; pub struct Third { count: usize, }
// Now define the functionality
impl Third {
pub fn new
let mut network: Network
// Insert the new node into the network let third = network.add_operation(Third::new());
network.build();
network.setinputslice(&third, &[1.0, 2.0, 3.0][..]);
network.process(); let res = network.get_output(&third).unwrap();
assert_eq!(res, [1.0, 2.0, 3.0]); ```