Skip to content

Commit 5b49c5e

Browse files
committed
DroneGroup: RTL_ALT_M and WP_ACC
1 parent 10c6285 commit 5b49c5e

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

Swarm/WaypointLeader/DroneGroup.cs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public void UpdatePositions()
130130
return;
131131
}
132132
}
133-
}
134-
135-
// check how close they are based on a 1 second projection
133+
}
134+
135+
// check how close they are based on a 1 second projection
136136
if (drone1.ProjectedLocation.GetDistance(drone2.ProjectedLocation) < Seperation / 2)
137137
{
138138
// check if they are heading the same direction
@@ -192,9 +192,9 @@ public void UpdatePositions()
192192
if (locs.Count == 0)
193193
continue;
194194
drone.PathIndex = path.IndexOf(locs[0]);
195-
}
196-
197-
195+
}
196+
197+
198198
switch (CurrentMode)
199199
{
200200
case Mode.idle:
@@ -213,20 +213,22 @@ public void UpdatePositions()
213213
{
214214
try
215215
{
216-
// get param
217-
MAV.parent.GetParam(MAV.sysid, MAV.compid, "RTL_ALT");
218-
// set param
219-
MAV.parent.setParam(MAV.sysid, MAV.compid, "RTL_ALT", 0); // cms - rtl at current alt
216+
// rtl at current alt
217+
if (MAV.param.ContainsKey("RTL_ALT"))
218+
MAV.parent.setParam(MAV.sysid, MAV.compid, "RTL_ALT", 0);
219+
else if (MAV.param.ContainsKey("RTL_ALT_M"))
220+
MAV.parent.setParam(MAV.sysid, MAV.compid, "RTL_ALT_M", 0);
220221
}
221222
catch
222223
{
223224
}
224225
try
225226
{
226-
// get param
227-
MAV.parent.GetParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL");
228-
// set param to default 100cm/s
229-
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", 100);
227+
// set accel to default
228+
if (MAV.param.ContainsKey("WPNAV_ACCEL"))
229+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", 100); // 100 cm/s/s
230+
else if (MAV.param.ContainsKey("WP_ACC"))
231+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WP_ACC", 1); // 1 m/s/s
230232
}
231233
catch
232234
{
@@ -280,7 +282,7 @@ public void UpdatePositions()
280282
0, takeoffalt))
281283
{
282284
drone.takeoffdone = true;
283-
}
285+
}
284286
}
285287
catch (Exception ex)
286288
{
@@ -390,7 +392,10 @@ public void UpdatePositions()
390392
continue;
391393
var MAV = drone.MavState;
392394
// update to faster speed
393-
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", (float)WPNAV_ACCEL * 100.0f);
395+
if (MAV.param.ContainsKey("WPNAV_ACCEL"))
396+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", (float)WPNAV_ACCEL * 100.0f);
397+
else if (MAV.param.ContainsKey("WP_ACC"))
398+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WP_ACC", (float)WPNAV_ACCEL);
394399

395400
MAV.parent.setMode(MAV.sysid, MAV.compid, "GUIDED");
396401
}
@@ -482,9 +487,11 @@ public void UpdatePositions()
482487
try
483488
{
484489
var MAV = drone.MavState;
485-
// set param to default 100cm/s
486-
if (MAV.param["WPNAV_ACCEL"].Value != 100)
487-
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", 100);
490+
// set accel to default
491+
if (MAV.param.ContainsKey("WPNAV_ACCEL") && MAV.param["WPNAV_ACCEL"].Value != 100)
492+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", 100); // 100 cm/s/s
493+
else if (MAV.param.ContainsKey("WP_ACC") && MAV.param["WP_ACC"].Value != 1)
494+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WP_ACC", 1); // 1 m/s/s
488495
}
489496
catch
490497
{
@@ -521,9 +528,11 @@ public void UpdatePositions()
521528
try
522529
{
523530
var MAV = drone.MavState;
524-
// set param to default 100cm/s
525-
if (MAV.param["WPNAV_ACCEL"].Value != 100)
526-
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", 100);
531+
// set accel to default
532+
if (MAV.param.ContainsKey("WPNAV_ACCEL") && MAV.param["WPNAV_ACCEL"].Value != 100)
533+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WPNAV_ACCEL", 100); // 100 cm/s/s
534+
else if (MAV.param.ContainsKey("WP_ACC") && MAV.param["WP_ACC"].Value != 1)
535+
MAV.parent.setParam(MAV.sysid, MAV.compid, "WP_ACC", 1); // 1 m/s/s
527536
}
528537
catch
529538
{
@@ -640,7 +649,7 @@ double GetOffPathDistance(List<PointLatLngAlt> path, PointLatLngAlt Location)
640649

641650
private List<PointLatLngAlt> GetLocationsV(List<PointLatLngAlt> path, PointLatLngAlt location, double lead,
642651
double seperation)
643-
{
652+
{
644653
List<PointLatLngAlt> result = new List<PointLatLngAlt>();
645654
var list = GetLocations(path, location, lead, seperation);
646655

0 commit comments

Comments
 (0)