From f8804533ccd7474f1aae91cb74654e0189c9a970 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Mon, 17 Aug 2020 11:52:53 +0200 Subject: [PATCH] Add animated plot for satellite positions --- .../leo-circular-orbit-tracing-example.cc | 41 +++++++++++++++++++ examples/wscript | 8 +++- utils/plot-satellites.gnuplot | 19 +++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 examples/leo-circular-orbit-tracing-example.cc create mode 100644 utils/plot-satellites.gnuplot diff --git a/examples/leo-circular-orbit-tracing-example.cc b/examples/leo-circular-orbit-tracing-example.cc new file mode 100644 index 0000000..0c11a20 --- /dev/null +++ b/examples/leo-circular-orbit-tracing-example.cc @@ -0,0 +1,41 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include "ns3/core-module.h" +#include "ns3/mobility-module.h" +#include "ns3/leo-module.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("LeoCircularOrbitTracingExample"); + +void CourseChange (std::string context, Ptr position) +{ + Vector pos = position->GetPosition (); + Ptr node = position->GetObject (); + std::cout << Simulator::Now () << "," << node->GetId () << "," << pos.x << "," << pos.y << "," << pos.z << "," << position->GetVelocity ().GetLength() << std::endl; +} + +int main(int argc, char *argv[]) +{ + NodeContainer c; + c.Create (600); + + MobilityHelper mobility; + mobility.SetPositionAllocator ("ns3::LeoCircularOrbitPostionAllocator", + "NumOrbits", IntegerValue (6), + "NumSatellites", IntegerValue (100)); + mobility.SetMobilityModel ("ns3::LeoCircularOrbitMobilityModel", + "Altitude", DoubleValue (1200.0), + "Inclination", DoubleValue (80.0), + "Precision", TimeValue (Minutes (1))); + mobility.Install (c); + + Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", + MakeCallback (&CourseChange)); + + std::cout << "Time,Satellite,x,y,z,Speed" << std::endl; + + Simulator::Stop (Minutes (60.0)); + Simulator::Run (); + Simulator::Destroy (); +} diff --git a/examples/wscript b/examples/wscript index 5903ffe..51903d1 100644 --- a/examples/wscript +++ b/examples/wscript @@ -1,4 +1,10 @@ # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- def build(bld): - pass + if not bld.env['ENABLE_EXAMPLES']: + return; + + obj = bld.create_ns3_program('leo-circular-orbit-trace', + ['core', 'leo', 'mobility']) + obj.source = 'leo-circular-orbit-tracing-example.cc' + diff --git a/utils/plot-satellites.gnuplot b/utils/plot-satellites.gnuplot new file mode 100644 index 0000000..5acccc3 --- /dev/null +++ b/utils/plot-satellites.gnuplot @@ -0,0 +1,19 @@ +set datafile separator comma +set key autotitle columnheader +set terminal gif animate +set output 'output.gif' + +unset xtics +unset ytics +unset ztics +unset border +set hidden3d +unset key +set view equal xyz + +n=600 + +do for [j=0:100] { + set title 'time '.j + splot 'somefile' using 3:4:5:2 every ::(j*n)::((j+1)*n) +}