refactor to use non-deprecated component iterator
This commit is contained in:
parent
a49117f909
commit
26019d48d3
@ -35,8 +35,7 @@ public class RollControlListener extends AbstractSimulationListener {
|
|||||||
|
|
||||||
// Maximum control fin angle (rad)
|
// Maximum control fin angle (rad)
|
||||||
private static final double MAX_ANGLE = 15 * Math.PI / 180;
|
private static final double MAX_ANGLE = 15 * Math.PI / 180;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PID parameters
|
* PID parameters
|
||||||
*
|
*
|
||||||
@ -47,29 +46,22 @@ public class RollControlListener extends AbstractSimulationListener {
|
|||||||
private static final double KP = 0.007;
|
private static final double KP = 0.007;
|
||||||
private static final double KI = 0.2;
|
private static final double KI = 0.2;
|
||||||
|
|
||||||
|
private double rollRate;
|
||||||
|
|
||||||
|
|
||||||
private double rollrate;
|
|
||||||
|
|
||||||
private double prevTime = 0;
|
private double prevTime = 0;
|
||||||
private double intState = 0;
|
private double intState = 0;
|
||||||
|
|
||||||
private double finPosition = 0;
|
private double finPosition = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlightConditions postFlightConditions(SimulationStatus status, FlightConditions flightConditions) {
|
public FlightConditions postFlightConditions(SimulationStatus status, FlightConditions flightConditions) {
|
||||||
// Store the current roll rate for later use
|
// Store the current roll rate for later use
|
||||||
rollrate = flightConditions.getRollRate();
|
rollRate = flightConditions.getRollRate();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postStep(SimulationStatus status) throws SimulationException {
|
public void postStep(SimulationStatus status) throws SimulationException {
|
||||||
|
|
||||||
// Activate PID controller only after a specific time
|
// Activate PID controller only after a specific time
|
||||||
if (status.getSimulationTime() < START_TIME) {
|
if (status.getSimulationTime() < START_TIME) {
|
||||||
prevTime = status.getSimulationTime();
|
prevTime = status.getSimulationTime();
|
||||||
@ -78,7 +70,7 @@ public class RollControlListener extends AbstractSimulationListener {
|
|||||||
|
|
||||||
// Find the fin set named CONTROL
|
// Find the fin set named CONTROL
|
||||||
FinSet finset = null;
|
FinSet finset = null;
|
||||||
for (RocketComponent c : status.getConfiguration().getActiveComponents()) {
|
for (RocketComponent c : status.getConfiguration().getAllComponents()) {
|
||||||
if ((c instanceof FinSet) && (c.getName().equals(CONTROL_FIN_NAME))) {
|
if ((c instanceof FinSet) && (c.getName().equals(CONTROL_FIN_NAME))) {
|
||||||
finset = (FinSet) c;
|
finset = (FinSet) c;
|
||||||
break;
|
break;
|
||||||
@ -87,23 +79,20 @@ public class RollControlListener extends AbstractSimulationListener {
|
|||||||
if (finset == null) {
|
if (finset == null) {
|
||||||
throw new SimulationException("A fin set with name '" + CONTROL_FIN_NAME + "' was not found");
|
throw new SimulationException("A fin set with name '" + CONTROL_FIN_NAME + "' was not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Determine time step
|
// Determine time step
|
||||||
double deltaT = status.getSimulationTime() - prevTime;
|
double deltaT = status.getSimulationTime() - prevTime;
|
||||||
prevTime = status.getSimulationTime();
|
prevTime = status.getSimulationTime();
|
||||||
|
|
||||||
|
|
||||||
// PID controller
|
// PID controller
|
||||||
double error = SETPOINT - rollrate;
|
double error = SETPOINT - rollRate;
|
||||||
|
|
||||||
double p = KP * error;
|
double p = KP * error;
|
||||||
intState += error * deltaT;
|
intState += error * deltaT;
|
||||||
double i = KI * intState;
|
double i = KI * intState;
|
||||||
|
|
||||||
double value = p + i;
|
double value = p + i;
|
||||||
|
|
||||||
|
|
||||||
// Clamp the fin angle between -MAX_ANGLE and MAX_ANGLE
|
// Clamp the fin angle between -MAX_ANGLE and MAX_ANGLE
|
||||||
if (Math.abs(value) > MAX_ANGLE) {
|
if (Math.abs(value) > MAX_ANGLE) {
|
||||||
System.err.printf("Attempting to set angle %.1f at t=%.3f, clamping.\n",
|
System.err.printf("Attempting to set angle %.1f at t=%.3f, clamping.\n",
|
||||||
@ -111,7 +100,6 @@ public class RollControlListener extends AbstractSimulationListener {
|
|||||||
value = MathUtil.clamp(value, -MAX_ANGLE, MAX_ANGLE);
|
value = MathUtil.clamp(value, -MAX_ANGLE, MAX_ANGLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Limit the fin turn rate
|
// Limit the fin turn rate
|
||||||
if (finPosition < value) {
|
if (finPosition < value) {
|
||||||
finPosition = Math.min(finPosition + TURNRATE * deltaT, value);
|
finPosition = Math.min(finPosition + TURNRATE * deltaT, value);
|
||||||
@ -122,6 +110,5 @@ public class RollControlListener extends AbstractSimulationListener {
|
|||||||
// Set the control fin cant and store the data
|
// Set the control fin cant and store the data
|
||||||
finset.setCantAngle(finPosition);
|
finset.setCantAngle(finPosition);
|
||||||
status.getFlightData().setValue(FIN_CANT_TYPE, finPosition);
|
status.getFlightData().setValue(FIN_CANT_TYPE, finPosition);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user