Skip to content

Commit

Permalink
Update to physics simulation params and autosimulate flags
Browse files Browse the repository at this point in the history
Fixing bug in non-armed agent configurations where the legacy version of calling physics updates was not entering the right loop correctly. Main fixes include:

- setting default minSimulateTimeSeconds so that one physics update happens when calling legacy actions
- Updating position of caching autoSimulate state so it happens after actionFinished calls happen
  • Loading branch information
winthos committed Feb 11, 2025
1 parent c1f52ee commit a1e8c4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 45 deletions.
49 changes: 14 additions & 35 deletions unity/Assets/Scripts/DebugInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,46 +293,26 @@ public void Execute(string command) {
}
case "initb": {
Dictionary<string, object> action = new Dictionary<string, object>();
// if you want to use smaller grid size step increments, initialize with a smaller/larger gridsize here
// by default the gridsize is 0.25, so only moving in increments of .25 will work
// so the MoveAhead action will only take, by default, 0.25, .5, .75 etc magnitude with the default
// grid size!
// if (splitcommand.Length == 2) {
// action["gridSize"] = float.Parse(splitcommand[1]);
// } else if (splitcommand.Length == 3) {
// action["gridSize"] = float.Parse(splitcommand[1]);
// action["agentCount"] = int.Parse(splitcommand[2]);
// } else if (splitcommand.Length == 4) {
// action["gridSize"] = float.Parse(splitcommand[1]);
// action["agentCount"] = int.Parse(splitcommand[2]);
// action["makeAgentsVisible"] = int.Parse(splitcommand[3]) == 1;
// }

// action.renderNormalsImage = true;
// action.renderDepthImage = true;
// action.renderSemanticSegmentation = true;
// action.renderInstanceSegmentation = true;
// action.renderFlowImage = true;

action["action"] = "Initialize";
action["agentMode"] = "locobot";
// action["gridSize"] = 0.25f;
action["visibilityDistance"] = 1.0f;
action["rotateStepDegrees"] = 30;
// action["agentControllerType"] = "stochastic";
// action["applyActionNoise"] = true;
action["width"] = 400;
action["height"] = 300;
action["snapToGrid"] = false;
action["fieldOfView"] = 79;
action["gridSize"] = 0.25f;

action["applyActionNoise"] = true;
action["continuousMode"] = true;
//action["snapToGrid"] = false;
//action["action"] = "Initialize";
//action["fieldOfView"] = 90;
//action["gridSize"] = 0.25f;

//action["autoSimulation"] = false;

PhysicsSimulationParams physicsParams = new PhysicsSimulationParams();
physicsParams.autoSimulation = false;
physicsParams.minSimulateTimeSeconds = 0.02f;
action["physicsSimulationParams"] = physicsParams;

CurrentActiveController()
.ProcessControlCommand(new DynamicServerAction(action), AManager);
break;
Expand Down Expand Up @@ -419,6 +399,7 @@ public void Execute(string command) {
action["agentMode"] = "arm";
action["agentControllerType"] = "arm";
action["renderInstanceSegmentation"] = true;
action["autoSimulation"] = false;

// action.useMassThreshold = true;
// action.massThreshold = 10f;
Expand Down Expand Up @@ -3304,14 +3285,12 @@ IEnumerator executeBatch(JArray jActions) {
case "ma": {
Dictionary<string, object> action = new Dictionary<string, object>();
action["action"] = "MoveAhead";
action["speed"] = 0.14f;
action["acceleration"] = 0.14f;
PhysicsSimulationParams physicsParams = new PhysicsSimulationParams() {
autoSimulation = false,
minSimulateTimeSeconds = 0.02f
};
//action["physicsSimulationParams"] = physicsParams;

if (splitcommand.Length > 1) {
action["moveMagnitude"] = float.Parse(splitcommand[1]);
} else {
action["moveMagnitude"] = 0.25f;
}
CurrentActiveController().ProcessControlCommand(action);
break;
}
Expand Down
9 changes: 5 additions & 4 deletions unity/Assets/Scripts/PhysicsSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class PhysicsSimulationParams {
public bool autoSimulation = false;
public float fixedDeltaTime = 0.02f;
public float minSimulateTimeSeconds = 0;
public float minSimulateTimeSeconds = 0.02f;

public bool syncTransformsAfterAction = false;

Expand Down Expand Up @@ -95,7 +95,7 @@ public static float fixedDeltaTime {
}

void Awake() {
SetDefaultSimulationParams(new PhysicsSimulationParams());
//SetDefaultSimulationParams(new PhysicsSimulationParams());
}

private void OnEnable() {
Expand Down Expand Up @@ -200,8 +200,6 @@ public static ActionFinished RunSimulatePhysicsForAction(
PhysicsSimulationParams physicsSimulationParams
) {
var fixedDeltaTime = physicsSimulationParams.fixedDeltaTime;
var previousAutoSimulate = Physics.autoSimulation;
Physics.autoSimulation = physicsSimulationParams.autoSimulation;

PhysicsSceneManager.PhysicsSimulateTimeSeconds = 0.0f;
var startPhysicsSimulateCallTime = PhysicsSceneManager.PhysicsSimulateCallCount;
Expand All @@ -210,6 +208,9 @@ PhysicsSimulationParams physicsSimulationParams
// Recursive expansion of IEnumerator
ActionFinished actionFinished = ExpandIEnumerator(enumerator, physicsSimulationParams);

var previousAutoSimulate = Physics.autoSimulation;
Physics.autoSimulation = physicsSimulationParams.autoSimulation;

if (actionFinished == null) {
throw new MissingActionFinishedException();
}
Expand Down
9 changes: 3 additions & 6 deletions unity/Assets/UnitTests/TestDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ public IEnumerator TestBackCompatAction()
}

[UnityTest]
public IEnumerator TestNewAction()
{
public IEnumerator TestNewAction() {
var controller = new TestController(this.agentManager);

var result = 5;
Expand All @@ -192,10 +191,8 @@ public IEnumerator TestNewAction()

// Complete (new actionFinished) was called automatically
Assert.IsTrue(controller.ranCompleteCallback);

// No physics sim happened
Assert.AreEqual(PhysicsSceneManager.PhysicsSimulateCallCount, 0);

// Defaults of PhyicsSimulationParams class will have one physics step of 0.02f seconds happen
Assert.AreEqual(PhysicsSceneManager.PhysicsSimulateCallCount, 1);
// 1 iteration corresponding the yield return new ActionFinished()
Assert.AreEqual(PhysicsSceneManager.IteratorExpandCount, 1);
// returns result
Expand Down

0 comments on commit a1e8c4d

Please sign in to comment.