public Sensors(IMyTerminalBlock reference, List <IMyTerminalBlock> blocks) : base(reference) { UpdateSensors(blocks); if (sensorBlocks.Count > 0) { IMySensorBlock sensor = sensorBlocks[0]; Min = sensor.GetMininum <float>("Back"); Max = sensor.GetMaximum <float>("Back"); Default = sensor.GetDefaultValue <float>("Back"); } }
/// <summary> /// initialize the travel movement module. /// </summary> /// <param name="vTargetLocation"></param> /// <param name="maxSpeed"></param> /// <param name="myShipController"></param> /// <param name="iThrustType"></param> void InitDoTravelMovement(Vector3D vTargetLocation, double maxSpeed, IMyTerminalBlock myShipController, int iThrustType = WicoThrusters.thrustAll) { tmMaxSpeed = maxSpeed; if (tmMaxSpeed > thisProgram.wicoControl.fMaxWorldMps) { tmMaxSpeed = thisProgram.wicoControl.fMaxWorldMps; } tmShipController = myShipController as IMyShipController; //TODO: add grav gen support if (thisProgram.wicoWheels.HasSledWheels()) { btmSled = true; // if (shipSpeedMax > 45) shipSpeedMax = 45; // sStartupError += "\nI am a SLED!"; thisProgram.wicoWheels.PrepareSledTravel(); } else { btmSled = false; } if (thisProgram.wicoWheels.HasWheels()) { btmWheels = true; // TODO: Turn brakes OFF if (tmShipController is IMyShipController) { tmShipController.HandBrake = false; } } else { btmWheels = false; } if (thisProgram.wicoGyros.GyrosAvailable() > 0) { btmHasGyros = true; } else { btmHasGyros = false; } if (thisProgram.wicoNavRotors.NavRotorCount() > 0) { btmRotor = true; // if (shipSpeedMax > 15) shipSpeedMax = 15; } else { btmRotor = false; } tmShipController = myShipController as IMyShipController; Vector3D vVec = vTargetLocation - tmShipController.CenterOfMass; double distance = vVec.Length(); thisProgram.wicoThrusters.ThrustersCalculateOrientation(tmShipController, ref thrustTmForwardList, ref thrustTmBackwardList, ref thrustTmDownList, ref thrustTmUpList, ref thrustTmLeftList, ref thrustTmRightList);//, iThrustType); thisProgram.wicoSensors.SensorsSleepAll(); if (thisProgram.wicoSensors.GetCount() > 0) { tmSB = thisProgram.wicoSensors.GetForwardSensor(); // tmSB = sensorsList[0]; if (btmRotor || btmSled) { tmSB.DetectAsteroids = false; } else { tmSB.DetectAsteroids = true; } tmSB.DetectEnemy = true; tmSB.DetectLargeShips = true; tmSB.DetectSmallShips = true; tmSB.DetectStations = true; tmSB.DetectPlayers = false; // run them over! tmMaxSensorM = tmSB.GetMaximum <float>("Front"); if (!thisProgram.wicoCameras.HasForwardCameras()) // cameraForwardList.Count < 1) { // sensors, but no cameras. // if (!AllowBlindNav) tmMaxSpeed = tmMaxSensorM / 2; // if (dTMUseCameraCollision) sStartupError += "\nNo Cameras for collision detection"; } } else { // no sensors... tmSB = null; tmMaxSensorM = 0; if (!thisProgram.wicoCameras.HasForwardCameras())// cameraForwardList.Count < 1) { // if (dTMUseCameraCollision || dTMUseSensorCollision) sStartupError += "\nNo Sensor nor cameras\n for collision detection"; // if (!AllowBlindNav) tmMaxSpeed = 5; } else { // if (dTMUseSensorCollision) sStartupError += "\nNo Sensor for collision detection"; } } btmApproach = false; // we have reached approach range btmPrecision = false; // we have reached precision range btmClose = false; // we have reached close range double optimalV = tmMaxSpeed; // need to check other propulsion flags.. if (!btmSled && !btmRotor) { optimalV = CalculateOptimalSpeed(thrustTmBackwardList, distance); } if (optimalV < tmMaxSpeed) { tmMaxSpeed = optimalV; } // if (dTMDebug) sInitResults += "\nDistance=" + niceDoubleMeters(distance) + " OptimalV=" + niceDoubleMeters(optimalV); dtmFarSpeed = tmMaxSpeed; dtmApproachSpeed = tmMaxSpeed * 0.50; dtmPrecisionSpeed = tmMaxSpeed * 0.25; // minimum speeds. if (dtmApproachSpeed < 5) { dtmApproachSpeed = 5; } if (dtmPrecisionSpeed < 5) { dtmPrecisionSpeed = 5; } if (dtmPrecisionSpeed > dtmApproachSpeed) { dtmApproachSpeed = dtmPrecisionSpeed; } if (dtmPrecisionSpeed > dtmFarSpeed) { dtmFarSpeed = dtmPrecisionSpeed; } // dtmPrecision =calculateStoppingDistance(thrustTmBackwardList, dtmPrecisionSpeed*1.1, 0); // dtmApproach = calculateStoppingDistance(thrustTmBackwardList, dtmApproachSpeed*1.1, 0); if (!(btmWheels || btmRotor)) { dtmPrecision = thisProgram.wicoThrusters.calculateStoppingDistance(tmShipController, thrustTmBackwardList, dtmPrecisionSpeed + (dtmApproachSpeed - dtmPrecisionSpeed) / 2, 0); dtmApproach = thisProgram.wicoThrusters.calculateStoppingDistance(tmShipController, thrustTmBackwardList, dtmApproachSpeed + (dtmFarSpeed - dtmApproachSpeed) / 2, 0); dtmFar = thisProgram.wicoThrusters.calculateStoppingDistance(tmShipController, thrustTmBackwardList, dtmFarSpeed, 0); // calculate maximum stopping distance at full speed } } // if (dTMDebug) sInitResults += "\nFarSpeed==" + niceDoubleMeters(dtmFarSpeed) + " ASpeed=" + niceDoubleMeters(dtmApproachSpeed); // if (dTMDebug) sInitResults += "\nFar==" + niceDoubleMeters(dtmFar) + " A=" + niceDoubleMeters(dtmApproach) + " P=" + niceDoubleMeters(dtmPrecision); bCollisionWasSensor = false; tmCameraElapsedMs = -1; // no delay for next check tmScanElapsedMs = 0; // do delay until check dtmRayCastQuadrant = 0; thisProgram.wicoGyros.SetMinAngle(0.01f);// minAngleRad = 0.01f; // reset Gyro aim tolerance to default }
/// <summary> /// initialize the travel movement module. /// </summary> /// <param name="vTargetLocation"></param> /// <param name="maxSpeed"></param> /// <param name="myShipController"></param> /// <param name="iThrustType"></param> void InitDoTravelMovement(Vector3D vTargetLocation, double maxSpeed, IMyTerminalBlock myShipController, int iThrustType = thrustAll) { tmMaxSpeed = maxSpeed; if (tmMaxSpeed > fMaxWorldMps) { tmMaxSpeed = fMaxWorldMps; } if ((craft_operation & CRAFT_MODE_SLED) > 0) { btmSled = true; // if (shipSpeedMax > 45) shipSpeedMax = 45; PrepareSledTravel(); } else { btmSled = false; } if ((craft_operation & CRAFT_MODE_ROTOR) > 0) { btmRotor = true; // if (shipSpeedMax > 15) shipSpeedMax = 15; } else { btmRotor = false; } tmShipController = myShipController as IMyShipController; Vector3D vVec = vTargetLocation - tmShipController.CenterOfMass; double distance = vVec.Length(); thrustersInit(tmShipController, ref thrustTmForwardList, ref thrustTmBackwardList, ref thrustTmDownList, ref thrustTmUpList, ref thrustTmLeftList, ref thrustTmRightList, iThrustType); sleepAllSensors(); if (sensorsList.Count > 0) { tmSB = sensorsList[0]; if (btmRotor || btmSled) { tmSB.DetectAsteroids = false; } else { tmSB.DetectAsteroids = true; } tmSB.DetectEnemy = true; tmSB.DetectLargeShips = true; tmSB.DetectSmallShips = true; tmSB.DetectStations = true; tmSB.DetectPlayers = false; // run them over! tmMaxSensorM = tmSB.GetMaximum <float>("Front"); } else { tmSB = null; tmMaxSensorM = 0; } btmApproach = false; // we have reached approach range btmPrecision = false; // we have reached precision range btmClose = false; // we have reached close range double optimalV = tmMaxSpeed; if (!btmSled && !btmRotor) { optimalV = CalculateOptimalSpeed(thrustTmBackwardList, distance); } if (optimalV < tmMaxSpeed) { tmMaxSpeed = optimalV; } sInitResults += "\nDistance=" + niceDoubleMeters(distance) + " OptimalV=" + optimalV; dtmFarSpeed = tmMaxSpeed; dtmApproachSpeed = tmMaxSpeed * 0.50; dtmPrecisionSpeed = tmMaxSpeed * 0.25; if (dtmPrecisionSpeed < 5) { dtmPrecisionSpeed = 5; } if (dtmPrecisionSpeed > dtmApproachSpeed) { dtmApproachSpeed = dtmPrecisionSpeed; } if (dtmPrecisionSpeed > dtmFarSpeed) { dtmFarSpeed = dtmPrecisionSpeed; } // dtmPrecision =calculateStoppingDistance(thrustTmBackwardList, dtmPrecisionSpeed*1.1, 0); // dtmApproach = calculateStoppingDistance(thrustTmBackwardList, dtmApproachSpeed*1.1, 0); dtmPrecision = calculateStoppingDistance(thrustTmBackwardList, dtmPrecisionSpeed + (dtmApproachSpeed - dtmPrecisionSpeed) / 2, 0); dtmApproach = calculateStoppingDistance(thrustTmBackwardList, dtmApproachSpeed + (dtmFarSpeed - dtmApproachSpeed) / 2, 0); dtmFar = calculateStoppingDistance(thrustTmBackwardList, dtmFarSpeed, 0); // calculate maximum stopping distance at full speed // sInitResults += "\nFarSpeed=="+niceDoubleMeters(dtmFarSpeed)+" ASpeed=" + niceDoubleMeters(dtmApproachSpeed); // sInitResults += "\nFar=="+niceDoubleMeters(dtmFar)+" A=" + niceDoubleMeters(dtmApproach) + " P="+niceDoubleMeters(dtmPrecision); tmCameraElapsedMs = -1; // no delay for next check tmScanElapsedMs = 0; // do delay until check minAngleRad = 0.01f; // reset Gyro aim tolerance to default }