Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions simulator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
<groupId>net.spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.12.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/spymemcached-2.12.3.jar</systemPath>
</dependency>
</dependencies>
<issueManagement>
Expand All @@ -56,4 +54,4 @@
</pluginManagement>
</build>
<groupId>msp.simulator</groupId>
</project>
</project>
11 changes: 7 additions & 4 deletions simulator/src/main/java/msp/simulator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ public static void main(String[] args) {
Dashboard.setSimulationDuration(1000000);

Dashboard.setIntegrationTimeStep(0.1);
Dashboard.setEphemerisTimeStep(1.0);
Dashboard.setSatelliteInertiaMatrix(SatelliteBody.satInertiaMatrix);
Dashboard.setEphemerisTimeStep(0.1);
Dashboard.setStepDelay(0.1);

Dashboard.setInitialAttitudeQuaternion(new Quaternion(1, 0, 0, 0));
Dashboard.setInitialSpin(new Vector3D(0.5, 0.5, 0.5));
Dashboard.setInitialSpin(new Vector3D(0.05, 0.05, 0.05));
Dashboard.setInitialRotAcceleration(new Vector3D(0,0,0));
Dashboard.setTorqueDisturbances(true);
Dashboard.setTorqueDisturbances(false);
//Dashboard.setSatelliteInertiaMatrix(SatelliteBody.satInertiaMatrix);
Dashboard.setSatelliteInertiaMatrix(SatelliteBody.ACRUX1InertiaMatrix);
//Dashboard.setSatelliteInertiaMatrix(SatelliteBody.simpleBalancedInertiaMatrix);

Dashboard.setCommandTorqueProvider(TorqueProviderEnum.MEMCACHED);
Dashboard.setMemCachedConnection(true, "127.0.0.1:11211");
Expand Down
6 changes: 4 additions & 2 deletions simulator/src/main/java/msp/simulator/NumericalSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class NumericalSimulator {
* Default value is Long.MAX_VALUE. */
public static long simulationDuration = Long.MAX_VALUE;

/** Wall clock time between computing steps of the simulation. */
public static double stepDelay = 0.1;

/** Real-time processing flag. */
public static boolean realTimeUserFlag = false;

Expand Down Expand Up @@ -215,8 +218,7 @@ public void process() {
scheduler.scheduleAtFixedRate(
mainSimulationTask,
0,
(long) (this.dynamic.getPropagation().getIntegrationManager()
.getStepSize() * 1000),
(long) (stepDelay * 1000),
TimeUnit.MILLISECONDS);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public static double[] computeEulerEquations(
* the Euler Equations of motion for a rotating rigid body.
*/
rotAcc[0] = (M1 - (I3 - I2) * W2 * W3) / I1 ;
rotAcc[1] = (M2 - (I1 - I3) * W3 * W1) / I1 ;
rotAcc[2] = (M3 - (I2 - I1) * W1 * W2) / I1 ;
rotAcc[1] = (M2 - (I1 - I3) * W3 * W1) / I2 ;
rotAcc[2] = (M3 - (I2 - I1) * W1 * W2) / I3 ;

return rotAcc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public Vector3D getTorque(AbsoluteDate date) {
}

/* Debug Information */
logger.debug("Torque Provider (Acquisition): " + date.toString() +" - " +
logger.info("Torque Provider (Acquisition): " + date.toString() +" - " +
this.stepTorque.toString());

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void executeMission(AbsoluteDate date) {
byte[] raan = MemcachedRawTranscoder.toRawByteArray(
Double.valueOf(tle.getLine2().substring(17, 25)));

byte[] eccentricity = MemcachedRawTranscoder.toRawByteArray(
byte[] eccentricity1e7 = MemcachedRawTranscoder.toRawByteArray(
Double.valueOf(tle.getLine2().substring(26, 33)));

byte[] argPerigee = MemcachedRawTranscoder.toRawByteArray(
Expand All @@ -175,7 +175,7 @@ public void executeMission(AbsoluteDate date) {
memcached.set("Simulation_TLE_Mean_Motion_First_Deriv" , 0, meanMotionFirstDerivative);
memcached.set("Simulation_TLE_Mean_Motion" , 0, meanMotion);
memcached.set("Simulation_TLE_Argument_Perigee" , 0, argPerigee);
memcached.set("Simulation_TLE_Eccentricity" , 0, eccentricity);
memcached.set("Simulation_TLE_Eccentricity_1e7" , 0, eccentricity1e7);
memcached.set("Simulation_TLE_Mean_Anomaly" , 0, meanAnomaly);
memcached.set("Simulation_TLE_Inclination" , 0, inclination);
memcached.set("Simulation_TLE_Bstar" , 0, bStar);
Expand Down Expand Up @@ -213,15 +213,15 @@ public void executeMission(AbsoluteDate date) {
+ "TLE_Epoch: " +
+ ByteBuffer.wrap(epoch).getDouble()
+ "\n"
+ "TLE_Eccentricity: " +
+ ByteBuffer.wrap(eccentricity).getDouble()
+ "TLE_Eccentricity_1e7: " +
+ ByteBuffer.wrap(eccentricity1e7).getDouble()
+ "\n"
+ "TLE_Argument_Perigee: " +
+ ByteBuffer.wrap(argPerigee).getDouble()
+ "\n"
+ "Raw : " + tle.getLine1()
+ "Raw: " + tle.getLine1()
+ "\n"
+ "Raw : " + tle.getLine2()
+ "Raw: " + tle.getLine2()
;

logger.info(tleUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Satellite(Environment environment) {
*/
public void executeStepMission() {
AbsoluteDate date = this.getStates().getCurrentState().getDate();

/* Export Sensor Measurements */
if (this.io.isConnectedToMemCached()) {

Expand Down Expand Up @@ -105,7 +105,7 @@ public void executeStepMission() {
);

/* Gyrometer Sensor Measurement */
Vector3D gyroMeasure = this.getSensors().getGyrometer().getData_rotAcc();
Vector3D gyroMeasure = this.getSensors().getGyrometer().getData_angularVelocity();
byte[] rawGyro_x = MemcachedRawTranscoder.toRawByteArray(gyroMeasure.getX());
byte[] rawGyro_y = MemcachedRawTranscoder.toRawByteArray(gyroMeasure.getY());
byte[] rawGyro_z = MemcachedRawTranscoder.toRawByteArray(gyroMeasure.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Assembly {

/** Logger of the class */
private static final Logger logger = LoggerFactory.getLogger(Assembly.class);

/** Earth instance of the simulation. */
private Earth earth;

Expand All @@ -46,9 +46,6 @@ public class Assembly {

/** Instance of the satellite initial state in space. */
private SatelliteStates satelliteStates;

/** Satellite frame. */
private Frame satelliteFrame;

/**
* Build the satellite as a body and a state vector.
Expand All @@ -62,11 +59,6 @@ public Assembly(Environment environment) {

this.satelliteBody = new SatelliteBody(environment);
this.satelliteStates = new SatelliteStates(environment, satelliteBody);
this.satelliteFrame = new Frame (
FramesFactory.getEME2000(),
this.getStates().getCurrentState().toTransform(),
"SatelliteFrame"
);
this.earth = environment.getSolarSystem().getEarth();
}

Expand Down Expand Up @@ -95,7 +87,11 @@ public SatelliteStates getStates() {
* frame fixed with the axis body.
*/
public Frame getSatelliteFrame() {
return this.satelliteFrame;
return new Frame (
FramesFactory.getEME2000(),
this.getStates().getCurrentState().toTransform(),
"SatelliteFrame"
);
}

/**
Expand All @@ -105,7 +101,7 @@ public Frame getSatelliteFrame() {
public Vector3D getAngularMomentum() {
Vector3D rotationRate = this.satelliteStates
.getCurrentState().getAttitude().getSpin();

double[][] inertiaMatrix = this.satelliteBody.getInertiaMatrix();

Vector3D row0 = new Vector3D(inertiaMatrix[0]);
Expand All @@ -130,13 +126,13 @@ public Transform getItrf2body(AbsoluteDate date) {
Transform itrf2body = null;
try {
itrf2body = this.earth.getRotatingFrame().getTransformTo(
this.satelliteFrame,
this.getSatelliteFrame(),
date
);
} catch (OrekitException e) {
e.printStackTrace();
}

return itrf2body;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,33 @@ public class SatelliteBody extends BoxAndSolarArraySpacecraft {
/* ******* Public Static Attributes ******* */

/** Size of the satellite box in meters - (x, y, z) */
public static double[] satBoxSizeWithNoSolarPanel = new double[] {0.01, 0.01, 0.01} ;
public static final double[] satBoxSizeWithNoSolarPanel = new double[] {0.01, 0.01, 0.01} ;

/* Note that the size of the solar panels is set to zero in the class constructor.*/

/** Mass of the satellite in kilogram. */
public static double satelliteMass = 1.04;
public static final double satelliteMass = 1.04;

/* TODO(rskew) update inertia matrix. */
/** Inertia matrix of the satellite. */
/** Default inertia matrix, set by the Dashboard. */
public static double[][] satInertiaMatrix = /* kg.m^2 */ {
{1191.648 * 1.3e-6, 0 , 0 },
{ 0 , 1169.506 * 1.3e-6, 0 },
{ 0 , 0 , 1203.969 * 1.3e-6 },
};

/* TODO(rskew) update inertia matrix. */
/** Inertia matrix of ACRUX1. */
public static final double[][] ACRUX1InertiaMatrix = /* kg.m^2 */ {
{1191.648 * 1.3e-6, 0 , 0 },
{ 0 , 1169.506 * 1.3e-6, 0 },
{ 0 , 0 , 1203.969 * 1.3e-6 },
};

/** Simple balance inertia matrix (Unit matrix). */
public static final double[][] simpleBalancedInertiaMatrix = {
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 }
{ 1e-3, 0 , 0 },
{ 0 , 1e-3, 0 },
{ 0 , 0 , 1e-3 }
};

/* **************************************** */
Expand Down Expand Up @@ -102,6 +109,7 @@ public SatelliteBody(Environment environment) {
this.satBoxSize = SatelliteBody.satBoxSizeWithNoSolarPanel;
this.satMass = SatelliteBody.satelliteMass;
this.inertiaMatrix = SatelliteBody.satInertiaMatrix;
//this.inertiaMatrix = SatelliteBody.simpleBalancedInertiaMatrix;

SatelliteBody.logger.info(CustomLoggingTools.indentMsg(SatelliteBody.logger,
" -> Building the CubeSat body: Success."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class Gyrometer {
/** This intensity is used to generate a random number to be
* added to each components of the sensor data.
*/
public static double defaultGyroNoiseIntensity = 1e-3;
//public static double defaultGyroNoiseIntensity = 1e-3;
public static double defaultGyroNoiseIntensity = 0;

/* **************************************** */

Expand Down Expand Up @@ -65,13 +66,13 @@ public Gyrometer(Environment environment, Assembly assembly) {
* Retrieve the data from the sensor.
* @return Rotational Acceleration
*/
public Vector3D getData_rotAcc() {
/* Get the acceleration from the satellite state. */
public Vector3D getData_angularVelocity() {
/* Get the angular velocity from the satellite state. */
/* Note that these data are already in the satellite
* body frame!
*/
Vector3D data = this.assembly.getStates()
.getCurrentState().getAttitude().getRotationAcceleration();
.getCurrentState().getAttitude().getSpin();

/* Add the noise contribution. */
Vector3D noise = new Vector3D(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,32 @@ public GeoMagneticElements retrievePerfectField() {
* the altitude of the satellite is slightly shifted from the true
* one.
*/
// GeoMagneticElements trueField_itrf = this.geomagField.getField().calculateField(
// FastMath.toDegrees(geodeticPosition.getLatitude()), /* decimal deg */
// FastMath.toDegrees(geodeticPosition.getLongitude()), /* decimal deg */
// (satState.getA() - this.earth.getRadius()) / 1e3 /* km */
// );

GeoMagneticElements trueField_itrf = this.geomagField.getField().calculateField(
FastMath.toDegrees(geodeticPosition.getLatitude()), /* decimal deg */
FastMath.toDegrees(geodeticPosition.getLongitude()), /* decimal deg */
(satState.getA() - this.earth.getRadius()) / 1e3 /* km */
0.007707323868690944, /* decimal deg */
-156.00687854677085, /* decimal deg */
574.9999944513394/* km */
);

logger.debug("Magnetometer Measurement: \n" +
"Latitude: " + FastMath.toDegrees(geodeticPosition.getLatitude()) + " °\n" +
"Longitud: " + FastMath.toDegrees(geodeticPosition.getLongitude()) + " °\n" +
"Altitude: " + (satState.getA() - this.earth.getRadius()) / 1e3 + " km\n" +
"True Geo ITRF" + trueField_itrf.toString()
"(ITRF): " + trueField_itrf.toString()
);

/* Rotate the magnetic field reading into the body frame */
Vector3D trueField_body = this.assembly.getItrf2body(satState.getDate())
.transformVector(trueField_itrf.getFieldVector());

return new GeoMagneticElements(trueField_body);
GeoMagneticElements trueGeoMag_body = new GeoMagneticElements(trueField_body);

return trueGeoMag_body;
}

/**
Expand Down
26 changes: 17 additions & 9 deletions simulator/src/main/java/msp/simulator/user/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public static void setDefaultConfiguration() {
Dashboard.setTorqueDisturbances(true);

/* **** Structure Settings **** */
Dashboard.setSatBoxSizeWithNoSolarPanel(new double[]{0.01, 0.01, 0.01});
Dashboard.setSatelliteMass(1.0);
Dashboard.setSatelliteInertiaMatrix(SatelliteBody.simpleBalancedInertiaMatrix);
//Dashboard.setSatBoxSizeWithNoSolarPanel(new double[]{0.01, 0.01, 0.01});
//Dashboard.setSatelliteMass(1.0);
//Dashboard.setSatelliteInertiaMatrix(SatelliteBody.simpleBalancedInertiaMatrix);

/* **** Structure Settings **** */
Dashboard.setMagnetometerNoiseIntensity(1e2);
Expand Down Expand Up @@ -232,6 +232,14 @@ public static void setSimulationDuration(long duration) {
NumericalSimulator.simulationDuration = duration ; /* s. */
}

/**
* Set the wall clock time daley between comuting steps
* @param stepDelay in seconds
*/
public static void setStepDelay(double stepDelay) {
NumericalSimulator.stepDelay = stepDelay;
}

/**
* Set the period of work of the ground station, i.e. the time without
* any update.
Expand All @@ -256,9 +264,9 @@ public static void setOrbitalParameters(OrbitalParameters param) {
* Set the size of the satellite box without solar panel.
* @param xyzSize a three-dimension array (x, y, z) in meter.
*/
public static void setSatBoxSizeWithNoSolarPanel(double[] xyzSize) {
SatelliteBody.satBoxSizeWithNoSolarPanel = xyzSize;
}
//public static void setSatBoxSizeWithNoSolarPanel(double[] xyzSize) {
// SatelliteBody.satBoxSizeWithNoSolarPanel = xyzSize;
//}

/**
* Set the initial attitude quaternion. (Representing the rotation
Expand Down Expand Up @@ -298,9 +306,9 @@ public static void setTorqueDisturbances(boolean flag) {
* Set the user-defined satellite mass.
* @param mass in kilogram
*/
public static void setSatelliteMass(double mass) {
SatelliteBody.satelliteMass = mass;
}
//public static void setSatelliteMass(double mass) {
// SatelliteBody.satelliteMass = mass;
//}

/**
* Set the user-specified inertia matrix of the satellite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,16 @@ public void writeStep(Satellite satellite) {
"Attitude: [{}, {}, {}, {}] \n" +
"Spin : {} \n" +
"RotAcc : {}\n" +
"Momentum: {}",
"Momentum: {}\n" +
"Momentum Norm: {}",
newState.getAttitude().getRotation().getQ0(),
newState.getAttitude().getRotation().getQ1(),
newState.getAttitude().getRotation().getQ2(),
newState.getAttitude().getRotation().getQ3(),
newState.getAttitude().getSpin().toString(),
newState.getAttitude().getRotationAcceleration().toString(),
satellite.getAssembly().getAngularMomentum()
satellite.getAssembly().getAngularMomentum(),
satellite.getAssembly().getAngularMomentum().getNorm()
);

} catch (OrekitException | IOException e) {
Expand Down