private async Task <Observed> UpdateFlightData(Observed observedData, Commanded commandedData) { // Initialize Variables Observed observedDataServerResponse = observedData; Commanded commandedDataServerResponse = commandedData; try { // Get New Observed Flight Data from Server observedDataServerResponse = await GetObservedDataAsync($"/observed").ConfigureAwait(false); // Update Server with Commanded Flight Data commandedDataServerResponse = await UpdateFlightDataAsync(commandedData).ConfigureAwait(false); } catch (Exception e) { // Clear Commanded Data Exit because we have disconnected commandedData.Exit = false; // Write log message Console.WriteLine(e.Message); } // return final response return(observedDataServerResponse); }
void Update() { if (selected.Count > 0) { blocks = new List <Informable>(); foreach (Transform tr in selected) { Commanded c = tr.GetComponent <Commanded>(); blocks.Add(c); } UpdateInfoPanel(); } else { List <Informable> newblocks = new List <Informable>(); foreach (Informable info in blocks) { if (info.GetType() != typeof(Commanded)) { newblocks.Add(info); } } blocks = newblocks; UpdateInfoPanel(); } }
public FlightStateDataViewModel(FlightStates controlledState, Commanded commanded, Observed observed) { State = controlledState; ObservedData = observed; CommandedData = commanded; }
//**********************************************************************************************GToStorage private static void ToStorage(Transform mytransform, Vector3 target, Func <string, bool> retf) { Vector3 dir = mytransform.position - target; target = mytransform.position + dir * Settings.GetOffDistance; Commanded com = mytransform.gameObject.GetComponent <Commanded>(); com.Command("Away!", "", target); retf("wellDone"); }
private void BurnWorker(int i) { GameObject worker = Instantiate(workerPrefab); worker.name = "Worker_" + i; worker.transform.position = transform.position + Random.insideUnitSphere * 5; Vector3 v = transform.position + Random.insideUnitSphere * 5; worker.transform.position = new Vector3(v.x, 1.05f, v.z); Commanded com = worker.GetComponent <Commanded>(); com.homeBase = transform.position; com.Command("GetOFF", "", transform.position); }
//*************************************************************************************************Go NEXT //to next Mine or home private static void GoNext(Transform mytransform, Vector3 target, Func <string, bool> retf) { Commanded com = mytransform.gameObject.GetComponent <Commanded>(); if (com.Loaded <= com.Capacity) { Vector3 nextTarget = MineInspector.GetNextBase(target); com.Command("Go!", com.currentTarget, nextTarget); } else { com.Command("ToStorage", com.currentTarget, target); } }
private void Upnloading(Collider col) { if (col.gameObject.layer == LayerMask.NameToLayer("Worker")) { Commanded worker = col.gameObject.GetComponent <Commanded>(); if (worker.Loaded > 0) { worker.Command("UnLoading", name, transform.position); } else { worker.Command("Away!", "", Random.insideUnitSphere * 20); } } }
private void Mining(Collider col) { if (col.gameObject.layer == LayerMask.NameToLayer("Worker")) { Commanded worker = col.gameObject.GetComponent <Commanded>(); if (WWorkersOnBoard < WorkersCapacity && ResourceCapacity > 0) { WWorkersOnBoard++; worker.Command("Mining", name, transform.position); } else { worker.Command("Away!", "", Random.insideUnitSphere * 20); } } }
//*************************************************************************************************WALKAROUND private static void WalkAround(Transform mytransform, Vector3 target, Func <string, bool> retf) { Commanded com = mytransform.gameObject.GetComponent <Commanded>(); float randomfactor = Random.Range(0f, 1f); mytransform.RotateAround(target, Vector3.up, 1 * randomfactor); if (com.ActionTime-- > 0) { retf("dd"); } else { retf("wellDone"); } }//*************************************************************************************************MINE ME
private async Task <Commanded> UpdateFlightDataAsync(Commanded commandedData) { //string flightDataAsString; HttpResponseMessage response = await _client.PutAsJsonAsync($"/commands/{commandedData.Id}", commandedData).ConfigureAwait(false); response.EnsureSuccessStatusCode(); // Get Flight Data as string //flightDataAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); // Deserialize //commandedData = JsonConvert.DeserializeObject<Commanded>(flightDataAsString); // Return FlightData return(commandedData); }
public MainPageViewModel() { // Set Gather Message Frequency (ms) _maxNumberOfPoints = 100; _gatherMessageFrequencyMs = 50; _frequencyOfChartUpdateMs = 500; _numberOfPointsAddedToChart = 0; _timeSinceLastChartUpdateMs = 0; _timeSinceLastServerUpdateMs = 0; _frequencyToUpdateServerWithNewFlighDataMs = 250; // Create Flight Data _observedData = new Observed(); _commandedData = new Commanded(); FlightStateDataViewModels = new List <FlightStateDataViewModel>() { new FlightStateDataViewModel(FlightStates.Roll, _commandedData, _observedData) { cKp = 0.001, cKi = 0.0001, cKd = 0.00005 }, new FlightStateDataViewModel(FlightStates.Pitch, _commandedData, _observedData) { cKp = 0.001, cKi = 0.0001, cKd = 0.00005 }, new FlightStateDataViewModel(FlightStates.Yaw, _commandedData, _observedData) { cKp = 0.001, cKi = 0.0001, cKd = 0.00005 }, new FlightStateDataViewModel(FlightStates.Throttle, _commandedData, _observedData) { cKp = 0.1, cKi = 0.2, cKd = 0.0 } }; // Set Initial PID Constants // Create Rest Client _myRestClient = new MyRestClient(); // Start Listening StartListening(); }
}//*************************************************************************************************Unloading private static void Unloading(Transform mytransform, Vector3 target, Func <string, bool> retf) { Commanded com = mytransform.gameObject.GetComponent <Commanded>(); float randomfactor = Random.Range(0f, 1f); mytransform.RotateAround(target, Random.insideUnitSphere, 2 * randomfactor); if (com.ActionTime-- > 0) { retf("dd"); } else { if (com.Loaded > 0) { com.Loaded--; } else { com.Command("GetOFF", com.currentTarget, target); } } }
public async Task <Observed> Update(Observed observedData, Commanded commandedData) { return(await UpdateFlightData(observedData, commandedData).ConfigureAwait(false)); }