forked from CPL/Simulator
+++
This commit is contained in:
@ -17,8 +17,6 @@ namespace DroneSimulator
|
||||
NetServerClients netServerClient = new NetServerClients();
|
||||
NetServerVisual netServerVisual = new NetServerVisual();
|
||||
|
||||
List<Drone> AllDrones = new List<Drone>();
|
||||
|
||||
public Form_Main()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -51,20 +49,24 @@ namespace DroneSimulator
|
||||
|
||||
screen2D.CreateDrone(Color.Red, data.ID);
|
||||
|
||||
AllDrones.Add(drone);
|
||||
lock (Drone.AllDrones) Drone.AllDrones.Add(drone);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Drone drone in AllDrones)
|
||||
Drone? d = null;
|
||||
|
||||
lock (Drone.AllDrones)
|
||||
{
|
||||
if (drone.ID != data.ID) continue;
|
||||
drone.Close();
|
||||
|
||||
screen2D.RemoveDrone(data.ID);
|
||||
|
||||
AllDrones.Remove(drone);
|
||||
break;
|
||||
foreach (Drone drone in Drone.AllDrones)
|
||||
{
|
||||
if (drone.ID != data.ID) continue;
|
||||
d = drone;
|
||||
Drone.AllDrones.Remove(drone);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (d != null) screen2D.RemoveDrone(d.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,11 +76,14 @@ namespace DroneSimulator
|
||||
|
||||
Drone? drone = null;
|
||||
|
||||
foreach (Drone d in AllDrones)
|
||||
lock (Drone.AllDrones)
|
||||
{
|
||||
if (d.ID != data.ID) continue;
|
||||
drone = d;
|
||||
break;
|
||||
foreach (Drone d in Drone.AllDrones)
|
||||
{
|
||||
if (d.ID != data.ID) continue;
|
||||
drone = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (drone == null) return;
|
||||
@ -123,6 +128,8 @@ namespace DroneSimulator
|
||||
|
||||
if (done != NetServerClients.ServerState.Start) return;
|
||||
|
||||
Drone.StartThread();
|
||||
|
||||
pictureBox_2D.Image = null;
|
||||
|
||||
screen2D = new Screen2D(DrawCallback);
|
||||
@ -155,23 +162,24 @@ namespace DroneSimulator
|
||||
|
||||
try
|
||||
{
|
||||
foreach (Drone d in AllDrones)
|
||||
lock (Drone.AllDrones)
|
||||
{
|
||||
screen2D.Move(d.ID, d.PosXYZ, d.GetOrientation());
|
||||
foreach (Drone d in Drone.AllDrones)
|
||||
{
|
||||
screen2D.Move(d.ID, d.PosXYZ, d.GetOrientation());
|
||||
|
||||
string line = "ID:" + d.ID.ToString() + " Pitch:" + ((int)d.Orientation.X).ToString() + " Roll:" + ((int)d.Orientation.Y).ToString() + " Yaw:" + ((int)d.Orientation.Z).ToString();
|
||||
string line = "ID:" + d.ID.ToString() + " Pitch:" + ((int)d.Orientation.X).ToString() + " Roll:" + ((int)d.Orientation.Y).ToString() + " Yaw:" + ((int)d.Orientation.Z).ToString();
|
||||
|
||||
listBox_Drones.Items.Add(line);
|
||||
listBox_Drones.Items.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
label_Timing.Text = Drone.Timing.ToString() + " Hz";
|
||||
|
||||
screen2D.DrawScene();
|
||||
}
|
||||
private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
foreach (Drone d in AllDrones) d.Close();
|
||||
}
|
||||
|
||||
private void VisualConnectionCallback(object o)
|
||||
{
|
||||
@ -198,12 +206,15 @@ namespace DroneSimulator
|
||||
|
||||
int index = 0;
|
||||
|
||||
foreach (Drone d in AllDrones)
|
||||
lock (Drone.AllDrones)
|
||||
{
|
||||
VisualData.VisualDrone v = d.GetVisual(AllDrones.Count, index++);
|
||||
foreach (Drone d in Drone.AllDrones)
|
||||
{
|
||||
VisualData.VisualDrone v = d.GetVisual(Drone.AllDrones.Count, index++);
|
||||
|
||||
try { data.Client.Send(Drone.getBytes(v)); }
|
||||
catch { }
|
||||
try { data.Client.Send(Drone.getBytes(v)); }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,5 +363,16 @@ namespace DroneSimulator
|
||||
Drone.Physics.Length = (float)numericUpDown_Physics_Length.Value;
|
||||
Drone.Physics.MaxPower = (float)numericUpDown_Physics_Power.Value;
|
||||
}
|
||||
|
||||
private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Drone.StopThread();
|
||||
}
|
||||
|
||||
private void numericUpDown_Timing_Freq_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Drone.Freq = (long)numericUpDown_Timing_Freq.Value;
|
||||
Drone.Boost = checkBox_Freq_Boost.Checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user