actuator_init.cpp
来自「一个很棒的网络控制系统仿真软件」· C++ 代码 · 共 60 行
CPP
60 行
// Distributed control system: actuator node//// Receives messages from the controller and actuates // the plant.#define S_FUNCTION_NAME actuator_init#include "ttkernel.cpp"// code functiondouble act_code(int seg, void *data) { static double *u; switch (seg) { case 1: ttWait("packet"); return 0.0; case 2: return 0.0005; case 3: u = (double *)ttGetMsg(); // Receive message if (u != NULL) { ttAnalogOut(1, *u); delete u; // delete message } ttSetNextSegment(1); // loop and wait for new packet return 0.0; }}double msgRcvhandler(int seg, void *data){ ttNotifyAll("packet"); return FINISHED;}void init(){ // Initialize TrueTime kernel ttInitKernel(0, 1, FP); // nbrOfInputs, nbrOfOutputs, fixed priority // Actuator task double deadline = 100.0; double prio = 1.0; ttCreateTask("act_task", deadline, prio, act_code); ttCreateJob("act_task"); // Initialize network ttCreateInterruptHandler("msgRcv", prio, msgRcvhandler); ttInitNetwork(2, "msgRcv"); // node #2 in the network ttCreateEvent("packet");}void cleanup() {}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?