A channel for sending double values to and from Process objects.
Here is an example that uses channels that enables a model of a car and a simple cruise controller to communicate.
#include <iostream>
#include <chrono>
#include "elma.h"
using std::vector;
public:
void init() {}
void start() {
velocity = 0;
}
void update() {
force = channel("Throttle").latest();
}
velocity += ( delta() / 1000 ) * ( - k * velocity + force ) / m;
channel("Velocity").send(velocity);
std::cout << "t: " << milli_time() << " ms\t"
<< " u: " << force << " N\t"
<< " v: " << velocity << " m/s\n";
}
void stop() {}
private:
double velocity;
double force;
const double k = 0.02;
const double m = 1000;
};
class CruiseControl :
public Process {
public:
void init() {}
void start() {}
void update() {
speed = channel("Velocity").latest();
}
channel("Throttle").send(-KP*(speed - desired_speed));
}
void stop() {}
private:
double speed = 0;
const double desired_speed = 50.0,
KP = 314.15;
vector<double> _v;
};
}
int main() {
}
Definition at line 21 of file channel.h.