Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 2208 → Rev 2209

/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/followme/followme.c
36,6 → 36,14
//############################################################################
//# HISTORY followme.c
//#
//#
//#
//#
//#
//# 22.09.2015 Starter
//# - FollowMeStep2 erweitert mit Kreisberechnung und test auf PKT
//# - PKT-Pos von lat lon auf latitude und longitude umbenannt
//#
//# 20.09.2015 Starter
//# FollowMeStep2 erweitert auf aktuelle GPS-Daten und followme_calculate_offset(...)
//#
262,7 → 270,10
//-----------------------------------------
if( redraw )
{
lcd_cls();
#ifdef USE_FOLLOWME_STEP2
printFollowMeStatic();
#else
lcd_cls();
 
lcdx_printf_center_P( 0, MNORMAL, 1,0, PSTR("FollowMe") ); // Titel: oben, mitte
 
281,6 → 292,7
draw_icon_target_round( 1, 50);
 
redraw = false;
#endif
}
 
 
344,8 → 356,10
// MK: Sat Anzahl
//-----------------
yoffs = -27;
if( naviData->SatsInUse > 5 ) drawmode = MNORMALX;
else drawmode = MINVERSX;
if( naviData->SatsInUse > 5 )
drawmode = MNORMALX;
else
drawmode = MINVERSX;
writex_ndigit_number_u( 17, 5, naviData->SatsInUse, 2, 0,drawmode, 3,2+yoffs);
draw_icon_satmini( 116+3, 42+yoffs);
 
622,20 → 636,42
 
 
 
void printFollowMeStatic(void)
{
lcdx_printf_center_P( 0, MNORMAL, 1,0, PSTR("FollowMe") ); // Titel: oben, mitte
 
lcd_line( 6*6-3, 0, 6*6-3, 11, 1); // Linie Vertikal links
lcd_line( 15*6+5, 0, 15*6+5, 11, 1); // Linie Vertikal rechts
lcd_line( 0, 12, 127, 12, 1); // Linie Horizontal
lcd_line( 66, 39, 127, 39, 1); // Linie Horizontal Mitte
 
lcd_rect_round( 0, 33, 66, 12, 1, R1); // Rahmen fuer "Di" (Distance)
 
lcdx_printf_at_P( 3, 2, MNORMAL, 3,-1, PSTR("Al:") ); // Label: "Al:"
 
draw_icon_mk( 1, 18);
draw_icon_target_round( 1, 50);
}
 
 
 
 
// FollowMeStep2:
#define ONLINE
#define DEBUG
 
#ifdef USE_FOLLOWME_STEP2
void Debug_GPS (void)
{
uint8_t redraw;
uint8_t redraw = true;
nmeaPOS NMEApos;
nmeaPOS NMEATarget;
 
set_beep( 25, 0xffff, BeepNormal ); // kurzer Bestaetigungs-Beep
redraw = true;
 
//#define OFFLINE
#ifndef OFFLINE
int retcode = GPSMouse_Connect(); // Abfrage der GPS-Daten zum testen Quick an Dirty ;-)
 
#ifdef ONLINE
int retcode = GPSMouse_Connect(); // Abfrage der GPS-Daten zum testen -> Quick an Dirty ;-)
if( retcode <= 0 )
{
return;
642,23 → 678,23
}
#endif
 
/* // DEBUG
NMEApos.lat = 520000000;
NMEApos.lon = 0;
Config.FM_Azimuth = 90;
Config.FM_Distance = 10000;
*/
#ifdef DEBUG
// NMEApos.lat = 520000000;
// NMEApos.lon = 0;
// Config.FM_Azimuth = 90;
// Config.FM_Distance = 10000;
#endif
 
while( true )
{
NMEApos.lat = NMEA.Latitude;
NMEApos.lon = NMEA.Longitude;
NMEApos.latitude = NMEA.Latitude;
NMEApos.longitude = NMEA.Longitude;
 
if( redraw )
{
lcd_cls();
 
lcdx_printf_center_P( 0, MNORMAL, 1,0, PSTR("FollowMeStep2") ); // Titel: oben, mitte
lcdx_printf_center_P( 0, MNORMAL, 1,0, PSTR("FollowMeStep2") );
lcdx_printf_center_P( 1, MNORMAL, 1,0, PSTR(" Source Lat/Lon") );
lcdx_printf_center_P( 3, MNORMAL, 1,0, PSTR(" Target Lat/Lon") );
 
665,36 → 701,38
redraw = false;
}
 
writex_gpspos( 1, 2, NMEApos.lat, MNORMAL, 0,0 ); // GPS-Maus: Latitude
writex_gpspos(10, 2, NMEApos.lon, MNORMAL, 0,0 ); // GPS-Maus: Longitude
writex_gpspos( 1, 2, NMEApos.latitude, MNORMAL, 0,0 ); // GPS-Maus: Latitude
writex_gpspos(10, 2, NMEApos.longitude, MNORMAL, 0,0 ); // GPS-Maus: Longitude
 
followme_calculate_offset(Config.FM_Distance, Config.FM_Azimuth, &followMeOffset);
 
// DEBUG
writex_gpspos( 1, 6, (int32_t)Config.FM_Azimuth*100 , MNORMAL, 0, 0 );
writex_gpspos( 10, 6, (int32_t)Config.FM_Distance*100 , MNORMAL, 0, 0 );
writex_gpspos( 1, 7, (int32_t)followMeOffset.offset_lat*100 , MNORMAL, 0, 0 );
writex_gpspos( 10, 7, (int32_t)followMeOffset.offset_long*100 , MNORMAL, 0, 0 );
#ifdef DEBUG
writex_gpspos( 1, 6, (int32_t)Config.FM_Azimuth*100, MNORMAL, 0, 0 );
writex_gpspos( 10, 6, (int32_t)Config.FM_Distance*100, MNORMAL, 0, 0 );
writex_gpspos( 1, 7, (int32_t)followMeOffset.latitude*100, MNORMAL, 0, 0 );
writex_gpspos( 10, 7, (int32_t)followMeOffset.longitude*100, MNORMAL, 0, 0 );
#endif
 
followme_add_offset(&NMEApos, &NMEATarget, &followMeOffset);
 
writex_gpspos( 1, 4, (int32_t)NMEATarget.lat , MNORMAL, 0, 0 ); // Ziel Latitude
writex_gpspos(10, 4, (int32_t)NMEATarget.lon , MNORMAL, 0, 0 ); // Ziel Longitude
writex_gpspos( 1, 4, (int32_t)NMEATarget.latitude, MNORMAL, 0, 0 ); // Ziel Latitude
writex_gpspos(10, 4, (int32_t)NMEATarget.longitude, MNORMAL, 0, 0 ); // Ziel Longitude
 
 
 
 
// Tasten
if( get_key_press(1 << KEY_ESC) )
{
#ifndef OFFLINE
#ifdef ONLINE
GPSMouse_Disconnect();
#endif
break;
}
 
 
if( get_key_press(1 << KEY_ENTER) )
{
redraw = true;
// break;
}
 
if( get_key_press(1 << KEY_MINUS) )
707,15 → 745,12
Config.FM_Azimuth += 10;
redraw = true;
}
}
}
}
 
 
 
 
 
#endif // FOLLOW_ME_STEP2
 
#endif // #ifdef USE_FOLLOWME
 
 
/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/followme/followme.h
14,5 → 14,7
void FollowMe (void);
void Debug_GPS (void);
void sendFollowMeData(Point_t *tFollowMe, uint32_t *tsend_followme_counter, uint32_t *tNMEA_GPGGA_counter_old);
void printFollowMeStatic(void);
 
 
#endif /* FOLLOWME_H_ */
/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/gps/gps.c
4,7 → 4,18
//############################################################################
//# HISTORY gps.c
//#
//# 20.09.2015 Startet
//#
//#
//#
//#
//#
//#
//#
//# 22.09.2015 Starter
//# - followme_add_offset(...) und followme_calculate_offset getestet mit PKT
//# - add my_abs(...)
//#
//# 20.09.2015 Starter
//# - add Routine um einen Offset in Meter zu den aktuellen Koordinaten dazurechnen
//# followme_calculate_offset(...)
//#
36,29 → 47,6
#include "gps.h"
 
 
/*
// definiert in: mk_data-stucts.h
typedef struct
{
u16 Distance; // distance to target in cm
s16 Bearing; // course to target in deg
} __attribute__((packed)) GPS_PosDev_t;
*/
 
/*
// definiert in: mk_data-stucts.h
typedef struct
{
s32 Longitude; // in 1E-7 deg
s32 Latitude; // in 1E-7 deg
s32 Altitude; // in mm
u8 Status; // validity of data
} __attribute__((packed)) GPS_Pos_t;
*/
 
 
//--------------------------------------------------------------
 
#define NMEA_PI (3.141592653589793) /**< PI value */
#define NMEA_PI180 (NMEA_PI / 180) /**< PI division by 180 */
#define NMEA_EARTHRADIUS_KM (6378) /**< Earth's mean radius in km */
109,13 → 97,13
distance /= NMEA_EARTHRADIUS_KM; /* Angular distance covered on earth's surface */
azimuth = nmea_degree2radian(azimuth);
 
end_pos->lat = asin( sin(p1.lat) * cos(distance) + cos(p1.lat) * sin(distance) * cos(azimuth));
end_pos->latitude = asin( sin(p1.latitude) * cos(distance) + cos(p1.latitude) * sin(distance) * cos(azimuth));
 
end_pos->lon = p1.lon + atan2( sin(azimuth) * sin(distance) * cos(p1.lat), cos(distance) - sin(p1.lat) * sin(end_pos->lat));
end_pos->longitude = p1.longitude + atan2( sin(azimuth) * sin(distance) * cos(p1.latitude), cos(distance) - sin(p1.latitude) * sin(end_pos->latitude));
 
if(NMEA_POSIX(isnan)(end_pos->lat) || NMEA_POSIX(isnan)(end_pos->lon))
if(NMEA_POSIX(isnan)(end_pos->latitude) || NMEA_POSIX(isnan)(end_pos->longitude))
{
end_pos->lat = 0; end_pos->lon = 0;
end_pos->latitude = 0; end_pos->longitude = 0;
RetVal = 0;
}
 
141,11 → 129,14
nmeaPOS pktPos = *pPktPos;
positionOffset followMeOffset = * pFollowMeOffset;
target_pos->lat = pktPos.lat + ( ( followMeOffset.offset_lat * ( LAT_DIV / FOLLOWME_M2DEG ) ) ) / 1000;
target_pos->lon = pktPos.lon + ( ( followMeOffset.offset_long * ( LONG_DIV / FOLLOWME_M2DEG ) * (8192/1000) ) / my_abs( c_cos_8192( (pktPos.lat / LONG_DIV ) ) ) );
target_pos->latitude = pktPos.latitude + ( ( followMeOffset.latitude * ( LAT_DIV / FOLLOWME_M2DEG ) ) ) / 1000;
target_pos->longitude = pktPos.longitude + ( ( followMeOffset.longitude * ( LONG_DIV / FOLLOWME_M2DEG ) * (8192/1000) ) / my_abs( c_cos_8192( (pktPos.latitude / LONG_DIV ) ) ) );
return 1;
}
 
 
// schlanke abs-Methode
// TODO: move to mymath.h
int16_t my_abs(int16_t input)
{
if(input < 0)
166,8 → 157,8
{
angle %= 360; // map angle to 0° - 360°
 
followMeOffset->offset_lat = ( radius * c_cos_8192( angle ) ) / 8192;
followMeOffset->offset_long = ( radius * c_sin_8192( angle ) ) / 8192;
followMeOffset->latitude = ( radius * c_cos_8192( angle ) ) / 8192;
followMeOffset->longitude = ( radius * c_sin_8192( angle ) ) / 8192;
 
return 1;
}
201,103 → 192,4
}
 
 
///**
// * \brief Calculate distance between two points
// * \return Distance in meters
// */
//int32_t nmea_distance(
// const nmeaPOS *from_pos, /**< From position in radians */
// const nmeaPOS *to_pos /**< To position in radians */
// )
//{
// int32_t dist = ((int32_t)NMEA_EARTHRADIUS_M) * acos(
// sin(to_pos->lat) * sin(from_pos->lat) +
// cos(to_pos->lat) * cos(from_pos->lat) * cos(to_pos->lon - from_pos->lon)
// );
// return dist;
//}
 
 
 
//// Berechnung von Distanz und Winkel aus GPS-Daten home(MK eingeschaltet)
//// zur aktuellen Position(nach Motorstart)
//geo_t calc_geo(HomePos_t *home, GPS_Pos_t *pos)
//{ double lat1, lon1, lat2, lon2, d1, dlat;
// geo_t geo;
//
// lon1 = MK_pos.Home_Lon;
// lat1 = MK_pos.Home_Lat;
// lon2 = (double)pos->Longitude / 10000000.0;
// lat2 = (double)pos->Latitude / 10000000.0;
//
// // Formel verwendet von http://www.kompf.de/gps/distcalc.html
// // 111.3 km = Abstand zweier Breitenkreise und/oder zweier Längenkreise am Äquator
// // es wird jedoch in Meter weiter gerechnet
// d1 = 111300 * (double)cos((double)(lat1 + lat2) / 2 * DEG_TO_RAD) * (lon1 - lon2);
// dlat = 111300 * (double)(lat1 - lat2);
// // returns a value in metres http://www.kompf.de/gps/distcalc.html
// geo.bearing = fmod((RAD_TO_DEG * (double)atan2(d1, dlat)) + 180, 360); // +180 besserer Vergleich mit MkCockpit
// if (geo.bearing > 360) geo.bearing -= 360; // bekam schon Werte über 400
// geo.distance = sqrt(d1 * d1 + dlat * dlat);
// return(geo);
//}
 
