【问题标题】:Waiting time in S-functionS-Function 中的等待时间
【发布时间】:2014-04-01 11:50:16
【问题描述】:

我正在尝试使用 S-Function(C 语言)在 Simulink 中创建一个闪烁过程,我需要发送一些帧,两个连续帧之间的时间应该是 200 毫秒。我怎样才能实现这个等待时间?有没有实现的可能?

【问题讨论】:

    标签: matlab simulink s-function


    【解决方案1】:

    如果您想每 200 毫秒更新一次,请将您的 S-Function 放入每 200 秒触发一次的子系统中。

    【讨论】:

    • 或者给它一个200ms的采样时间,每200ms调用对应的model_stepX函数。 (参见多任务 grt main)
    • 我希望这个等待时间在函数中,我不要
    • 如果让它在函数中等待,则无法执行其他块。这是故意的吗?
    • 我希望这个等待时间在函数中,而不是每 200 毫秒执行一次的函数
    • 您应该在 S-Function 中使用 mdlGetTimeOfNextVarHit 方法来指定下一次对块进行采样的时间。
    【解决方案2】:

    您可以在下面找到我在函数中遵循的步骤:

    1.create first frame
    2.send first frame
    3.save the time when I send first frame
    4.if(current_time - time_send_FF == x ms)
        5. calculate nr of consecutive frame
        6. for each consecutive frame
            7. create consecutive frame
            8. send consecutive frame
            9. save the time when I send consecutive frame 
            10. if(current_time - time_send_CF == x ms)
                11. jump to step 6
            else 
                12. check again if(current_time - time_send_CF == x ms)
       else
            13.check again  if(current_time - time_send_FF == x ms)
    

    问题是我无法存储发送第一个/连续帧的时间,因为即使我使用全局 DWOrk/RWork 数组,它也会不断增加,当我尝试计算 current_time 和 time_send_FF 之间的差异时,结果始终为 0。 我可以使用时钟块作为输入来访问系统时间。我应该尝试什么其他方法... 谢谢!

    【讨论】:

    • 一个工作向量不会自动增加,它的值只有在你写入它时才会改变,所以其他事情正在发生。在您上面的代码中,您没有显示您在什么时候获得不同的时间(也没有显示您是在谈论模拟时间还是系统时间)。我怀疑时差正好是 x 的可能性几乎可以忽略不计。
    • 这正是我想要做的,但我无法获得例如 system_time_global_variable time ,它不是恒定的,它总是在变化,并且 ssGetT(S) -system_time_global_variable 之间的差异总是0. 只发送第一帧和最后一帧:link
    猜你喜欢
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 2020-05-04
    • 2022-10-18
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 2022-11-03
    相关资源
    最近更新 更多