mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 01:53:58 +02:00
Create command line options for orbit trace
This commit is contained in:
parent
f214b48dbf
commit
b7f459e36a
10 changed files with 266 additions and 97 deletions
|
@ -10,59 +10,46 @@ using namespace ns3;
|
|||
|
||||
NS_LOG_COMPONENT_DEFINE ("LeoCircularOrbitTracingExample");
|
||||
|
||||
ofstream outfile ("leo-circular-orbit-tracing-example.csv");
|
||||
|
||||
void CourseChange (std::string context, Ptr<const MobilityModel> position)
|
||||
{
|
||||
Vector pos = position->GetPosition ();
|
||||
Ptr<const Node> node = position->GetObject<Node> ();
|
||||
outfile << Simulator::Now () << ":" << node->GetId () << ":" << pos.x << ":" << pos.y << ":" << pos.z << ":" << position->GetVelocity ().GetLength() << std::endl;
|
||||
std::cout << Simulator::Now () << ":" << node->GetId () << ":" << pos.x << ":" << pos.y << ":" << pos.z << ":" << position->GetVelocity ().GetLength() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
class Orbit {
|
||||
public:
|
||||
Orbit (double a, double i, double p, double s) : alt (a), inc (i), planes (p), sats (s) {}
|
||||
double alt;
|
||||
double inc;
|
||||
uint16_t planes;
|
||||
uint16_t sats;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::vector<Orbit> orbits = {
|
||||
Orbit (1150, 53.0, 32, 50),
|
||||
Orbit (1110, 53.8, 32, 50),
|
||||
// Orbit (1130, 74.0, 8, 50),
|
||||
// Orbit (1275, 81, 5, 75),
|
||||
// Orbit (1325, 70, 6, 75),
|
||||
};
|
||||
NodeContainer satellites;
|
||||
for (Orbit orb: orbits)
|
||||
{
|
||||
NodeContainer c;
|
||||
c.Create (orb.sats*orb.planes);
|
||||
|
||||
MobilityHelper mobility;
|
||||
mobility.SetPositionAllocator ("ns3::LeoCircularOrbitPostionAllocator",
|
||||
"NumOrbits", IntegerValue (orb.planes),
|
||||
"NumSatellites", IntegerValue (orb.sats));
|
||||
mobility.SetMobilityModel ("ns3::LeoCircularOrbitMobilityModel",
|
||||
"Altitude", DoubleValue (orb.alt),
|
||||
"Inclination", DoubleValue (orb.inc),
|
||||
"Precision", TimeValue (Minutes (1)));
|
||||
mobility.Install (c);
|
||||
satellites.Add (c);
|
||||
}
|
||||
CommandLine cmd;
|
||||
std::string orbitFile;
|
||||
std::string traceFile;
|
||||
Time duration;
|
||||
cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile);
|
||||
cmd.AddValue("traceFile", "CSV file to store mobility trace in", traceFile);
|
||||
cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel::Precision");
|
||||
cmd.AddValue("duration", "Duration of the simulation", duration);
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
LeoOrbitNodeHelper orbit;
|
||||
NodeContainer satellites = orbit.Install (orbitFile);
|
||||
|
||||
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
|
||||
MakeCallback (&CourseChange));
|
||||
|
||||
outfile << "Time,Satellite,x,y,z,Speed" << std::endl;
|
||||
std::streambuf *coutbuf = std::cout.rdbuf();
|
||||
// redirect cout if traceFile is specified
|
||||
std::ofstream out;
|
||||
out.open (traceFile);
|
||||
if (out.is_open ())
|
||||
{
|
||||
std::cout.rdbuf(out.rdbuf());
|
||||
}
|
||||
|
||||
Simulator::Stop (Hours (1));
|
||||
std::cout << "Time,Satellite,x,y,z,Speed" << std::endl;
|
||||
|
||||
Simulator::Stop (duration);
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
out.close ();
|
||||
std::cout.rdbuf(coutbuf);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue