]> err.no Git - mapper/commitdiff
GPS simulator changes:
authorKaj-Michael Lang <milang@tal.org>
Fri, 21 Mar 2008 12:41:46 +0000 (14:41 +0200)
committerKaj-Michael Lang <milang@tal.org>
Fri, 21 Mar 2008 12:41:46 +0000 (14:41 +0200)
- Set start position to home if set
- If destination is set, try to travel towards it, otherwise use the old random way.

src/gps.c

index 718dd5574d599c28550394628459261c98534b60..fadb66c4ea793e472143ee4e4c1a775c69e3eb06 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
@@ -402,8 +402,14 @@ static void
 gps_simulate_start(Gps *gps)
 {
 g_assert(gps);
-gps->data.lat=60.45;
-gps->data.lon=22.26;
+if (_home.valid) {
+       gps->data.lat=_home.lat;
+       gps->data.lon=_home.lon;
+} else {
+       gps->data.lat=60.45;
+       gps->data.lon=22.26;
+}
+
 gps->io.conn=RCVR_FIXED;
 gps->data.fix=FIX_2D;
 gps->data.satinview=0;
@@ -415,25 +421,36 @@ static gboolean
 gps_simulate_move(Gps *gps)
 {
 static gdouble slat=0, slon=0;
-gdouble plat, plon;
+gdouble plat, plon, accel;
 gfloat h;
 
 g_assert(gps);
 
-if (g_random_double()<0.2) {
-       slat=g_random_double_range(-0.0009, 0.0009);
-       slon=g_random_double_range(-0.0009, 0.0009);
+if (_dest.valid) {
+       _dest.angle=calculate_course(_dest.lat,_dest.lon, gps->data.lat, gps->data.lon);
+
+       accel=0.005*g_random_double();
+       slat=accel*cos(_dest.angle);
+       slon=accel*sin(_dest.angle);
+       g_debug("Sim: %f %f %f %f", slat, slon, accel, _dest.angle);
+} else {
+       if (g_random_double()<0.2) {
+               slat=g_random_double_range(-0.0009, 0.0009);
+               slon=g_random_double_range(-0.0009, 0.0009);
+       }
 }
 plat=gps->data.lat;
 plon=gps->data.lon;
 gps->data.lat+=slat;
 gps->data.lon+=slon;
+
 BOUND(gps->data.lat, -80.0, 80.0);
 BOUND(gps->data.lon, -80.0, 80.0);
 
 g_debug("Sim: %f %f", gps->data.lat, gps->data.lon);
 
-gps->data.speed=1+g_random_double_range(0.1, 10.0);
+gps->data.speed=0;
+
 h=calculate_course(plat, plon, gps->data.lat, gps->data.lon);
 gps->data.heading=(h<0) ? 360+h : h;
 gps->data.time=time(NULL);