主要内容

Simulate Mobility of Peripheral Node in Bluetooth Network

Since R2026a

Incorporate mobility for a Bluetooth® Peripheral node. You must create a Central and a Peripheral node, assign a mobility model to the Peripheral, and configure a Bluetooth connection between them. Choose random walk, random waypoint, or constant velocity as the mobility model. Then, run the simulation, and obtain the statistics for the Central and Peripheral nodes.

Initialize the wireless network simulator.

networkSimulator = wirelessNetworkSimulator.init;

Create the Bluetooth Central and Peripheral nodes.

centralNode = bluetoothLENode("central",Name="Central1");
peripheralNode = bluetoothLENode("peripheral",Name="Peripheral1",Position=[1 0 0]);

Initialize the wireless network viewer.

visualizer = wirelessNetworkViewer;

Add the Bluetooth Central and Peripheral nodes to the wireless network viewer.

addNodes(visualizer,[centralNode peripheralNode])

Select the mobility model for the Peripheral node. Create the selected mobility model and assign it to the Peripheral node.

mobilityModelOption = "Random Walk";
switch mobilityModelOption
    case "Random Walk"
        mobilityModel = nodeMobilityRandomWalk( ...
    BoundaryShape= "circle", ...
    Bounds=[0 0 20], ...           % Center at (0,0), radius 20
    SpeedRange=[1 2], ...          % Speed range between 1 and 2 (Units are in meters per second)
    WalkMode="distance", ...       % Change direction after a fixed distance
    Distance= 0.6, ...             % Change direction every 0.6 meters
    RefreshInterval= 0.1);         % Refresh every 0.1 seconds
    case "Random Waypoint"
        mobilityModel = nodeMobilityRandomWaypoint( ...
    BoundaryShape= "circle", ...
    Bounds=[0 0 20], ...           % Center at (0,0), radius 20
    SpeedRange=[1 2], ...          % Speed range between 1 and 2
    RefreshInterval= 0.1);         % Refresh every 0.1 seconds; 
    case "Constant Velocity"
        mobilityModel = nodeMobilityConstantVelocity( ...
    Velocity=[2 1 0], ...          % velocity vector in m/s along x, y, z axes
    RefreshInterval= 0.1);         % Refresh every 0.1 seconds;
end
addMobility(peripheralNode,MobilityModel=mobilityModel)

Create and configure the Bluetooth connection.

cfgConnection = bluetoothLEConnectionConfig;
configureConnection(cfgConnection,centralNode,peripheralNode)
ans = 
  bluetoothLEConnectionConfig with properties:

    ConnectionInterval: 0.0200
         AccessAddress: "5DA44270"
          UsedChannels: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36]
             Algorithm: 1
          HopIncrement: 5
     CRCInitialization: "012345"
    SupervisionTimeout: 1
               PHYMode: "LE1M"
         InstantOffset: 6
      ConnectionOffset: 0
          ActivePeriod: 0.0200
                MaxPDU: 251
                  TIFS: 1.5000e-04
                 TMCES: 1.5000e-04

Configure On-Off application traffic.

traffic = networkTrafficOnOff(DataRate=200,PacketSize=27,OnTime=inf);

Add traffic from the Central node to Peripheral node.

addTrafficSource(centralNode,traffic,DestinationNode=peripheralNode)

Add the nodes to the simulator.

addNodes(networkSimulator,[centralNode peripheralNode])

Set the simulation time.

simulationTime = 1;

Run the simulation.

run(networkSimulator,simulationTime)

Figure Wireless Network Viewer contains an axes object. The axes object with xlabel X-axis (m), ylabel Y-axis (m) contains 6 objects of type line, text. One or more of the lines displays its values using only markers This object represents bluetoothLENode.

Obtain the PHY statistics for the Central and Peripheral nodes.

centralStats = statistics(centralNode);
centralPHYStats = centralStats.PHY
centralPHYStats = struct with fields:
                ReceivedPackets: 914
                 DecodeFailures: 0
    InvalidAccessAddressPackets: 0
           InvalidLengthPackets: 0
                   ReceivedBits: 65808
               PacketCollisions: 0
            CoChannelCollisions: 0
              CollisionsWithBLE: 0
           CollisionsWithNonBLE: 0
     CollisionsWithBLEAndNonBLE: 0
             TransmittedPackets: 915
                TransmittedBits: 270840

peripheralStats = statistics(peripheralNode);
peripheralPHYStats = peripheralStats.PHY
peripheralPHYStats = struct with fields:
                ReceivedPackets: 915
                 DecodeFailures: 0
    InvalidAccessAddressPackets: 0
           InvalidLengthPackets: 0
                   ReceivedBits: 263232
               PacketCollisions: 0
            CoChannelCollisions: 0
              CollisionsWithBLE: 0
           CollisionsWithNonBLE: 0
     CollisionsWithBLEAndNonBLE: 0
             TransmittedPackets: 914
                TransmittedBits: 73120

See Also

Objects

Classes