第一范文网 - 专业文章范例文档资料分享平台

Truetime网络仿真 (4)

来源:用户分享 时间:2020-06-22 本文由柠檬脾气 分享 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

消息。

ttInitNetwork(2, 'nw_handler'); % node #2 in the network初始化网络接口,网络数目,当事件到达时,激发的端口名称

2. function [exectime, data] = actcode(seg, data)

switch seg, case 1,

data.u = ttGetMsg; 从网络输入队列中获取信息 exectime = 0.0005;执行时间 case 2,

ttAnalogOut(1, data.u) 设定输出通道值,通道号,通道值 exectime = -1; % finished end

3. function controller_init(arg) 控制器初始化

% Distributed control system: controller node %

% Receives messages from the sensor node, computes control signal % and sends it to the actuator node. Also contains a high-priority % disturbing task.

% Initialize TrueTime kernel

ttInitKernel(1, 0, 'prioFP'); % nbrOfInputs, nbrOfOutputs, fixed priority初始化内核,设置功能块输入、输出端口的数目和调度策略

% Controller parameters 控制器参数设置,h为采样周期,N为采样次数 h = 0.010; N = 100000; Td = 0.035; K = 1.5;

% Create task data (local memory) data.u = 0.0; data.K = K; data.ad = Td/(N*h+Td); data.bd = N*K*Td/(N*h+Td); data.Dold = 0.0; data.yold = 0.0; % Create controller task deadline = h; prio = 2;

ttCreateTask('pid_task', deadline, prio, 'ctrlcode', data); 任务名称,最终期限(截止期),代码名称 % Optional disturbance task 随机扰动任务 if arg > 0 offset = 0.0002; period = 0.007; prio = 1;

ttCreatePeriodicTask('dummy', offset, period, prio, 'dummycode'); 对于时钟驱动的节点,调用ttCreatPeriodicTask函数,设置周期性的任务调度策略,以实现定时采样功能。

end

% Initialize network

ttCreateInterruptHandler('nw_handler', prio, 'msgRcvCtrl'); 对于事件驱动的节点,调用

ttCreateInterruptHandler函数,设置中断式消息调度策略,使节点在接受到网络数据后触发相应的消息。

ttInitNetwork(3, 'nw_handler'); % node #3 in the network,初始化网络接口,网络数目,当事件到达时,激发的端口名称

4. function [exectime, data] = ctrlcode(seg, data)

switch seg, case 1,

y = ttGetMsg; % Obtain sensor value,从网络输入队列中获取信息 r = ttAnalogIn(1); % Read reference value,从输入通道取值 P = data.K*(r-y);

D = data.ad*data.Dold + data.bd*(data.yold-y); data.u = P + D; data.Dold = D; data.yold = y; exectime = 0.0005; case 2,

ttSendMsg(2, data.u, 80); % Send 80 bits to node 2 (actuator),在网络上发送信息,发送数据内容的80个字节到执行器节点2 exectime = -1; % finished end

5. function [exectime, data] = dummycode(seg, data) 虚拟节点功能

switch seg, case 1, exectime = 0.004; case 2, exectime = -1; end

6. function [exectime, data] = interfcode(seg, data) 干扰节点功能

BWshare = 0.0; % Fraction of the network bandwidth occupied by this node 节点占用网络带宽 if (rand(1) < BWshare)

ttSendMsg(1, 1, 80); % send 80 bits to myself,发送80个字节给自己 end exectime = -1;

7. function interference_init

% Distributed control system: interference node 离散控制系统的干扰节点 % Generates disturbing network traffic. 产生网络干扰通信量 % Initialize TrueTime kernel

ttInitKernel(0, 0, 'prioFP'); % nbrOfInputs, nbrOfOutputs, fixed priority,初始化内核,设置功能块输入、输出端口的数目和调度策略 % Create sender task 创建发送任务 offset = 0;

period = 0.001; prio = 1;

ttCreatePeriodicTask('interf_task', offset, period, prio, 'interfcode'); % Initialize network

