{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Broadcast Communication\n", "\n", "By default, communication occurs between all satellites that are specified by the communication\n", "method. This tutorial shows how to use two classes to configure a broadcast action that must be\n", "taken for communication to occur:\n", "\n", "* [Broadcast](../api_reference/act/index.html#bsk_rl.act.Broadcast), which gives satellites an action\n", " that enables communication from them at the end of the current step.\n", "* [BroadcastCommunication](../api_reference/comm/index.html#bsk_rl.comm.BroadcastCommunication), which\n", " can be combined with another communication method to limit communication from broadcasters to\n", " those satellites satisfying the requirements of the other communication method.\n", "\n", "## Configuring the Environment\n", "\n", "For this example, a multisatellite target imaging environment will be used. The goal is\n", "to maximize the value of unique images taken. This configuration is similar to the \n", "[Multi-Agent Environments](../examples/multiagent_envs.html) example." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from bsk_rl import sats, act, obs, scene, data, comm\n", "from bsk_rl.sim import dyn, fsw\n", "\n", "\n", "class ImagingSatellite(sats.ImagingSatellite):\n", " observation_spec = [\n", " obs.OpportunityProperties(\n", " dict(prop=\"priority\"),\n", " dict(prop=\"opportunity_open\", norm=5700.0),\n", " n_ahead_observe=4,\n", " )\n", " ]\n", " action_spec = [act.Broadcast(duration=15.0), act.Image(n_ahead_image=4)]\n", " dyn_type = dyn.FullFeaturedDynModel\n", " fsw_type = fsw.SteeringImagerFSWModel\n", "\n", "\n", "ACTION_BROADCAST = 0\n", "ACTION_IMAGE_0 = 1\n", "ACTION_IMAGE_1 = 2\n", "ACTION_IMAGE_2 = 3\n", "ACTION_IMAGE_3 = 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Satellite properties are set to give the satellite near-unlimited power and storage resources. To randomize some parameters in a correlated manner across satellites, a ``sat_arg_randomizer`` is set and passed to the environment. In this case, the satellites are distributed in a trivial single-plane Walker-delta constellation." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from bsk_rl.utils.orbital import walker_delta_args\n", "\n", "N_AGENTS = 2\n", "sat_args = dict(\n", " imageAttErrorRequirement=0.01,\n", " imageRateErrorRequirement=0.01,\n", " batteryStorageCapacity=1e9,\n", " storedCharge_Init=1e9,\n", " dataStorageCapacity=1e12,\n", " u_max=0.4,\n", " K1=0.25,\n", " K3=3.0,\n", " omega_max=0.087,\n", " servo_Ki=5.0,\n", " servo_P=150 / 5,\n", ")\n", "sat_arg_randomizer = walker_delta_args(\n", " altitude=800.0, inc=60.0, n_planes=1, clustersize=N_AGENTS, clusterspacing=5.0\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A communication type is defined that uses multidegree line-of-sight communication with broadcasting." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class BroadcastLOS(comm.BroadcastCommunication, comm.LOSMultiCommunication):\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, the environment can be instantiated." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from bsk_rl import ConstellationTasking\n", "\n", "env = ConstellationTasking(\n", " satellites=[ImagingSatellite(f\"EO-{i + 1}\", sat_args) for i in range(N_AGENTS)],\n", " scenario=scene.UniformTargets(1000),\n", " rewarder=data.UniqueImageReward(),\n", " communicator=BroadcastLOS(),\n", " sat_arg_randomizer=sat_arg_randomizer,\n", " log_level=\"INFO\",\n", ")\n", "_ = env.reset()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the first step, both agents are tasked with an imaging action, and one successfully images a target." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_ = env.step({\"EO-1\": ACTION_IMAGE_3, \"EO-2\": ACTION_IMAGE_2})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When both select the broadcast action, data is shared in both directions. This is subject to line-of-sight availability as well as selecting the correct action." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_ = env.step({\"EO-1\": ACTION_BROADCAST, \"EO-2\": ACTION_BROADCAST})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One agent can broadcast while the others are completing a different task." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_ = env.step({\"EO-1\": ACTION_IMAGE_2, \"EO-2\": ACTION_BROADCAST}) # Agent 1 broadcasts" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" } }, "nbformat": 4, "nbformat_minor": 2 }