Skip to content

Commit 023e65f

Browse files
Formatting the code.
1 parent 07671c7 commit 023e65f

File tree

12 files changed

+1408
-1288
lines changed

12 files changed

+1408
-1288
lines changed

example-simulations/src/main/java/us/ihmc/exampleSimulations/yoFilteredDouble/emptyRobotSCS/YoFilteredDoubleController.java

Lines changed: 184 additions & 177 deletions
Large diffs are not rendered by default.

example-simulations/src/main/java/us/ihmc/exampleSimulations/yoFilteredDouble/emptyRobotSCS/YoFilteredDoubleSimulation.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@
44
import us.ihmc.simulationconstructionset.SimulationConstructionSet;
55
import us.ihmc.yoVariables.registry.YoRegistry;
66

7-
public class YoFilteredDoubleSimulation {
8-
9-
private YoRegistry registry;
10-
private double dt_ns = 1000000.0; // 100 Hz
11-
12-
public YoFilteredDoubleSimulation() {
13-
14-
// 1.0 Create YoRegistry to store YoFiltered Doubles in for the simulation.
15-
registry = new YoRegistry("yoFilteredDoubleTest");
16-
17-
Robot robot = new Robot("EmptyRobot");
18-
SimulationConstructionSet scs = new SimulationConstructionSet();
19-
YoFilteredDoubleController controller = new YoFilteredDoubleController(registry, dt_ns);
20-
robot.setController(controller);
21-
scs.setRobot(robot);
22-
scs.setDT(dt_ns/1000000000.0, 1);
23-
scs.changeBufferSize(16342*10);
24-
scs.hideViewport();
25-
scs.setFastSimulate(true, 10);
26-
scs.setSimulateNoFasterThanRealTime(true);
27-
scs.startOnAThread();
28-
}
29-
30-
public static void main(String[] args)
31-
{
32-
YoFilteredDoubleSimulation sim = new YoFilteredDoubleSimulation();
33-
}
7+
public class YoFilteredDoubleSimulation
8+
{
9+
10+
private YoRegistry registry;
11+
private double dt_ns = 1000000.0; // 100 Hz
12+
13+
public YoFilteredDoubleSimulation()
14+
{
15+
16+
// 1.0 Create YoRegistry to store YoFiltered Doubles in for the simulation.
17+
registry = new YoRegistry("yoFilteredDoubleTest");
18+
19+
Robot robot = new Robot("EmptyRobot");
20+
SimulationConstructionSet scs = new SimulationConstructionSet();
21+
YoFilteredDoubleController controller = new YoFilteredDoubleController(registry, dt_ns);
22+
robot.setController(controller);
23+
scs.setRobot(robot);
24+
scs.setDT(dt_ns / 1000000000.0, 1);
25+
scs.changeBufferSize(16342 * 10);
26+
scs.hideViewport();
27+
scs.setFastSimulate(true, 10);
28+
scs.setSimulateNoFasterThanRealTime(true);
29+
scs.startOnAThread();
30+
}
31+
32+
public static void main(String[] args)
33+
{
34+
YoFilteredDoubleSimulation sim = new YoFilteredDoubleSimulation();
35+
}
3436
}
3537

example-simulations/src/main/java/us/ihmc/exampleSimulations/yoFilteredDouble/simplePendulumSCS2/SimplePendulumController.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import us.ihmc.robotics.math.filters.ContinuousTransferFunction;
55
import us.ihmc.robotics.math.filters.TransferFunctionDiscretizer;
66
import us.ihmc.robotics.math.filters.YoFilteredDouble;
7-
import us.ihmc.robotics.math.trajectories.generators.TrajectoryGenerator;
8-
import us.ihmc.robotics.math.trajectories.generators.TrajectoryGenerator.Trajectory;
97
import us.ihmc.scs2.definition.controller.ControllerInput;
108
import us.ihmc.scs2.definition.controller.ControllerOutput;
119
import us.ihmc.scs2.definition.controller.interfaces.Controller;
@@ -33,19 +31,19 @@ public class SimplePendulumController implements Controller
3331

3432
// This is the desired torque that we will apply to the fulcrum joint (PinJoint)
3533
private double torque;
36-
37-
// PID Parameters
38-
private final double Kp = 250.0;
39-
private final double Ki = 10.0;
40-
private final double Kd = 100.0;
41-
private final double Tau = 0.35;
42-
43-
// Notch Filter Parameters
44-
private final double wn = 60*2*Math.PI;
45-
private final double Q = 1.0;
46-
47-
// Controller Frequency
48-
private YoFilteredDouble Controller_Var; // PID Controller Double
34+
35+
// PID Parameters
36+
private final double Kp = 250.0;
37+
private final double Ki = 10.0;
38+
private final double Kd = 100.0;
39+
private final double Tau = 0.35;
40+
41+
// Notch Filter Parameters
42+
private final double wn = 60 * 2 * Math.PI;
43+
private final double Q = 1.0;
44+
45+
// Controller Frequency
46+
private YoFilteredDouble Controller_Var; // PID Controller Double
4947

5048
// Constructor: Where we instantiate and initialize control variables
5149
public SimplePendulumController(ControllerInput controllerInput, ControllerOutput controllerOutput)
@@ -56,18 +54,18 @@ public SimplePendulumController(ControllerInput controllerInput, ControllerOutpu
5654
// Get the objects of the fulcrum joint to read input and write output in the control loop
5755
this.fulcrumJoint = (OneDoFJointReadOnly) controllerInput.getInput().findJoint(SimplePendulumDefinition.jointName);
5856
this.fulcrumJointCommand = controllerOutput.getOneDoFJointOutput(fulcrumJoint);
59-
57+
6058
// Set up PID Transfer Function and use TransferFunctionDiscretizer to solve for the discrete TF coefficients.
61-
ContinuousTransferFunction PID_TF = new ContinuousTransferFunction("PID",
62-
1.0,
63-
new double[] {(Kp + Tau*Kd), (Tau*Kp + Ki), Ki*Tau},
64-
new double[] { 1.0, Tau, 0.0});
65-
66-
// Discretize the PID TF into a filter for a YoFilteredDouble
67-
TransferFunctionDiscretizer PID_Filter = new TransferFunctionDiscretizer(PID_TF, 1/SimplePendulumSimulation.DT);
68-
69-
// Pass the Filter into the a YoFilteredDouble object with safe startup active.
70-
Controller_Var = new YoFilteredDouble("Controller_Var", registry, PID_Filter, true);
59+
ContinuousTransferFunction PID_TF = new ContinuousTransferFunction("PID",
60+
1.0,
61+
new double[] {(Kp + Tau * Kd), (Tau * Kp + Ki), Ki * Tau},
62+
new double[] {1.0, Tau, 0.0});
63+
64+
// Discretize the PID TF into a filter for a YoFilteredDouble
65+
TransferFunctionDiscretizer PID_Filter = new TransferFunctionDiscretizer(PID_TF, 1 / SimplePendulumSimulation.DT);
66+
67+
// Pass the Filter into the a YoFilteredDouble object with safe startup active.
68+
Controller_Var = new YoFilteredDouble("Controller_Var", registry, PID_Filter, true);
7169
}
7270

7371
@Override
@@ -76,20 +74,20 @@ public void initialize()
7674
}
7775

7876
private double positionError = 0;
79-
77+
8078
@Override
8179
public void doControl()
8280
{
8381
// ERROR term: Compute the difference between the desired position the pendulum
8482
// and its current position
85-
positionError = desiredPositionRadians.getDoubleValue() - fulcrumJoint.getQ();
83+
positionError = desiredPositionRadians.getDoubleValue() - fulcrumJoint.getQ();
8684

8785
// Pass the error term into the input of the filter.
8886
Controller_Var.set(positionError);
89-
87+
9088
// Retrieve the filter output as the new torque command.
9189
torque = Controller_Var.getFilteredValue();
92-
90+
9391
// Set the desired torque for the fulcrum joint as controller output
9492
this.fulcrumJointCommand.setEffort(torque);
9593
}
@@ -105,5 +103,4 @@ public String getName()
105103
{
106104
return name;
107105
}
108-
109106
}

example-simulations/src/main/java/us/ihmc/exampleSimulations/yoFilteredDouble/simplePendulumSCS2/SimplePendulumDefinition.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,4 @@ private RigidBodyDefinition createPendulumLink(String name,
144144

145145
return pendulumLink;
146146
}
147-
148147
}

example-simulations/src/main/java/us/ihmc/exampleSimulations/yoFilteredDouble/simplePendulumSCS2/SimplePendulumSimulation.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public SimplePendulumSimulation()
4343

4444
// Launch the simulator
4545
scs.start(true, false, false);
46-
4746
}
4847

4948
public static void main(String[] args)

0 commit comments

Comments
 (0)