Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ sysinfo.txt
# Builds
*.apk
*.unitypackage

# simualtionRuns
collitionsCases/
2 changes: 2 additions & 0 deletions Assets/ExtendedFlycam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void prevUAV()
private void OnGUI()
{
GUI.Label(new Rect(0, 0, 100, 100), droneName, guiStyle);

GUI.Label(new Rect(0,100, 100, 100), Time.timeSinceLevelLoad.ToString(), guiStyle);
}
int numberOfDrones = 0;
void Update()
Expand Down
7 changes: 4 additions & 3 deletions Assets/code/UAV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UAV : MonoBehaviour
public string[] cmdList { set; get; }
public uint currentCmdIndex = 0;
// public string droneId {set; get;} using the bultin unity monoBehavior name attr

protected bool powerON = true;
protected droneEventsLogger eventLogger;
protected Stream outputStream;
protected StreamWriter outputStreamWriter;
Expand Down Expand Up @@ -84,7 +84,7 @@ public virtual void sendMessage(object msg,UAV target)
entry.rotation = this.transform.rotation.eulerAngles;
Rigidbody rb = GetComponent<Rigidbody>();
entry.velocity = rb.velocity;
entry.time = Time.time;
entry.time = Time.timeSinceLevelLoad;
// entry.relativeVelocity = collision.relativeVelocity;
entry.info = msg.ToString();
if (target != null){
Expand All @@ -102,14 +102,15 @@ public virtual void sendMessage(object msg,UAV target)
}
public virtual void readMessage(object msg,UAV src)
{
if (powerON == false) return;
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.time = Time.timeSinceLevelLoad;
// entry.relativeVelocity = collision.relativeVelocity;
entry.info = msg.ToString();
entry.otherName = src.name;
Expand Down
7 changes: 4 additions & 3 deletions Assets/code/comminactionLogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.Linq;
using System.Text;

public class comminactionLogEntry
[Serializable]
public class comminactionLogEntry
{
public string msg, from, to;
public List<reviverData> recivedby;
Expand All @@ -16,7 +16,8 @@ public comminactionLogEntry()
faildToReciveBy = new List<reviverData>();
}
}
public class reviverData
[Serializable]
public class reviverData
{
public string name;
public float distance;
Expand Down
4 changes: 2 additions & 2 deletions Assets/code/comminactionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class comminactionLogger
[Serializable]
public class comminactionLogger
{
public List<comminactionLogEntry> logs;
public comminactionLogger()
Expand Down
44 changes: 38 additions & 6 deletions Assets/code/loadEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,59 @@
public class loadEnv : MonoBehaviour {
public static string folderName;
// Use this for initialization

double startTime;
Stream outputStream;
StreamWriter outputStreamWriter;
Stream summaryStream;
StreamWriter summaryStremWrite;
void Start () {
startTime = Time.timeSinceLevelLoad;
XmlSerializer serializer = new XmlSerializer(typeof(List<objectState>), new[] { typeof(visibleObjectState), typeof(uavObjectState), typeof(List<KeyValuePair<string, string>>) });
string path = "conf.xml";
if (PlayerPrefs.HasKey("configPath"))
path = PlayerPrefs.GetString("configPath");
folderName = System.DateTime.Now.ToFileTimeUtc().ToString();

if (PlayerPrefs.HasKey("outputFolder"))
folderName = PlayerPrefs.GetString("outputFolder");
if(Directory.Exists(folderName))
Directory.Delete(folderName);

Directory.CreateDirectory(folderName);
Stream file = File.Open(path,FileMode.Open);
List<objectState> list = serializer.Deserialize(file) as List<objectState>;

string summrayFilePath =folderName+ "/summary.txt";
summaryStream = File.Open(summrayFilePath, FileMode.OpenOrCreate);
summaryStremWrite = new StreamWriter(summaryStream);

foreach(var i in list)
{
i.createGameObject();
Debug.Log(i.name);
// Debug.Log(i.name);
}


}

private void FixedUpdate()
{
//Debug.Log("time " + Time.timeSinceLevelLoad);
if(PlayerPrefs.HasKey("simTime"))
if(( Time.timeSinceLevelLoad-startTime) >= PlayerPrefs.GetFloat("simTime"))
{
Application.LoadLevel("test");
}
var droneList = FindObjectsOfType<UAV>();
int numberOfDrones = droneList.Length;
summaryStremWrite.WriteLine( Time.timeSinceLevelLoad.ToString()+","+ numberOfDrones);
}
private void OnDestroy()
{
summaryStremWrite.Flush();
summaryStremWrite.Close();

}
private void OnApplicationQuit()
{
PlayerPrefs.DeleteAll();
}
// Update is called once per frame
void Update () {

Expand Down
2 changes: 1 addition & 1 deletion Assets/code/simpleDrone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void FixedUpdate () {
cmdDone = true;
}

outputStreamWriter.WriteLine(Time.time.ToString() + ","
outputStreamWriter.WriteLine( Time.timeSinceLevelLoad.ToString() + ","
+ transform.position.x + ","
+ transform.position.y + ","
+ transform.position.z + ","
Expand Down
195 changes: 131 additions & 64 deletions Assets/code/testSenaroGentrater1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,81 +13,148 @@ public class testSenaroGentrater1 : MonoBehaviour {
int maxNumberOfTrys = 1000;
public int numberOfMoveCmds;
List<Vector3> currentStartLocations;
void Start () {
minX = -AreaWidth / 2;
maxX = -minX;
maxZ = maxX;
minZ = minX;
currentStartLocations = new List<Vector3> ();
for (int i = 0; i < numberOfDrones; i++) {
bool canAdd = false;
Vector3 point = Vector3.zero;
int trys = 0;
while (!canAdd) {
point = getRandomVector ();
canAdd = true;
trys++;
for (int j = 0; j < currentStartLocations.Count; j++) {
if ((currentStartLocations [j] - point).magnitude < droneRaduis * 2) {
canAdd = false;
break;
}
}
if (trys >= maxNumberOfTrys) {
Debug.Log ("satruation");
break;
}

int numberOfDronesIndex;
int[] droneNumbers = { 500,750,1000,1500 };
void makeCase()
{
minX = -AreaWidth / 2;
maxX = -minX;
maxZ = maxX;
minZ = minX;
if (PlayerPrefs.HasKey("numberOfDronesIndex"))
numberOfDronesIndex = PlayerPrefs.GetInt("numberOfDronesIndex");
else
numberOfDronesIndex = 0;
numberOfDrones = droneNumbers[numberOfDronesIndex];


currentStartLocations = new List<Vector3>();
for (int i = 0; i < numberOfDrones; i++)
{
bool canAdd = false;
Vector3 point = Vector3.zero;
int trys = 0;
while (!canAdd)
{
point = getRandomVector();
canAdd = true;
trys++;
for (int j = 0; j < currentStartLocations.Count; j++)
{
if ((currentStartLocations[j] - point).magnitude < droneRaduis * 2)
{
canAdd = false;
break;
}
}
if (trys >= maxNumberOfTrys)
{
Debug.Log("satruation");
break;
}

}
if (canAdd) {
currentStartLocations.Add (point);
// Debug.Log (point);
}
}

Debug.Log ("points Gnareted");
List<objectState> stateList = new List<objectState>();
int count =0;
foreach (var x in currentStartLocations) {

Dictionary<string, string> uavData = new Dictionary<string, string> ();
uavData ["mass"] = "4";
string[] cmdList = new string[numberOfMoveCmds+1];
cmdList [0] = "setSpeed 30";
for (int k = 0; k < numberOfMoveCmds; k++) {
Vector3 endLocation = getRandomVector ();
cmdList [k+1] = "move x" + endLocation.x.ToString () + " y" + endLocation.y.ToString () + " z" + endLocation.z.ToString ();

}
}
if (canAdd)
{
currentStartLocations.Add(point);
// Debug.Log (point);
}
}

uavObjectState state = new uavObjectState("drone " + count.ToString(), "basicDrone");
state.position = x;
state.uavData = uavObjectState.makeListFromDictionary(uavData) ;
state.cmdList = cmdList;
//Debug.Log("points Gnareted");
List<objectState> stateList = new List<objectState>();
int count = 0;

foreach (var x in currentStartLocations)
{

stateList.Add (state);
Dictionary<string, string> uavData = new Dictionary<string, string>();
uavData["mass"] = "4";
string[] cmdList = new string[numberOfMoveCmds + 1];
cmdList[0] = "setSpeed 15";
for (int k = 0; k < numberOfMoveCmds; k++)
{
Vector3 endLocation = getRandomVector();
cmdList[k + 1] = "move x" + endLocation.x.ToString() + " y" + endLocation.y.ToString() + " z" + endLocation.z.ToString();

count++;
}
string path = "coedeGenrtatedCase"+System.DateTime.Now.ToFileTimeUtc().ToString() + ".xml";
Stream fileStream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write);
}

XmlSerializer serializer = new XmlSerializer(typeof(List<objectState>),new []{ typeof(visibleObjectState),typeof(uavObjectState),typeof(List<KeyValuePair<string,string>>)});
var sw = new StreamWriter (fileStream);
serializer.Serialize (sw,stateList);
sw.Flush ();
sw.Close ();

}
uavObjectState state = new uavObjectState("drone " + count.ToString(), "basicDrone");
state.position = x;
state.uavData = uavObjectState.makeListFromDictionary(uavData);
state.cmdList = cmdList;

stateList.Add(state);

count++;
}
string path = "collitionsCases/" + numberOfDrones + "/conf.xml";
Directory.CreateDirectory("collitionsCases/" + numberOfDrones);
PlayerPrefs.SetString("configPath", path);
PlayerPrefs.SetString("outputFolder", "collitionsCases/" + numberOfDrones + "/output");

Stream fileStream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write);

XmlSerializer serializer = new XmlSerializer(typeof(List<objectState>), new[] { typeof(visibleObjectState), typeof(uavObjectState), typeof(List<KeyValuePair<string, string>>) });
var sw = new StreamWriter(fileStream);
serializer.Serialize(sw, stateList);
sw.Flush();
sw.Close();
}
double lastSenceStartTime = 0;
void Start () {

Application.runInBackground = true;
PlayerPrefs.SetFloat("simTime", 60 * 2);
if (PlayerPrefs.HasKey("numberOfDronesIndex"))
numberOfDronesIndex = PlayerPrefs.GetInt("numberOfDronesIndex");
else
numberOfDronesIndex = 0;
if (numberOfDronesIndex == droneNumbers.Length)
{
PlayerPrefs.DeleteAll();
Application.Quit();
}
else if (!Application.isLoadingLevel)
{

PlayerPrefs.SetInt("numberOfDronesIndex", numberOfDronesIndex);
makeCase();
Application.LoadLevel("emptyPlane");
}
numberOfDronesIndex++;
PlayerPrefs.SetInt("numberOfDronesIndex", numberOfDronesIndex);

}


Vector3 getRandomVector()
Vector3 getRandomVector()
{
return new Vector3 (UnityEngine.Random.Range(minX,maxX),Y,UnityEngine.Random.Range(minZ,maxZ));
}
// Update is called once per frame
void Update () {
private void OnApplicationQuit()
{
PlayerPrefs.DeleteAll();
}
public void FixedUpdate()
{
// Debug.Log("time = " + Time.timeSinceLevelLoad.ToString());
//if( Time.timeSinceLevelLoad-lastSenceStartTime>60f)
//{

// Application.UnloadLevel("emptyPlane");
// numberOfDrones = PlayerPrefs.GetInt("numOfdrone");
// numberOfDrones += 5;
// if (numberOfDrones > 50) Application.Quit();
// makeCase();
// lastSenceStartTime = Time.timeSinceLevelLoad;
// PlayerPrefs.SetInt("numOfdrone", numberOfDrones);
// Application.LoadLevel("emptyPlane");
//}
}
// Update is called once per frame
void Update () {

}
}
14 changes: 9 additions & 5 deletions Assets/code/testSenaroGentrater2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ void Start()

Dictionary<string, string> uavData = new Dictionary<string, string>();
uavData["mass"] = "4";
string[] cmdList = new string[4];
cmdList[0] = "setSpeed 30";
cmdList[1] = "wait " + Random.Range(0, 2 * 60);
cmdList[2] = "move x" + endLoc.x + " y" + endLoc.y + " z" + endLoc.z;
cmdList[3] = "wait";
string[] cmdList = new string[7];
cmdList[0] = "powerOFF";
cmdList[1] = "setSpeed 15";
cmdList[2] = "wait s" + Random.Range(0, 2 * 60);
cmdList[3] = "powerON";
cmdList[4] = "move x" + endLoc.x + " y" + endLoc.y + " z" + endLoc.z;
cmdList[5] = "move x" + endLoc.x + " y" + "0.8" + " z" + endLoc.z;

cmdList[6] = "powerOFF";

uavObjectState state = new uavObjectState("drone " + count.ToString(), "basicDrone");
state.position = startLoc;
Expand Down
Loading