// Berechnung von Distanz und Winkel aus GPS-Daten home(MK eingeschaltet)
// zur aktuellen Position(nach Motorstart)
//--------------------------------------------------------------
//--------------------------------------------------------------
 
/*
geo_t calc_geo( HomePos_t *home, GPS_Pos_t *pos )
{
int32_t lat1, lon1, lat2, lon2;
int32_t d1, dlat;
geo_t geo;
 
lon1 = home->Home_Lon;
lat1 = home->Home_Lat;
lon2 = pos->Longitude;
lat2 = pos->Latitude;
 
if( !CheckGPS )
{
writex_gpspos( 0, 3, home->Home_Lat , MNORMAL, 0,0); // Anzeige: Breitengrad (Latitude)
writex_gpspos( 11, 3, home->Home_Lon , MNORMAL, 0,0); // Anzeige: Laengengrad (Longitude)
writex_gpspos( 0, 4, pos->Latitude , MNORMAL, 0,0); // Anzeige: Breitengrad (Latitude)
writex_gpspos( 11, 4, pos->Longitude , MNORMAL, 0,0); // Anzeige: Laengengrad (Longitude)
 
//lcd_puts_at (0, 3, my_itoa(home->Home_Lat, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr
//lcd_puts_at (11, 3, my_itoa(home->Home_Lon, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr
//lcd_puts_at (0, 4, my_itoa(pos->Latitude, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr
//lcd_puts_at (11, 4, my_itoa(pos->Longitude, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr
}
 
// Formel verwendet von http://www.kompf.de/gps/distcalc.html
// 111.3 km = Abstand zweier Breitenkreise und/oder zweier Langenkreise am Äquator
// es wird jedoch in dm Meter weiter gerechnet
// (tlon1 - tlon2)/10) sonst uint32_t-Überlauf bei cos(0) gleich 1
d1 = (1359 * (int32_t)(c_cos_8192((lat1 + lat2) / 20000000)) * ((lon1 - lon2)/10))/ 10000000;
dlat = 1113 * (lat1 - lat2) / 10000;
geo.bearing = (my_atan2(d1, dlat) + 540) % 360; // 360 +180 besserer Vergleich mit MkCockpit
geo.distance = sqrt32(d1 * d1 + dlat * dlat);
if( !CheckGPS )
{
lcd_printp_at (0, 5, PSTR("Bear:"), 0);
 
lcdx_printf_at_P( 5, 5, MNORMAL, 0,0, PSTR("%3d"), geo.bearing );
//lcd_puts_at (5, 5, my_itoa((uint32_t)geo.bearing, 3, 0, 0), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr
 
lcd_printp_at (8, 5, PSTR("\x1e"), 0);
lcd_printp_at (9, 5, PSTR("Dist:"), 0);
 
lcdx_printf_at_P( 15, 5, MNORMAL, 0,0, PSTR("%3d"), geo.distance );
//lcd_puts_at (15, 5, my_itoa((uint32_t)geo.distance, 3, 1, 1), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr
 
lcd_printp_at (20, 5, PSTR("m"), 0);
}
 
 
return(geo);
}
*/
 
/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/gps/gps.h
4,6 → 4,16
//############################################################################
//# HISTORY gps.h
//#
//#
//#
//#
//#
//#
//#
//#
//# 22.09.2015 Starter
//# - PKT-Pos von lat lon auf latitude und longitude umbenannt
//#
//# 20.06.2014 OG - NEU
//############################################################################
 
11,32 → 21,31
#ifndef GPS_H_
#define GPS_H_
 
 
 
GPS_PosDev_t gps_Deviation( GPS_Pos_t pos1, GPS_Pos_t pos2 );
 
/**
* Position data in fractional degrees or radians
*/
typedef struct _nmeaPOS
{
int32_t lat; /**< Latitude */
int32_t lon; /**< Longitude */
int32_t latitude; // Latitude in 1e-7 Grad
int32_t longitude; // Longitude in 1e-7 Grad
 
} nmeaPOS;
 
 
 
typedef struct _positionOffset
{
int32_t offset_lat;
int32_t offset_long;
int32_t latitude; // latitude offset in mm
int32_t longitude; // longitude offset in mm
}positionOffset;
 
 
GPS_PosDev_t gps_Deviation(
GPS_Pos_t pos1,
GPS_Pos_t pos2
);
 
extern nmeaPOS NMEApos;
extern nmeaPOS NMEATarget;
 
 
int nmea_move_horz(
const nmeaPOS *start_pos, /**< Start position in radians */
nmeaPOS *end_pos, /**< Result position in radians */