/// <summary> /// Convert current weather respone to Wheather Entity /// and update city value with Zipcode if the response is from zipcode /// </summary> /// <param name="weather"></param> /// <param name="inputValue"></param> /// <param name="isCity"></param> /// <returns></returns> public WeatherEntity GetWeatherData(CurrentWeather weather, string inputValue, bool isCity) { try { return(new WeatherEntity( isCity ? weather.Name : string.Concat(weather.Name, Hiphen, inputValue), Utililty.UnixTimeStampToDateTime(weather.Dt), (int)weather.Main.Temp, (int)weather.Main.Humidity, (int)weather.Wind.Speed, weather.Weather.FirstOrDefault().Description, (int)weather.Weather.FirstOrDefault().Id )); } catch (Exception) { throw; } }
public void Next(Platform platform) { platform.Measure(); platform.Communicate(); // init breadCumbers stack if it is null (fix serialization) if (trajectory == null) { trajectory = new Stack <Pose>(); } // init commandSequence stack if it is null (fix serialization) if (commandSequence == null) { commandSequence = new Stack <Pose>(); } this.NextInit(platform); // if robot is stopped then return if (platform.IsStopped) { return; } // if the map is discovered we are done if (platform.Map.IsDiscovered(platform)) { platform.Stop(); return; } Pose nextPose = null; if (!(platform.ControlPolicy is ReplayPolicy)) { // get the next pose and decide whether a replan is needed bool isReplan = false; if ((commandSequence != null) && (commandSequence.Count > 0)) { nextPose = commandSequence.Pop(); // ok, on the next step, there is another guy, plan the track again if (platform.ObservedPlatforms.Find(pt => nextPose.Equals(pt.Pose)) != null) { isReplan = true; } // ok, next step would be a wall, let's plan the track again if (platform.Map.MapMatrix[nextPose.X, nextPose.Y] >= platform.OccupiedThreshold) { isReplan = true; } // if the goal is not changed, then keep the track // this is good, if needed time to plan the way back from an abonden area if ((bestFronterier != null) && (platform.Map.MapMatrix[bestFronterier.X, bestFronterier.Y] != prevFronterierValue)) { isReplan = true; } } else { isReplan = true; } //isReplan = true; // *** need to replan if (isReplan) { // this is the search radius around the platform // if it is -1, then look for the first fronterier and don't worry about the manuevers int rad = (int)((double)platform.FieldOfViewRadius * 1.5); ReplanLocal(platform, rad); // get the next pose, if it is available if (commandSequence.Count > 0) { nextPose = commandSequence.Pop(); solutionType = SolutionType.LocalPlanner; } if ((nextPose == null) || (commandSequence.Count == 0)) { ReplanGlobal(platform); if (commandSequence.Count > 0) { nextPose = commandSequence.Pop(); solutionType = SolutionType.GlobalPlanner; } } } } else { nextPose = commandSequence.Pop(); } // *** need to replan if ((platform.ControlPolicy is ReplayPolicy) || ((nextPose != null) && (platform.Map.MapMatrix[nextPose.X, nextPose.Y] < platform.OccupiedThreshold) && ((platform.ObservedPlatforms.Find(pt => nextPose.Equals(pt.Pose)) == null)))) { // maintain breadcumbers prevPose = new Pose(nextPose.X, nextPose.Y, nextPose.Heading); // do action double dx = nextPose.X - platform.Pose.X; double dy = nextPose.Y - platform.Pose.Y; int goalAlpha = Utililty.ConvertAngleTo360(Math.Atan2(dy, dx) / Math.PI * 180); // choose the angle that is closer to the target heading int dalpha1 = Utililty.ConvertAngleTo360(goalAlpha - platform.Pose.Heading); int dalpha2 = Utililty.ConvertAngleTo360((platform.Pose.Heading - goalAlpha) + 360.0); double dalpha = Math.Abs(dalpha1) < Math.Abs(dalpha2) ? dalpha1 : -dalpha2; if (dalpha == 0) { if (bestFronterier != null) { prevFronterierValue = platform.Map.MapMatrix[bestFronterier.X, bestFronterier.Y]; } trajectory.Push(nextPose); platform.Move((int)dx, (int)dy); } else // rotatation is needed, let's rotate { double rot = Math.Sign(dalpha) * 45; platform.Rotate(rot); commandSequence.Push(nextPose); } hasFeasablePath = true; } else { platform.SendLog("No feasible solution"); hasFeasablePath = false; commandSequence.Clear(); } }