MechJeb2

MechJeb2

4M Downloads

Breaking Ground Scanner Arm affects Rover Autopilot Stability Control

TonkaCrash opened this issue ยท 3 comments

commented

MechJeb Version

MechJeb Dev #889 but was first noticed in earlier versions

KSP Version

KSP 1.7.2 with Breaking Ground DLC only other mod installed was Module Manager. Rover control keys were remapped to number pad arrow buttons (8246) for forward/reverse/left/right instead of WASD.

Description

See related forum post

Adding a scanning arm to a rover affects MechJeb behavior at low speed. If you engage the Rover Autopilot Stability Control, something is throwing off what MechJeb is using for the requested attitude at low velocities.

From the video you can see the Requested Attitude Arrow is pointing up and a little left of center at zero velocity. As the rover moves forward it changes to down and a little right. Once speed is up high enough (around 5 m/s) MechJeb settles down to what it should be doing.

All problems go away without the Scanning Arm on the craft. Moving the location of the scanning arm around the rover changes the Requested Attitude vector at zero velocity. I was unable to find a position to zero out the effect of the arm.

Replication Case

youtube video

Related Craft File

KSP.log

No warnings, errors or exceptions were if the Log around the time the AP is engaged.

commented

I have the same issue.

commented

The problem occurs here because the raycast hits the scanning arm's "rangeTrigger" sphere collider on layer 15 ("Local Scenery") and uses its normal vector at that points.

If the velocity is high enough, the ray looks past the scanner and hits the surface again.

Possibly related to an earlier KSP bug

commented

Passing QueryTriggerInteraction.Ignore to Physics.Raycast seems to be the solution and makes MJ see the surface again. Thanks, StackOverflow.

diff --git a/MechJeb2/MechJebModuleRoverController.cs b/MechJeb2/MechJebModuleRoverController.cs
index 7375ddbc..d49c53c1 100644
--- a/MechJeb2/MechJebModuleRoverController.cs
+++ b/MechJeb2/MechJebModuleRoverController.cs
@@ -177,7 +177,7 @@ public void CalculateTraction()
                {
                        if (wheels.Count == 0 && colliders.Count == 0) { OnVesselModified(vessel); }
                        RaycastHit hit;
-                       Physics.Raycast(vessel.CoM + vesselState.surfaceVelocity * terrainLookAhead + vesselState.up * 100, -vesselState.up, out hit, 500, 1 << 15);
+                       Physics.Raycast(vessel.CoM + vesselState.surfaceVelocity * terrainLookAhead + vesselState.up * 100, -vesselState.up, out hit, 500, 1 << 15, QueryTriggerInteraction.Ignore);
                        norm = hit.normal;
                        traction = 0;
 //                     foreach (var c in colliders) {

Edit: maybe the same flag should also be passed to the two layer-15 Raycast calls in MechJebModuleWaypointWindow (here and there)?