Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger SendFrame() api for CAN relevant participants for a cyclic interval #187

Open
AmanChaturvedi24 opened this issue Mar 5, 2025 · 3 comments
Assignees

Comments

@AmanChaturvedi24
Copy link

I have a co-simulation where participnats are communicating over CAN api (OperationMode :: Coordinated)

  • Inside the SetSimulationStepHandler i have various function which triggers SendFrame() api's respectively
  • I am hoping to trigger certain of these functions with a particular interval.
    For example :
    my StepSize is 10 ms and i want certain functions to be triggered for every 2 ms per simulation cycle
    So in ideal case, such function should be triggered 5 times per simulation cycle

Is this something that could be achieved with the current version ?

@VDanielEdwards VDanielEdwards self-assigned this Mar 6, 2025
@VDanielEdwards
Copy link
Member

VDanielEdwards commented Mar 6, 2025

Hello @AmanChaturvedi24, thank you for your question!

Im not 100% sure that I understand your issue correctly, if the following isn't what you meant, please clarify.

When using SIL Kit with time-synchronization, the participant only sees steps with the duration you specified when registering the simulation step handler. The outgoing messages will be annotated with the timestamp you are informed about in the simulation step handlers now argument. There is no way for a SIL Kit participant to produce messages with 'intermediate' timestamps.

If your simulation doesn't care about the timestamps, and also doesn't care that the frames arrive 'together' (from the point of view of another participant), just send the five frames in the desired order during the simulation step handler.

If the timestamps are important to you, identify the smallest required time step and use that when registering the simulation step handler. You will get more invocations of the simulation step handler, but also get the required timestamps. You will likely have to adjust the logic such that it can deal with these smaller steps.

EDIT (VDanielEdwards): Fixed typo

@AmanChaturvedi24
Copy link
Author

HI @VDanielEdwards,
Thanks for the quick reply,
You got my point as "There is no way for a SIL Kit participant to produce messages with 'intermediate' timestamps." this clears my doubt,
However regarding the last paragraph i didn't get it fully as in my case i am having multiple SendFrame Api's sending different payloads under SetSimulationStepHandler, you can have a look in below picture

Image

even if i change my step size to a lesser value lets say 100ms i still did not get how can trigger the SendFrame_3 after every 10 ms so that in one simulation cycle it will get executed 10 times with specific interval in between (i.e. 10ms virtual time).

@VDanielEdwards
Copy link
Member

VDanielEdwards commented Mar 6, 2025

I meant to use the simulation step handler like this:

using namespace std::chrono_literals; // for the ...ms literal suffix

// ...

timeSyncService->SetSimulationStepHandler(
    [&](std::chrono::nanoseconds now, std::chrono::nanoseconds duration)
    {
        if (now % 1000ms == 0ms)
        {
            SendFrame_1(canController_1, logger);
        }

        if (now % 1000ms == 200ms)
        {
            SendFrame_2(canController_2, logger);
        }

        if (now % 1000ms == 400ms)
        {
            SendFrame_3(canController_3, logger);
        }

        // ...
    },
    100ms);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants