BowlerKernel
HingeCSGPhysicsManager.java
Go to the documentation of this file.
1 package com.neuronrobotics.bowlerstudio.physics;
2 
3 import java.util.ArrayList;
4 
5 import com.bulletphysics.dynamics.constraintsolver.HingeConstraint;
6 import com.bulletphysics.linearmath.Transform;
7 //import com.neuronrobotics.bowlerstudio.BowlerStudio;
8 import com.neuronrobotics.sdk.common.IClosedLoopController;
9 
10 import eu.mihosoft.vrl.v3d.CSG;
11 
12 import javafx.application.Platform;
13 import javafx.scene.paint.Color;
14 
16 
17  private HingeConstraint constraint = null;
19  private double target = 0;
20  private static float muscleStrength = (float) 1000;
21  boolean flagBroken = false;
22  private double velocity;
23 
24  public HingeCSGPhysicsManager(ArrayList<CSG> baseCSG, Transform pose, double mass,
25  PhysicsCore c) {
26  super(baseCSG, pose, mass, false, c);
27 
28  }
29 
30  @Override
31  public void update(float timeStep) {
32  super.update(timeStep);
33  if (constraint != null &&
34  getController() != null
35  && !flagBroken) {
36  velocity = getController().compute(constraint.getHingeAngle(), getTarget(), timeStep);
37  constraint.enableAngularMotor(true, (float) velocity, getMuscleStrength());
38  if (constraint.getAppliedImpulse() > getMuscleStrength()) {
39  for (CSG c1 : baseCSG) {
40  c1.setColor(Color.WHITE);
41  }
42  flagBroken = true;
43  getCore().remove(this);
44  setConstraint(null);
45  getCore().add(this);
46  System.out.println(
47  "ERROR Link Broken, Strength: " + getMuscleStrength() + " applied impluse " + constraint
48  .getAppliedImpulse());
49  }
50  } else if (constraint != null && flagBroken) {
51  constraint.enableAngularMotor(false, 0, 0);
52  }
53  //System.out.println("Constraint = "+constraint+" controller= "+getController()+" broken= "+flagBroken);
54  }
55 
56 
57  public HingeConstraint getConstraint() {
58  return constraint;
59  }
60 
61  public void setConstraint(HingeConstraint constraint) {
62  this.constraint = constraint;
63  }
64 
65  public double getTarget() {
66  return target;
67  }
68 
69  public void setTarget(double target) {
70  this.target = target;
71  }
72 
73  public static float getMuscleStrength() {
74  return muscleStrength;
75  }
76 
77  public static void setMuscleStrength(float ms) {
78  muscleStrength = ms;
79  }
80 
81  public void setMuscleStrength(double muscleStrength) {
83  }
84 
86  return controller;
87  }
88 
90  this.controller = controller;
91  }
92 
93 }
HingeCSGPhysicsManager(ArrayList< CSG > baseCSG, Transform pose, double mass, PhysicsCore c)
double compute(double currentState, double target, double seconds)