public async Task <IHttpActionResult> PutUAV(int id, UAV uAV) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != uAV.Id) { return(BadRequest()); } _db.Entry(uAV).State = System.Data.Entity.EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UAVExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PostUAVWithConfig(UAV uav) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } uav.Configurations = new Configuration { Classification = "quadrotor", create_date = DateTime.Now, modified_date = DateTime.Now, Name = "autogen", NumberOfMotors = 4, }; uav.Schedules.Add(new Schedule { UAVId = uav.Id, create_date = DateTime.Now, modified_date = DateTime.Now, CurrentMission = null }); _db.UAVs.Add(uav); await _db.SaveChangesAsync(); return(Ok(uav)); }
void OnCollisionEnter(Collision collision) { //Debug.Log("collision"); //eventsOutputStreamWriter.WriteLine("collisionData"); //eventsOutputStreamWriter.WriteLine("time = " +Time.time); //eventsOutputStreamWriter.WriteLine("object = "+collision.transform.name); //eventsOutputStreamWriter.WriteLine("EndcollisionData\n"); droneEventLogEntry entry = new droneEventLogEntry(); entry.cmd = lastFetchedCmd; entry.entryType = "collision"; entry.position = this.transform.position; entry.rotation = this.transform.rotation.eulerAngles; entry.velocity = rb.velocity; entry.time = Time.time; entry.relativeVelocity = collision.relativeVelocity; entry.otherName = collision.gameObject.name; UAV otherUAV = collision.gameObject.GetComponent <UAV>(); if (otherUAV != null) { entry.otherCmd = otherUAV.lastFetchedCmd; } eventLogger.logs.Add(entry); //cmdList = new string[2]; //cmdList[0] = "move y0 x"+transform.position.x.ToString()+" z"+ transform.position.z.ToString(); //cmdList[1] = "wait"; //currentCmdIndex = 0; //cmdDone = true; Destroy(this.gameObject); // Debug.Log(name + " cs LogSize:" + eventLogger.logs.Count); }
public virtual void sendMessage(object msg, UAV target) { comminaction air = FindObjectOfType <comminaction>(); air.routeMsg(this, target, msg); // target.readMessage(msg, this); droneEventLogEntry entry = new droneEventLogEntry(); entry.cmd = lastFetchedCmd; entry.entryType = "new message sent"; entry.position = this.transform.position; entry.rotation = this.transform.rotation.eulerAngles; Rigidbody rb = GetComponent <Rigidbody>(); entry.velocity = rb.velocity; entry.time = Time.time; // entry.relativeVelocity = collision.relativeVelocity; entry.info = msg.ToString(); if (target != null) { entry.otherName = target.name; UAV otherUAV = target.gameObject.GetComponent <UAV>(); if (otherUAV != null) { entry.otherCmd = otherUAV.lastFetchedCmd; } } else { entry.otherName = "ALL"; eventLogger.logs.Add(entry); } }
public HttpResponseMessage AddUavAndAssign(UAV uav) { try { uav.estimated_workload = 0; _db.UAVs.Add(uav); var nextUserInQueue = _db.Users.FirstOrDefault(u => u.position_in_queue == 1); var users = _db.Users; if (nextUserInQueue != null) { nextUserInQueue.UAVs.Add(uav); uav.User = nextUserInQueue; foreach (var user in users.Where(user => user.user_id != nextUserInQueue.user_id && user.UserRole.role_type == "Flight Dispatcher")) { user.position_in_queue--; _db.Entry(user).State = System.Data.Entity.EntityState.Modified; } nextUserInQueue.position_in_queue = users.Count(); _db.Entry(nextUserInQueue).State = System.Data.Entity.EntityState.Modified; _db.Entry(uav).State = System.Data.Entity.EntityState.Modified; _db.SaveChanges(); } else { return(Request.CreateResponse(HttpStatusCode.Conflict)); } } catch (Exception exception) { return(Request.CreateResponse(HttpStatusCode.Conflict)); } return(Request.CreateResponse(HttpStatusCode.OK)); //emit to user that uav has been tasked to them later via signalr }
private void OnTriggerExit(Collider other) { if (inRageObjects.Contains(other.gameObject)) { inRageObjects.Remove(other.gameObject); } else { return; } droneEventLogEntry entry = new droneEventLogEntry(); entry.cmd = lastFetchedCmd; entry.entryType = "object out of range"; entry.position = this.transform.position; entry.rotation = this.transform.rotation.eulerAngles; entry.velocity = rb.velocity; entry.time = Time.time; // entry.relativeVelocity = collision.relativeVelocity; entry.otherName = other.name; UAV otherUAV = other.gameObject.GetComponent <UAV>(); if (otherUAV != null) { entry.otherCmd = otherUAV.lastFetchedCmd; } eventLogger.logs.Add(entry); }
void camraFoucsOn(UAV target) { // hack need to be genrlaezed for when drones this.transform.position = target.transform.position + (new Vector3(0, 3f, -5f)) + userOfsets; // this.transform.localRotation.eulerAngles.Set(30f, 0f, 0f); }
public async Task <IHttpActionResult> disableUAV(int id) { UAV uav = await _db.UAVs.FindAsync(id); if (uav == null) { return(NotFound()); } uav.isActive = false; _db.Entry(uav).State = System.Data.Entity.EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UAVExists(id)) { return(NotFound()); } else { throw; } } return(Ok(uav)); }
public void UavWasRejected(UAV uav) { var userConnections = activeConnections.Where(p => p.Value == uav.User.user_id).Select(p => p.Key); //(IHubCallerConnectionContext<dynamic>)userConnections.uavWasRejected(uav); Clients.Clients((IList <string>)userConnections).uavWasRejected(uav); //Clients.All.uavWasRejected(uav); }
public uavObjectState(GameObject src) : base(src) { UAV uav = src.GetComponent <UAV>(); cmdList = uav.cmdList; Dictionary <string, string> Data = uav.makeDictionary(); uavData = makeListFromDictionary(Data); }
public void reportBackAtBase(int uavId) { UAV uav = db.UAVs.FirstOrDefault(x => x.Id == uavId); //if the uav landed at 'base', remove from list -- allows sending warning again batteryWarning.Remove(uav); areaWarning.Remove(uav); Clients.All.uavBackAtBase(uavId); }
public async Task <IHttpActionResult> GetUAV(int id) { UAV uAV = await _db.UAVs.FindAsync(id); if (uAV == null) { return(NotFound()); } return(Ok(uAV)); }
public async Task <IHttpActionResult> PostUAV(UAV uAV) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _db.UAVs.Add(uAV); await _db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = uAV.Id }, uAV)); }
public async Task <IHttpActionResult> DeleteUAV(int id) { UAV uAV = await _db.UAVs.FindAsync(id); if (uAV == null) { return(NotFound()); } _db.UAVs.Remove(uAV); await _db.SaveChangesAsync(); return(Ok(uAV)); }
public async Task <HttpResponseMessage> UAVAssignment(int id, int?userId) { try { UAV u = _db.UAVs.FirstOrDefault(x => x.Id == id); u.User_user_id = userId; _db.Entry(u).State = System.Data.Entity.EntityState.Modified; await _db.SaveChangesAsync(); } catch (DbUpdateException e) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public void SpawnUAV() { UAV_MODEL = Function.Call <Entity>("spawn", "script_model", UAV.Call <Vector3>("getTagOrigin", "tag_origin")); UAV_MODEL.Call("setModel", "vehicle_predator_b"); double zOffset = 6300; double angle = 0; double radiusOffset = 6100; double xOffset = (double)Math.Cos(angle) * radiusOffset; double yOffset = (double)Math.Sin(angle) * radiusOffset; Vector3 angleVector = Function.Call <Vector3>("vectorNormalize", new Vector3((float)xOffset, (float)yOffset, (float)zOffset)); angleVector = (angleVector * 6100); UAV_MODEL.Call("linkTo", UAV, "tag_origin", angleVector, new Vector3(0, (float)angle - 90, 10)); }
public void routeMsg(UAV sendr, UAV rcever, object msg) { comminactionLogEntry entry = new comminactionLogEntry(); entry.msg = msg.ToString(); entry.from = sendr.name; entry.time = Time.time; if (rcever != null) { float distnace = (sendr.transform.position - rcever.transform.position).magnitude; entry.to = rcever.name; entry.recivedby.Add(new reviverData(rcever.name, distnace)); rcever.readMessage(msg, sendr); } else { var allUav = GameObject.FindObjectsOfType <UAV>(); entry.to = "ALL"; foreach (var x in allUav) { float distnace = (sendr.transform.position - x.transform.position).magnitude; if (x == sendr) { continue; } if (sendr.inRageObjects.Contains(x.gameObject)) { entry.recivedby.Add(new reviverData(x.name, distnace)); } else { entry.faildToReciveBy.Add(new reviverData(x.name, distnace)); } } } loger.logs.Add(entry); }
public virtual void readMessage(object msg, UAV src) { droneEventLogEntry entry = new droneEventLogEntry(); entry.cmd = lastFetchedCmd; entry.entryType = "new message recived "; entry.position = this.transform.position; entry.rotation = this.transform.rotation.eulerAngles; Rigidbody rb = GetComponent <Rigidbody>(); entry.velocity = rb.velocity; entry.time = Time.time; // entry.relativeVelocity = collision.relativeVelocity; entry.info = msg.ToString(); entry.otherName = src.name; UAV otherUAV = src.gameObject.GetComponent <UAV>(); if (otherUAV != null) { entry.otherCmd = otherUAV.lastFetchedCmd; } eventLogger.logs.Add(entry); }
void OnTriggerEnter(Collider other) { //Debug.Log(other.name+" is in range"); //eventsOutputStreamWriter.WriteLine("newObjectInRange"); //eventsOutputStreamWriter.WriteLine("time = " + Time.time); //eventsOutputStreamWriter.WriteLine("object = " + other.name); //eventsOutputStreamWriter.WriteLine("endnewObjectInRange\n"); if (inRageObjects.Contains(other.gameObject)) { return; } inRageObjects.Add(other.gameObject); droneEventLogEntry entry = new droneEventLogEntry(); entry.cmd = lastFetchedCmd; entry.entryType = "object Detected"; entry.position = this.transform.position; entry.rotation = this.transform.rotation.eulerAngles; entry.velocity = rb.velocity; entry.time = Time.time; // entry.relativeVelocity = collision.relativeVelocity; entry.otherName = other.name; UAV otherUAV = other.gameObject.GetComponent <UAV>(); if (otherUAV != null) { entry.otherCmd = otherUAV.lastFetchedCmd; } eventLogger.logs.Add(entry); if (otherUAV != null) { sendMessage(lastFetchedCmd, otherUAV); } }
public async Task <IHttpActionResult> assignUser(int uav_id, int user_id) { UAV uav = await _db.UAVs.FindAsync(uav_id); User user = await _db.Users.FindAsync(user_id); if (uav == null || user == null) { return(NotFound()); } uav.User = user; user.UAVs.Add(uav); _db.Entry(uav).State = System.Data.Entity.EntityState.Modified; _db.Entry(user).State = System.Data.Entity.EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(Ok(uav)); }
public async Task PushFlightStateUpdate(FlightStateDTO dto) { Clients.All.flightStateUpdate(dto); //await TrespassChecker.ReportTrespassIfNecesarry(dto.UAVId, dto.Latitude, dto.Longitude); var eventHub = GlobalHost.ConnectionManager.GetHubContext <EventLogHub>(); UAV uav = db.UAVs.FirstOrDefault(x => x.Id == dto.Id); double lat = Math.Round(dto.Latitude * 10000) / 10000; double lon = Math.Round(dto.Longitude * 10000) / 10000; var mis = from ms in db.Missions where ms.ScheduleId == uav.Id select ms; //look up the uav bool areaList = (areaWarning.Where(u => u.Id == uav.Id).Count()) > 0; bool batteryList = (batteryWarning.Where(u => u.Id == uav.Id).Count()) > 0; if (!areaList) { bool check = db.MapRestrictedSet.Where( u => u.SouthWestLatitude <mis.FirstOrDefault().Latitude&& u.NorthEastLatitude> mis.FirstOrDefault().Latitude&& u.SouthWestLongitude <mis.FirstOrDefault().Longitude&& u.NorthEastLongitude> mis.FirstOrDefault().Longitude ).Count() > 0; if (check) { areaWarning.Add(uav); EventLog evt = new EventLog(); evt.event_id = events; evt.uav_id = uav.Id; evt.uav_callsign = uav.Callsign; evt.criticality = "critical"; evt.message = "Delivery is in restricted area"; evt.create_date = DateTime.Now; evt.modified_date = DateTime.Now; //wtf seriously? -- why is this in here twice... evt.UAVId = uav.Id; evt.operator_screen_name = "jimbob"; eventHub.Clients.All.newEvent(evt); db.EventLogs.Add(evt); events++; } } //it's not in the battery list if (!batteryList) { if (dto.BatteryLevel < .2) { //add list -- stops from sending warning everytime batteryWarning.Add(uav); EventLog evt = new EventLog(); evt.event_id = events; evt.uav_id = uav.Id; evt.uav_callsign = uav.Callsign; evt.criticality = "critical"; evt.message = "Low Battery"; evt.create_date = DateTime.Now; evt.modified_date = DateTime.Now; //wtf seriously? -- why is this in here twice... evt.UAVId = uav.Id; evt.operator_screen_name = "jimbob"; eventHub.Clients.All.newEvent(evt); db.EventLogs.Add(evt); events++; } } try { db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } // flightstatedto entity is not the same as models in our db context. can not guarantee atomic. need to wipe out flightstatedto }
public async Task <IHttpActionResult> generateUAVs(int number) { Random num = new Random(); for (int i = 0; i < number; i++) { UAV uav = new UAV { Callsign = getName().ToUpper() + num.Next(1, 99), NumDeliveries = num.Next(1, 2000), Mileage = num.Next(1, 100), Id = i, create_date = DateTime.Now, modified_date = DateTime.Now, MaxAcceleration = 20, MaxVelocity = 20, MaxVerticalVelocity = 20, MinDeliveryAlt = 100, UpdateRate = 1000, CruiseAltitude = 400, isActive = true, }; uav.Schedules.Add(new Schedule { UAVId = uav.Id, create_date = DateTime.Now, modified_date = DateTime.Now, CurrentMission = null }); Configuration config = new Configuration { Classification = "Predator", create_date = DateTime.Now, modified_date = DateTime.Now, Name = "Default", NumberOfMotors = 4 }; var flights = new List <FlightState> { new FlightState { Longitude = -118.5288, Latitude = 34.2420, Altitude = 400, VelocityX = 0, VelocityY = 0, VelocityZ = 0, Yaw = 0, Roll = 0, Pitch = 0, YawRate = 0, RollRate = 0, PitchRate = 0, BatteryLevel = .99, UAVId = i }, }; flights.ForEach(f => { f.Timestamp = DateTime.Now; f.create_date = DateTime.Now; f.modified_date = DateTime.Now; }); DateTime dateValue = new DateTime(); dateValue = DateTime.Now; var randPoint = getDistance(); uav.Configurations = config; uav.FlightStates = flights; //uav.Schedules = sched; _db.UAVs.Add(uav); //db.Missions.Add(mission.First()); //db.Maintenances.Add(maintenances.First()); _db.Configurations.Add(config); //db.Schedules.Add(sched.First()); _db.FlightStates.Add(flights.First()); try { _db.SaveChanges(); } catch (DbUpdateException e) { Console.Write(e.Entries); } } var drones = from u in _db.UAVs.Include(u => u.FlightStates) select new { Id = u.Id, Mileage = u.Mileage, NumDeliveries = u.NumDeliveries, Callsign = u.Callsign, create_date = u.create_date, modified_date = u.modified_date, MaxVelocity = u.MaxVelocity, MaxAcceleration = u.MaxAcceleration, MaxVerticalVelocity = u.MaxVerticalVelocity, UpdateRate = u.UpdateRate, FlightState = u.FlightStates.OrderBy(fs => fs.Timestamp).FirstOrDefault(), EventLog = u.EventLogs }; return(Ok(drones)); }
//[HttpGet] //[Route("api/sim/resetsim")] //public void ResetSim() //{ // startIndex = 0; //} public HttpResponseMessage GetInitSim() { int ct = 0; //Check if the UAV list has already been created if (!generated) { //Flag the list as being created //System.Diagnostics.Debug.WriteLine("started"); generated = true; UAV temp = db.UAVs.Find(0); var uavs = from u in db.UAVs.Include(u => u.FlightStates).Include(u => u.Schedules) let s = u.Schedules.OrderBy(s => s.create_date).FirstOrDefault() select new { Id = u.Id, Mileage = u.Mileage, NumDeliveries = u.NumDeliveries, Callsign = u.Callsign, create_date = u.create_date, modified_date = u.modified_date, MaxVelocity = u.MaxVelocity, MaxAcceleration = u.MaxAcceleration, MaxVerticalVelocity = u.MaxVerticalVelocity, UpdateRate = u.UpdateRate, Schedule = new { Id = s.Id, UAVId = s.UAVId, create_date = s.create_date, modified_date = s.modified_date, Missions = s.Missions, }, FlightState = u.FlightStates.OrderBy(fs => fs.Timestamp).FirstOrDefault(), User = u.User }; //System.Diagnostics.Debug.WriteLine("uav var generated"); //Find out how many drones have been retrieved foreach (var vehicle in uavs) { ct++; } //Create a transferobject list of uavs xList = new TransferObject[ct]; ct = 0; //Populate the uav list foreach (var vehicle in uavs) { xList[ct] = new TransferObject { Id = vehicle.Id, Mileage = vehicle.Mileage, NumDeliveries = vehicle.NumDeliveries, Callsign = vehicle.Callsign, create_date = vehicle.create_date, modified_date = vehicle.modified_date, MaxVelocity = vehicle.MaxVelocity, MaxAcceleration = vehicle.MaxAcceleration, MaxVerticalVelocity = vehicle.MaxVerticalVelocity, UpdateRate = vehicle.UpdateRate, Schedule = new Schedule { Id = vehicle.Schedule.Id, UAVId = vehicle.Schedule.UAVId, create_date = vehicle.Schedule.create_date, modified_date = vehicle.Schedule.modified_date, Missions = vehicle.Schedule.Missions, }, FlightState = vehicle.FlightState, }; ct++; } //System.Diagnostics.Debug.WriteLine("List created"); int capacity = 0; //Check if creating a new numofdrones-sized array would exceed the number of remaining, unassigned drones //If it would exceed, make the length only as long as the remaining number of drones if ((startIndex + numOfDrones) > xList.Length) { capacity = xList.Length - startIndex; } else { capacity = numOfDrones; } TransferObject[] transferList = new TransferObject[capacity]; for (int i = startIndex; i < (startIndex + numOfDrones) && i < xList.Length; i++) { transferList[i] = new TransferObject(); transferList[i] = transferList[i].Copy(xList[i]); } //Build the list of drones to send to the simulator startIndex += numOfDrones; return(Request.CreateResponse(HttpStatusCode.OK, transferList)); } else //xList is already generated { if (startIndex > xList.Length) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } else { int capacity = 0; //Check if creating a new numofdrones-sized array would exceed the number of remaining, unassigned drones //If it would exceed, make the length only as long as the remaining number of drones if ((startIndex + numOfDrones) > xList.Length) { capacity = xList.Length - startIndex; } else { capacity = numOfDrones; } TransferObject[] transferList = new TransferObject[capacity]; //Build the list of drones to send to the simulator for (int i = 0; i < numOfDrones && (i + startIndex) < xList.Length; i++) { transferList[i] = new TransferObject(); transferList[i] = transferList[i].Copy(xList[i + startIndex]); } //Increase the starting index of the next iteration startIndex += numOfDrones; return(Request.CreateResponse(HttpStatusCode.OK, transferList)); } } }
void OnEnable() { uav = target as UAV; setHeight = serializedObject.FindProperty("HeightSet"); heightSet = uav.HeightPreSet; }