### Quick start: launch and enable plugins manually Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Launch the app with all plugins enabled, or manually enable selective plugins. The onStart method begins the simulation. Use this when you need to control which plugins are active. ```matlab % Launch with all plugins enabled run_SwarmFly % Or launch manually with selective plugins app = SwarmFly(); app.enablePlugin('fault_injection'); app.enablePlugin('metrics'); app.onStart(); % Begin simulation ``` -------------------------------- ### Enable plugins in run_SwarmFly.m Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Shows the three ways to enable plugins: automatic (default), selective via app.enablePlugin, and via GUI. Use this when setting up which plugins should run. ```matlab % 1. Automatic (in run_SwarmFly.m - enabled by default) app.enableAllPlugins(); % 2. Selective app.enablePlugin('fault_injection'); app.enablePlugin('metrics'); % 3. Via GUI % Go to the Modules tab and check the box next to any plugin ``` -------------------------------- ### Plugin lifecycle state machine Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Describes the plugin lifecycle: startup discovery, enabling, per-tick execution, and disabling. Use this to understand when plugin callbacks are invoked. ```text Startup discoverPlugins() Scans plugins/ for swf_*.m files For each file: calls the function, gets the plugin struct Registers in PluginRegistry, sets PluginEnabled.(id) = false User enables plugin (checkbox or app.enablePlugin) PluginEnabled.(id) = true PluginStates.(id) = struct() Empty state container onLoad(app) Plugin initializes its data buildTab(app, tab) Plugin builds its GUI tab Simulation running (every tick) simStep() Physics engine runs Telemetry recorded For each enabled plugin with hasStep: plugin.onStep(app) Plugin reads/writes app state Map graphics updated drawnow limitrate User disables plugin (uncheck or app.disablePlugin) PluginEnabled.(id) = false onUnload(app) Plugin cleans up Tab deleted PluginStates.(id) removed ``` -------------------------------- ### Project file structure (SwarmFly directory tree) Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Required directory layout for the SwarmFly project. Preserve this structure so the application and its plugins are discovered correctly. ```text SwarmFly/ SwarmFly.m run_SwarmFly.m README.md plugins/ swf_plugin_template.m swf_fault_injection.m swf_metrics.m swf_battery.m swf_collision.m swf_scenario_runner.m swf_3d_view.m swf_geofence.m swf_map_polish.m ``` -------------------------------- ### Plugin struct template (MATLAB) Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Returns a struct with required and optional plugin fields, plus callback function handles. Copy this template to create a new plugin. The plugin ID must be a valid MATLAB field name (no spaces, no leading digits). Callbacks are optional; set to [] to skip. ```matlab function plugin = swf_yourname() % --- REQUIRED --- plugin.id = 'yourname'; % Valid MATLAB field name (no leading digits) plugin.name = 'Your Plugin'; % Display name in Modules tab % --- OPTIONAL --- plugin.description = 'What it does.'; % Shown in detail panel plugin.version = '1.0'; % Version string plugin.hasTab = true; % Creates a GUI tab when enabled plugin.hasStep = true; % onStep called every sim tick plugin.hasToolbar = false; % Reserved for future use % --- CALLBACKS (function handles, or [] to skip) --- plugin.onLoad = @(app) init(app); plugin.onUnload = @(app) cleanup(app); plugin.buildTab = @(app, tab) buildUI(app, tab); plugin.onStep = @(app) update(app); end ``` -------------------------------- ### Plugin state API usage Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Shows how to store and retrieve plugin state using app.setState and app.getState. Use the plugin's own id as the namespace to avoid collisions. ```matlab % Store a value app.setState('my_plugin', 'key', value); % Retrieve a value (returns [] if not found) val = app.getState('my_plugin', 'key'); ``` -------------------------------- ### Launch SwarmFly from MATLAB command line Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Run this command in MATLAB after navigating to the SwarmFly directory. It opens the application window, enables plugins automatically, and attempts GPS acquisition. ```matlab run_SwarmFly ``` -------------------------------- ### Programmatic API usage in MATLAB Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Shows how to control the SwarmFly simulation from the MATLAB Command Window using the app handle. Covers simulation start/stop/reset, mode and parameter changes, UAV position/telemetry access, waypoint setting, plugin management, custom tab creation, logging, and data export. All methods are public and accessible via the app handle. ```matlab % --- Simulation Control --- app.onStart() % Start simulation app.onStop() % Stop simulation app.onReset() % Reset to initial formation % --- Mode & Parameters --- app.onModeChanged('Decentralized') % Switch swarm mode app.onLeaderChanged('UAV-2 (Bravo)') % Set leader (Leader-Follower mode) app.MaxSwarmDist = 80; % Set max swarm distance (m) app.CruiseAlt = 50; % Set cruise altitude (m) app.CruiseSpeed = 8; % Set cruise speed (m/s) app.WindSpeed = 5; % Set wind speed (m/s) app.WindDir = 90; % Set wind direction (degrees) % --- UAV Access --- pos = app.getUAVPosition(1); % Get [x, y, z] of UAV-1 app.setUAVPosition(2, [50 30 40]); % Override UAV-2 position tel = app.getTelemetry(3); % Get telemetry history struct for UAV-3 % --- Waypoints --- app.setWaypoints([50 50; 100 0; 50 -50; 0 0]); % --- Plugin Management --- app.enablePlugin('fault_injection'); % Enable single plugin app.disablePlugin('battery'); % Disable single plugin app.enableAllPlugins(); % Enable all discovered plugins app.discoverPlugins(); % Re-scan plugins/ folder % --- Plugin State --- app.setState('my_plugin', 'key', value); val = app.getState('my_plugin', 'key'); % --- Custom Tabs --- app.addCustomTab('My Tab', @(tab) uilabel(tab, 'Text', 'Hello')); % --- Logging --- app.logMsg('Custom log message'); % --- Data Export --- app.exportTelemetry(); % Opens save dialog for .mat file ``` -------------------------------- ### Programmatic API Source: https://github.com/abhishekphadke/swarmfly/blob/main/README.md Public methods and properties accessible from the MATLAB Command Window via the `app` handle. These methods control simulation, mode, waypoints, plugins, tabs, logging, and data export. ```APIDOC ## Programmatic API ### Description All public methods are accessible from the MATLAB Command Window via the `app` handle. This API allows control of simulation, mode and parameters, UAV access, waypoints, plugin management, plugin state, custom tabs, logging, and data export. ### Method N/A ### Endpoint N/A ### Parameters #### Properties - **UAVPositions** ([4x3] double) - Current x, y, z of each UAV - **UAVHeadings** ([4x1] double) - Current heading in radians - **UAVRoles** ({4x1} cell) - Role strings: leader, follower, relay, etc. - **TelHistory(k)** (struct) - Per-UAV telemetry (see Telemetry Data Format) - **SimTime** (double) - Current simulation clock (seconds) - **dt** (double) - Current time step (seconds) - **SwarmMode** (char) - Current mode string - **Waypoints** ([Nx2] double) - Waypoint coordinates [x, y] - **WaypointIdx** (double) - Index of next waypoint to reach - **IsRunning** (logical) - Whether simulation is active - **GPSAcquired** (logical) - Whether GPS lock was obtained - **MapOrigin** ([1x2] double) - Base station [lat, lon] - **NumUAVs** (double) - Number of UAVs (always 4) ### Request Example ```matlab % --- Simulation Control --- app.onStart() % Start simulation app.onStop() % Stop simulation app.onReset() % Reset to initial formation % --- Mode & Parameters --- app.onModeChanged('Decentralized') % Switch swarm mode app.onLeaderChanged('UAV-2 (Bravo)') % Set leader (Leader-Follower mode) app.MaxSwarmDist = 80; % Set max swarm distance (m) app.CruiseAlt = 50; % Set cruise altitude (m) app.CruiseSpeed = 8; % Set cruise speed (m/s) app.WindSpeed = 5; % Set wind speed (m/s) app.WindDir = 90; % Set wind direction (degrees) % --- UAV Access --- pos = app.getUAVPosition(1); % Get [x, y, z] of UAV-1 app.setUAVPosition(2, [50 30 40]); % Override UAV-2 position tel = app.getTelemetry(3); % Get telemetry history struct for UAV-3 % --- Waypoints --- app.setWaypoints([50 50; 100 0; 50 -50; 0 0]); % --- Plugin Management --- app.enablePlugin('fault_injection'); % Enable single plugin app.disablePlugin('battery'); % Disable single plugin app.enableAllPlugins(); % Enable all discovered plugins app.discoverPlugins(); % Re-scan plugins/ folder % --- Plugin State --- app.setState('my_plugin', 'key', value); val = app.getState('my_plugin', 'key'); % --- Custom Tabs --- app.addCustomTab('My Tab', @(tab) uilabel(tab, 'Text', 'Hello')); % --- Logging --- app.logMsg('Custom log message'); % --- Data Export --- app.exportTelemetry(); % Opens save dialog for .mat file ``` ### Response #### Success Response - **getUAVPosition(uavIdx)** returns [x, y, z] of specified UAV - **getTelemetry(uavIdx)** returns telemetry history struct - **getState(pluginID, key)** returns current plugin state value #### Response Example ```matlab pos = [44.5 55.1 50.0]; % Example position vector tel = struct('time', [...], 'alt', [...], ...); % Example telemetry struct val = 42; % Example state value ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.