public void InitMode(DriveCommand dc) { axis = ModuleWheel.AlignmentAxis.None; foreach (Part p in mVessel.parts) { if (p.Modules.Contains("ModuleWheel")) { axis = (p.Modules["ModuleWheel"] as ModuleWheel).alignmentAxis; if (axis != ModuleWheel.AlignmentAxis.None) { break; } } } mRoverAlt = (float)mVessel.altitude; mRoverLat = (float)mVessel.latitude; mRoverLon = (float)mVessel.longitude; switch (dc.mode) { case DriveCommand.DriveMode.Turn: mRoverRot = mVessel.ReferenceTransform.rotation; break; case DriveCommand.DriveMode.Distance: mWheelPID.setClamp(-1, 1); mKeepHDG = RoverHDG; break; case DriveCommand.DriveMode.DistanceHeading: mWheelPID.setClamp(-dc.steering, dc.steering); break; case DriveCommand.DriveMode.Coord: mWheelPID.setClamp(-dc.steering, dc.steering); mTargetLat = dc.target; mTargetLon = dc.target2; break; } mThrottlePID.Reset(); mWheelPID.Reset(); mVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false); }
private void UpdateAxis() { mAxis = ModuleWheel.AlignmentAxis.None; foreach (Part p in mVessel.parts) { if (p.Modules.Contains("ModuleWheel")) { float a = 0, b = 0, c = 0; ModuleWheel.ControlAxis controlAxis = (p.Modules["ModuleWheel"] as ModuleWheel).controlAxis; switch (controlAxis) { case ModuleWheel.ControlAxis.Forward: a = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.forward, p.transform.forward)); b = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.right, p.transform.forward)); c = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.up, p.transform.forward)); break; case ModuleWheel.ControlAxis.Right: a = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.forward, p.transform.right)); b = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.right, p.transform.right)); c = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.up, p.transform.right)); break; case ModuleWheel.ControlAxis.Up: a = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.forward, p.transform.up)); b = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.right, p.transform.up)); c = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.up, p.transform.up)); break; } if (a > c) { if (a > b) { mAxis = ModuleWheel.AlignmentAxis.Forward; } else { mAxis = ModuleWheel.AlignmentAxis.Right; } } else { if (c > b) { mAxis = ModuleWheel.AlignmentAxis.Up; } else { mAxis = ModuleWheel.AlignmentAxis.Right; } } if (mAxis != ModuleWheel.AlignmentAxis.None) { break; } } } }
private void UpdateAxis() { mAxis = ModuleWheel.AlignmentAxis.None; foreach (Part p in mVessel.parts) { if (p.Modules.Contains("ModuleWheel")) { float a = 0, b = 0, c = 0; ModuleWheel.ControlAxis controlAxis = (p.Modules["ModuleWheel"] as ModuleWheel).controlAxis; switch (controlAxis) { case ModuleWheel.ControlAxis.Forward: a = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.forward, p.transform.forward)); b = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.right, p.transform.forward)); c = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.up, p.transform.forward)); break; case ModuleWheel.ControlAxis.Right: a = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.forward, p.transform.right)); b = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.right, p.transform.right)); c = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.up, p.transform.right)); break; case ModuleWheel.ControlAxis.Up: a = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.forward, p.transform.up)); b = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.right, p.transform.up)); c = Math.Abs(Vector3.Dot(mVessel.ReferenceTransform.up, p.transform.up)); break; } if (a > c) { if (a > b) mAxis = ModuleWheel.AlignmentAxis.Forward; else mAxis = ModuleWheel.AlignmentAxis.Right; } else { if (c > b) mAxis = ModuleWheel.AlignmentAxis.Up; else mAxis = ModuleWheel.AlignmentAxis.Right; } if (mAxis != ModuleWheel.AlignmentAxis.None) break; } } }
public void InitMode(DriveCommand dc) { axis = ModuleWheel.AlignmentAxis.None; foreach (Part p in mVessel.parts) { if (p.Modules.Contains("ModuleWheel")) { axis = (p.Modules["ModuleWheel"] as ModuleWheel).alignmentAxis; if (axis != ModuleWheel.AlignmentAxis.None) break; } } mRoverAlt = (float)mVessel.altitude; mRoverLat = (float)mVessel.latitude; mRoverLon = (float)mVessel.longitude; switch (dc.mode) { case DriveCommand.DriveMode.Turn: mRoverRot = mVessel.ReferenceTransform.rotation; break; case DriveCommand.DriveMode.Distance: mWheelPID.setClamp(-1, 1); mKeepHDG = RoverHDG; break; case DriveCommand.DriveMode.DistanceHeading: mWheelPID.setClamp(-dc.steering, dc.steering); break; case DriveCommand.DriveMode.Coord: mWheelPID.setClamp(-dc.steering, dc.steering); mTargetLat = dc.target; mTargetLon = dc.target2; break; } mThrottlePID.Reset(); mWheelPID.Reset(); mVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false); }