37 if ( channel(
"Throttle").nonempty() ) {
38 force = channel(
"Throttle").latest();
40 velocity += ( delta() / 1000 ) * ( - k * velocity + force ) / m;
41 channel(
"Velocity").send(velocity);
42 std::cout << milli_time() <<
"," 52 const double k = 0.02;
53 const double m = 1000;
69 watch(
"desired speed", [
this](
Event& e) {
70 desired_speed = e.
value();
81 if ( channel(
"Velocity").nonempty() ) {
82 speed = channel(
"Velocity").latest();
84 channel(
"Throttle").send(-KP*(speed - desired_speed));
92 double desired_speed = 0.0;
93 const double KP = 314.15;
117 if ( desired_speed == 50 ) {
122 emit(
Event(
"desired speed", desired_speed));
129 double desired_speed;
void init()
Watch for events that change the desired speed.
void init()
Nothing to do to initialize.
The Process Manager class.
void stop()
Nothing to do to stop.
void start()
Nothing to do to initialize.
Manager & schedule(Process &process, high_resolution_clock::duration period)
Example: A cruise controller for a Car process. See examples/driving.cc.
CruiseControl(std::string name)
Manager & run(high_resolution_clock::duration runtime)
void init()
initialize the desired speed
Events that can be emitted, watched, and responded to with event handlers.
Manager & add_channel(Channel &)
void stop()
Nothing to do to stop.
Example: Another car simulation process. See examples/driving.cc.
void stop()
Nothing to do to stop.
Example: A simulated driver, who keeps cycling between 50 and 60 kph. See examples/driving.cc.
A channel for sending double values to and from Process objects.
void start()
Nothing to do to start.
An abstract base class for processes.