ttCreateInterruptHandler('nw_handler', prio, 'msgRcvInterf'); 对于事件驱动的节点,调用

ttCreateInterruptHandler函数,设置中断式消息调度策略,使节点在接受到网络数据后触发相应的消息。

ttInitNetwork(1, 'nw_handler'); % node #1 in the network,初始化网络节点1

8. function [exectime, data] = msgRcvActuator(seg, data) 执行器与网络连接的信号端口功能

ttCreateJob('act_task') 创建任务,任务名称,负责激发到达的任务 exectime = -1;

9. function [exectime, data] = msgRcvCtrl(seg, data) 控制器与网络连接的信号端口功能

ttCreateJob('pid_task') exectime = -1;

10. function [exectime, data] = msgRcvInterf(seg, data) 干扰节点与网络连接的信号端口功能

msg = ttGetMsg; exectime = -1;

11. function [exectime, data] = msgRcvSensor(seg, data) 传感器节点与网络连接的信号端口功能

disp('ERROR: sensor received a message'); exectime = -1;

12. function [exectime, data] = senscode(seg, data) 传感器节点功能

switch seg, case 1,

data.y = ttAnalogIn(1); 从输入通道取值 exectime = 0.00005; case 2,

ttSendMsg(3, data.y, 80); % Send message (80 bits) to node 3 (controller)发送80个字节到节点3(控制器) exectime = 0.0004; case 3,

exectime = -1; % finished end

13. function sensor_init 传感器初始化

% Distributed control system: sensor node

% Samples the plant periodically and sends the samples to the controller node. % Initialize TrueTime kernel

ttInitKernel(1, 0, 'prioFP'); % nbrOfInputs, nbrOfOutputs, fixed priority,初始化内核,设置功能块输入、输出端口的数目和调度策略 % Create sensor task 建立传感器任务 data.y = 0; offset = 0; period = 0.010; prio = 1;

ttCreatePeriodicTask('sens_task', offset, period, prio, 'senscode', data); 对于时钟驱动的节点,调用

ttCreatPeriodicTask函数,设置周期性的任务调度策略,以实现定时采样功能。 % Initialize network 初始化网络

ttCreateInterruptHandler('nw_handler', prio, 'msgRcvSensor'); 对于事件驱动的节点,调用

ttCreateInterruptHandler函数,设置中断式消息调度策略,使节点在接受到网络数据后触发相应的消息。

ttInitNetwork(4, 'nw_handler'); % node #4 in the network

Distributed Control System:

包含了四个计算机节点,时钟驱动的传感器节点周期性的对过程进行采样,并通过网络传递给计算机节点。控制任务在这个节点上运算控制信号,并发送运算结果给执行器,立即执行。同时,干扰节点发送通过网络干扰信号,作为高优先级任务在计算机节点执行。 干扰节点占用网络的设置通过interfcode.m中的变量BWshare,当设置为零时表示没有干扰,同时,研究网络调度(高电平代表节点发送,中电平表示节点等待,低电平表示节点空闲)。 改变网络调度策略进行研究。

ttSendMsg/ttGetMsg stand-alone network blocks:

时间触发和事件触发两个实例表明单机网络模块用来模拟网络闭环控制系统。

在时间触发实例中,发送模块被脉冲发生器(周期为0.1s)触发,脉冲发生器的第二个节点有0.05s的相位延迟。比例控制器补偿白噪声的干扰。

在事件触发实例中,当过程输出幅值超过0.25时,发送模块被触发。控制器也是事件触发的,第二个发送模块轮流延迟0.001s被触发。 网络利用率

8个网络节点的仿真模型:

默认条件下的仿真结果及网络调度:

在令牌网下,传输速率为93.75Kbit/s,系统的输出和网络资源调度情况,调度策略为PrioRM(单调速率),(相同条件下,增加网络节点对控制系统性能的影响):

搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新幼儿教育Truetime网络仿真 (4)全文阅读和word下载服务。

Truetime网络仿真 (4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/wenku/1095010.html(转载请注明文章来源)
热门推荐
Copyright © 2018-2022 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top