Main Content

sendEvent

Send event to scenario

Since R2022b

    Description

    sendEvent(actorSim,"ActionComplete",ActionID) sends an event indicating completion of the user-defined action ActionID by the actor actorSim to a scenario.

    example

    sendEvent(actorSim,"UserDefinedEvent",eventName,eventStruct) sends a user-defined event by the actor actorSim to a scenario. eventName contains parameters in the structure eventStruct.

    example

    Examples

    collapse all

    Send an action completion event for the user-defined action named CustomBrakes.

    sendEvent(mActorHdl,"ActionComplete","CustomBrakes");

    Send a user-defined event named UD1 to a scenario.

     function interface = getInterfaceImpl(~) 
         import matlab.system.interface.*; 
         interface = ActorInterface(); 
         attribute = struct("ActorID",3);
         overtakeTruckEvent = matlab.system.interface.UserDefinedEvent("LaneChange",attribute); 
         addEvent(interface,"UserDefinedEvent",overtakeTruckEvent);  
     end
     function stepImpl(obj,~)
       for idx = 1:length(actorsim)
         redCar = actorsim(idx);
         id = double(getAttribute(redCar,"ID"));
         if(obj.HasSentEvent)
             sendEvent(obj.mActorSimulationHdl,"UserDefinedEvent","LaneChange",attribute);
         end
       end
     end

    Input Arguments

    collapse all

    Actor for which an event is sent, specified as an ActorSimulation object.

    Identifier of the completed action, specified as a string or character vector.

    Name of user-defined event sent to a scenario, specified as a string scalar or character vector. The user-defined event must be defined and added to the interface of a MATLAB® System object™ actor model through the getInterfaceImpl (Simulink) function.

    Name of event structure carrying parameters with corresponding values for a user-defined event, specified as a string scalar or character vector.

    The parameters can be of the following data types.

    • double

    • uint16

    • int32

    • uint32

    • string

    • logical

    Version History

    Introduced in R2022b

    expand all