Subversion Repositories FlightCtrl

Rev

Rev 626 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 626 Rev 628
Line 14... Line 14...
14
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
Peter Muehlenbrock
15
Peter Muehlenbrock
16
Auswertung der Daten vom GPS im ublox Format
16
Auswertung der Daten vom GPS im ublox Format
17
Hold Modus mit PID Regler
17
Hold Modus mit PID Regler
18
Rückstuerz zur Basis Funktion
18
Rückstuerz zur Basis Funktion
19
Stand 7.1.2008
19
Stand 8.1.2008
Line 20... Line 20...
20
 
20
 
21
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22
*/
22
*/
23
#include "main.h"
23
#include "main.h"
Line 61... Line 61...
61
static signed int       hdng_2home,dist_2home; //Richtung und Entfernung zur home Position 
61
static signed int       hdng_2home,dist_2home; //Richtung und Entfernung zur home Position 
62
static signed           gps_tick; //wird bei jedem Update durch das GPS Modul hochgezaehlt 
62
static signed           gps_tick; //wird bei jedem Update durch das GPS Modul hochgezaehlt 
63
static                          short int hold_fast,hold_reset_int; //Flags fuer Hold Regler
63
static                          short int hold_fast,hold_reset_int; //Flags fuer Hold Regler
64
static                          uint8_t *ptr_payload_data;
64
static                          uint8_t *ptr_payload_data;
65
static                          uint8_t *ptr_pac_status;
65
static                          uint8_t *ptr_pac_status;
66
static long int         dist_flown;
66
static  int                     dist_flown;
67
static unsigned int int_ovfl_cnt; // Zaehler fuer Overflows des Integrators
67
static unsigned int int_ovfl_cnt; // Zaehler fuer Overflows des Integrators
Line 68... Line 68...
68
 
68
 
Line 75... Line 75...
75
 
75
 
76
GPS_ABS_POSITION_t              gps_act_position;               // Alle wichtigen Daten zusammengefasst
76
GPS_ABS_POSITION_t              gps_act_position;               // Alle wichtigen Daten zusammengefasst
77
GPS_ABS_POSITION_t              gps_home_position;      // Die Startposition, beim Kalibrieren ermittelt
77
GPS_ABS_POSITION_t              gps_home_position;      // Die Startposition, beim Kalibrieren ermittelt
78
GPS_REL_POSITION_t              gps_rel_act_position;   // Die aktuelle relative Position bezogen auf Home Position
78
GPS_REL_POSITION_t              gps_rel_act_position;   // Die aktuelle relative Position bezogen auf Home Position
79
GPS_REL_POSITION_t              gps_rel_hold_position;  // Die gespeicherte Sollposition fuer GPS_ Hold Mode
79
GPS_REL_POSITION_t              gps_rel_hold_position;  // Die gespeicherte Sollposition fuer GPS_ Hold Mode
Line 80... Line 80...
80
GPS_REL_POSITION_t              gps_rel_start_position; // Die gespeicherte Ausgangsposition fuer GPS_ Home Mode
80
static GPS_REL_POSITION_t               gps_rel_start_position; // Die gespeicherte Ausgangsposition fuer GPS_ Home Mode
81
 
81
 
82
// Initialisierung
82
// Initialisierung
83
void GPS_Neutral(void)
83
void GPS_Neutral(void)
Line 360... Line 360...
360
 
360
 
361
                case GPS_CMD_REQ_HOLD: // Die Lageregelung soll aktiviert werden.
361
                case GPS_CMD_REQ_HOLD: // Die Lageregelung soll aktiviert werden.
362
                        if (gps_state != GPS_CRTL_HOLD_ACTIVE)
362
                        if (gps_state != GPS_CRTL_HOLD_ACTIVE)
363
                        {
363
                        {
364
                                cnt++;
364
                                cnt++;
365
                                if (cnt > 500) // erst nach Verzoegerung 
365
                                if (cnt > 700) // erst nach Verzoegerung 
366
                                {
366
                                {
367
                                        cnt     =       0;
367
                                        cnt     =       0;
368
                                        // aktuelle positionsdaten abspeichern
368
                                        // aktuelle positionsdaten abspeichern
369
                                        if (gps_rel_act_position.status > 0)
369
                                        if (gps_rel_act_position.status > 0)
Line 423... Line 423...
423
                                {
423
                                {
424
                                        gps_tick++;
424
                                        gps_tick++;
425
                                        int d1,d2,d3;
425
                                        int d1,d2,d3;
426
                                        d1      = abs (gps_rel_hold_position.utm_east - gps_rel_act_position.utm_east );
426
                                        d1      = abs (gps_rel_hold_position.utm_east - gps_rel_act_position.utm_east );
427
                                        d2      = abs (gps_rel_hold_position.utm_north - gps_rel_act_position.utm_north );
427
                                        d2      = abs (gps_rel_hold_position.utm_north - gps_rel_act_position.utm_north );
428
                                        d3      = (dist_2home - (int)dist_flown); // Restdistanz zum Ziel       
428
                                        d3      = (dist_2home - dist_flown); // Restdistanz zum Ziel    
-
 
429
                                        debug_gp_2      = dist_2home;  // zum Debuggen
-
 
430
                                        debug_gp_3      = dist_flown; // zum Debuggen
-
 
431
                                        debug_gp_4      = hdng_2home;  // zum Debuggen
-
 
432
//                                      debug_gp_5      = amplfy_speed_north; // zum Debuggen
Line 429... Line 433...
429
       
433
       
430
                                        if (d3 > GPS_G2T_DIST_MAX_STOP) // Schneller Rueckflug, noch weit weg vom Ziel
434
                                        if (d3 > GPS_G2T_DIST_MAX_STOP) // Schneller Rueckflug, noch weit weg vom Ziel
431
                                        {
435
                                        {
432
                                                if ((d1 < GPS_G2T_FAST_TOL)  && (d2 < GPS_G2T_FAST_TOL)) //nur weiter wenn Lage innerhalb der Toleranz
436
                                                if ((d1 < GPS_G2T_FAST_TOL)  && (d2 < GPS_G2T_FAST_TOL)) //nur weiter wenn Lage innerhalb der Toleranz
433
                                                {
437
                                                {
434
                                                        if (gps_g2t_act_v < GPS_G2T_V_MAX) gps_g2t_act_v++;    //Geschwindigkeit langsam erhoehen
438
                                                        if (gps_g2t_act_v < GPS_G2T_V_MAX-2) gps_g2t_act_v +=2;    //Geschwindigkeit langsam erhoehen
435
                                                        dist_flown              +=(long)gps_g2t_act_v; // Vorgabe der Strecke anhand der Geschwindigkeit
439
                                                        dist_flown              +=gps_g2t_act_v; // Vorgabe der Strecke anhand der Geschwindigkeit
436
                                                        gps_sub_state   = GPS_HOME_FAST_IN_TOL;
440
                                                        gps_sub_state   = GPS_HOME_FAST_IN_TOL;
437
                                                }
441
                                                }
438
                                                else    //Den Lageregler in Ruhe arbeiten lassen weil ausserhalb der Toleranz
442
                                                else    //Den Lageregler in Ruhe arbeiten lassen weil ausserhalb der Toleranz
439
                                                {
443
                                                {
440
                                                        if (gps_g2t_act_v > 1) gps_g2t_act_v--; // Geschwindigkeit reduzieren
444
                                                        if (gps_g2t_act_v > 1) gps_g2t_act_v--; // Geschwindigkeit reduzieren
441
                                                        dist_flown++;                                                   //Auch ausserhalb der Toleranz langsam erhoehen
445
                                                        dist_flown++;                                                   //Auch ausserhalb der Toleranz langsam erhoehen
442
                                                        gps_sub_state   = GPS_HOME_FAST_OUTOF_TOL;
446
                                                        gps_sub_state   = GPS_HOME_FAST_OUTOF_TOL;
443
                                                }
447
                                                }
444
                                                hold_reset_int                                  = 0; // Integrator einsschalten  
448
                                                hold_reset_int                                  = 0; // Integrator einsschalten  
445
                                                hold_fast                                               = 1; // Regler fuer schnellen Flug
449
                                                hold_fast                                               = 1; // Regler fuer schnellen Flug
446
                                                dist_frm_start_east                             = (int)((dist_flown * (long)sin_i(hdng_2home))/1000);
450
                                                dist_frm_start_east                             = (int)(((long)dist_flown * (long)sin_i(hdng_2home))/1000);
447
                                                dist_frm_start_north                    = (int)((dist_flown * (long)cos_i(hdng_2home))/1000);
451
                                                dist_frm_start_north                    = (int)(((long)dist_flown * (long)cos_i(hdng_2home))/1000);
448
                                                gps_rel_hold_position.utm_east  = gps_rel_start_position.utm_east  + dist_frm_start_east; //naechster Zielpunkt
452
                                                gps_rel_hold_position.utm_east  = gps_rel_start_position.utm_east  + dist_frm_start_east; //naechster Zielpunkt
449
                                                gps_rel_hold_position.utm_north = gps_rel_start_position.utm_north + dist_frm_start_north; //naechster Zielpunkt
453
                                                gps_rel_hold_position.utm_north = gps_rel_start_position.utm_north + dist_frm_start_north; //naechster Zielpunkt
450
                                        }
454
                                        }
451
                                        else if (d3 > GPS_G2T_DIST_HOLD)   //Das Ziel naehert sich, deswegen abbremsen
455
                                        else if (d3 > GPS_G2T_DIST_HOLD)   //Das Ziel naehert sich, deswegen abbremsen
Line 460... Line 464...
460
                                                        dist_flown++; //Auch ausserhalb der Toleranz langsam erhoehen
464
                                                        dist_flown++; //Auch ausserhalb der Toleranz langsam erhoehen
461
                                                        gps_sub_state   = GPS_HOME_RMPDWN_OUTOF_TOL;
465
                                                        gps_sub_state   = GPS_HOME_RMPDWN_OUTOF_TOL;
462
                                                }                                      
466
                                                }                                      
463
                                                hold_reset_int                                  = 0; // Integrator ausschalten            
467
                                                hold_reset_int                                  = 0; // Integrator ausschalten            
464
                                                hold_fast                                               = 1; // Wieder normal regeln
468
                                                hold_fast                                               = 1; // Wieder normal regeln
465
                                                dist_frm_start_east                             = (int)((dist_flown * (long)sin_i(hdng_2home))/1000);
469
                                                dist_frm_start_east                             = (int)(((long)dist_flown * (long)sin_i(hdng_2home))/1000);
466
                                                dist_frm_start_north                    = (int)((dist_flown * (long)cos_i(hdng_2home))/1000);
470
                                                dist_frm_start_north                    = (int)(((long)dist_flown * (long)cos_i(hdng_2home))/1000);
467
                                                gps_rel_hold_position.utm_east  = gps_rel_start_position.utm_east  + dist_frm_start_east; //naechster Zielpunkt
471
                                                gps_rel_hold_position.utm_east  = gps_rel_start_position.utm_east  + dist_frm_start_east; //naechster Zielpunkt
468
                                                gps_rel_hold_position.utm_north = gps_rel_start_position.utm_north + dist_frm_start_north; //naechster Zielpunkt
472
                                                gps_rel_hold_position.utm_north = gps_rel_start_position.utm_north + dist_frm_start_north; //naechster Zielpunkt
469
                                        }                                                      
473
                                        }                                                      
470
                                        else  //Soll-Ziel fast erreicht, Jetzt noch Reste ausgleichen, weil Zielpunkt nicht exakt bestimmt werden konnte (Fehler in Winkelfkt) 
474
                                        else  //Soll-Ziel fast erreicht, Jetzt noch Reste ausgleichen, weil Zielpunkt nicht exakt bestimmt werden konnte (Fehler in Winkelfkt) 
471
                                        {
475
                                        {
Line 513... Line 517...
513
 
517
 
514
                                #define GPSINT_MAX 3000 // Neues Verfahren ab  30.12.2007  bei Integratoroverflow
518
                                #define GPSINT_MAX 3000 // Neues Verfahren ab  30.12.2007  bei Integratoroverflow
515
                                if ((abs(int_east) > GPSINT_MAX) || (abs(int_north)> GPSINT_MAX))
519
                                if ((abs(int_east) > GPSINT_MAX) || (abs(int_north)> GPSINT_MAX))
516
                                {
520
                                {
517
                                        if (int_ovfl_cnt < 40) int_ovfl_cnt += 1; // Zahl der Overflows zaehlen
-
 
518
//                                      int_east        -= dist_east; auf alten Wert halten
-
 
519
//                                      int_north   -= dist_north;                                      
521
                                        if (int_ovfl_cnt < 40) int_ovfl_cnt += 1; // Zahl der Overflows zaehlen
520
                                }
522
                                }
521
                                if (int_ovfl_cnt > 0) //bei Overflow Wert Integratorwert reduzieren 
523
                                if (int_ovfl_cnt > 0) //bei Overflow Wert Integratorwert reduzieren 
522
                                {
524
                                {
523
                                        int_ovfl_cnt    -= 1;
525
                                        int_ovfl_cnt    -= 1;
Line 528... Line 530...
528
                                if (hold_reset_int > 0)  //Im Schnellen Mode Integrator abschalten
530
                                if (hold_reset_int > 0)  //Im Schnellen Mode Integrator abschalten
529
                                {
531
                                {
530
                                        int_east        = 0;   
532
                                        int_east        = 0;   
531
                                        int_north       = 0;                                   
533
                                        int_north       = 0;                                   
532
                                }
534
                                }
-
 
535
                                if (hold_fast > 0)  //schneller Coming Home Modus
-
 
536
                                {
-
 
537
                                        amplfy_speed_east  = (Parameter_UserParam3/GPS_USR_PAR_FKT);
-
 
538
                                        amplfy_speed_north = (Parameter_UserParam3/GPS_USR_PAR_FKT);
-
 
539
                                }
-
 
540
                                else  //langsamer Holdmodus
-
 
541
                                {
-
 
542
                                        // Verstaerkungsfaktor fuer Geschwindigkeit ermitteln um exponentielles Verhalten zu erzielen
-
 
543
                                        amplfy_speed_east  = (((abs(speed_east)) *(DIFF_Y_MAX-1)*10)/DIFF_X_MAX) +10;
-
 
544
                                        amplfy_speed_north = (((abs(speed_north))*(DIFF_Y_MAX-1)*10)/DIFF_X_MAX) +10;
-
 
545
                                        if (amplfy_speed_east  > (DIFF_Y_MAX *10)) amplfy_speed_east  = DIFF_Y_MAX *10; // Begrenzung
-
 
546
                                        if (amplfy_speed_north > (DIFF_Y_MAX *10)) amplfy_speed_north = DIFF_Y_MAX *10; // Begrenzung
-
 
547
                                        amplfy_speed_east  *= (Parameter_UserParam3/GPS_USR_PAR_FKT);
-
 
548
                                        amplfy_speed_north *= (Parameter_UserParam3/GPS_USR_PAR_FKT);
-
 
549
                                        amplfy_speed_east   /= 10; //Faktor 10 wieder rausnehmen
-
 
550
                                        amplfy_speed_north  /= 10; //Faktor 10 wieder rausnehmen
-
 
551
                                }
-
 
552
 
Line 533... Line -...
533
 
-
 
534
                                // Verstaerkungsfaktor fuer Geschwindigkeit ermitteln um exponentielles Verhalten zu erzielen
-
 
535
                                amplfy_speed_east  = (((abs(speed_east)) *(DIFF_Y_MAX-1)*10)/DIFF_X_MAX) +10;
-
 
536
                                amplfy_speed_north = (((abs(speed_north))*(DIFF_Y_MAX-1)*10)/DIFF_X_MAX) +10;
-
 
537
                                if (amplfy_speed_east  > (DIFF_Y_MAX *10)) amplfy_speed_east  = DIFF_Y_MAX *10; // Begrenzung
-
 
538
                                if (amplfy_speed_north > (DIFF_Y_MAX *10)) amplfy_speed_north = DIFF_Y_MAX *10; // Begrenzung
-
 
539
                                amplfy_speed_east  *= (Parameter_UserParam3/GPS_USR_PAR_FKT);
-
 
540
                                amplfy_speed_north *= (Parameter_UserParam3/GPS_USR_PAR_FKT);
-
 
541
                                amplfy_speed_east   /= 10; //Faktor 10 wieder rausnehmen
-
 
542
                                amplfy_speed_north  /= 10; //Faktor 10 wieder rausnehmen
553
 
543
                                #define GPS_SPEED_SCALE 5
554
                                #define GPS_SPEED_SCALE 5
544
                                speed_east  /= GPS_SPEED_SCALE; // Wegen overflow Gefahr Wert jetzt schon runterskalieren
555
                                speed_east  /= GPS_SPEED_SCALE; // Wegen overflow Gefahr Wert jetzt schon runterskalieren
545
                                speed_north /= GPS_SPEED_SCALE; // Wegen overflow Gefahr Wert jetzt schon runterskalieren
-
 
546
                                debug_gp_2      = speed_east;  // zum Debuggen
-
 
547
                                debug_gp_3      = speed_north; // zum Debuggen
-
 
548
                                debug_gp_4      = amplfy_speed_east;  // zum Debuggen
-
 
Line 549... Line 556...
549
                                debug_gp_5      = amplfy_speed_north; // zum Debuggen
556
                                speed_north /= GPS_SPEED_SCALE; // Wegen overflow Gefahr Wert jetzt schon runterskalieren
550
 
557
 
551
 
558
 
Line 595... Line 602...
595
                                }
602
                                }
596
                                GPS_dist_2trgt  = (int) dev;
603
                                GPS_dist_2trgt  = (int) dev;
597
                                // Winkel und Distanz in Nick und Rollgroessen umrechnen
604
                                // Winkel und Distanz in Nick und Rollgroessen umrechnen
598
                                n  = (int) +( (dev * (long) sin_i(GPS_hdng_rel_2trgt))/1000); //Rollwert bestimmen
605
                                n  = (int) +( (dev * (long) sin_i(GPS_hdng_rel_2trgt))/1000); //Rollwert bestimmen
599
                                n1 = (int) -( (dev * (long) cos_i(GPS_hdng_rel_2trgt))/1000); //Nickwert bestimmen
606
                                n1 = (int) -( (dev * (long) cos_i(GPS_hdng_rel_2trgt))/1000); //Nickwert bestimmen
600
 
-
 
601
//                              GPS_Roll = (int) +( (dev * (long) sin_i(GPS_hdng_rel_2trgt))/1000); 
-
 
602
//                              GPS_Nick = (int) -( (dev * (long) cos_i(GPS_hdng_rel_2trgt))/1000);
-
 
Line 603... Line 607...
603
                                       
607
                                       
604
                                if (n > (GPS_NICKROLL_MAX * GPS_V)) n = (GPS_NICKROLL_MAX * GPS_V);
608
                                if (n > (GPS_NICKROLL_MAX * GPS_V)) n = (GPS_NICKROLL_MAX * GPS_V);
605
                                else if (n < -(GPS_NICKROLL_MAX * GPS_V)) n = -(GPS_NICKROLL_MAX * GPS_V);
609
                                else if (n < -(GPS_NICKROLL_MAX * GPS_V)) n = -(GPS_NICKROLL_MAX * GPS_V);
606
                                if (n1 > (GPS_NICKROLL_MAX * GPS_V)) n1 = (GPS_NICKROLL_MAX * GPS_V);
610
                                if (n1 > (GPS_NICKROLL_MAX * GPS_V)) n1 = (GPS_NICKROLL_MAX * GPS_V);
Line 611... Line 615...
611
/*                              n                       = sin_i((GPS_Roll*90)/(GPS_NICKROLL_MAX * GPS_V));
615
/*                              n                       = sin_i((GPS_Roll*90)/(GPS_NICKROLL_MAX * GPS_V));
612
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
616
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
613
                                GPS_Roll        = (int) n_l;
617
                                GPS_Roll        = (int) n_l;
614
                                n                       = sin_i((GPS_Nick*90)/(GPS_NICKROLL_MAX * GPS_V));
618
                                n                       = sin_i((GPS_Nick*90)/(GPS_NICKROLL_MAX * GPS_V));
615
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
619
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
616
                                GPS_Nick        = (int) n_l;
620
                                GPS_Nick        = (int) n_l;*/                           
617
*/                               
-
 
Line 618... Line 621...
618
 
621
 
619
                                if ((abs(dist_east) > GPS_DIST_MAX) || (abs(dist_north) > GPS_DIST_MAX))  // bei zu grossem Abstand abbrechen
622
                                if ((abs(dist_east) > GPS_DIST_MAX) || (abs(dist_north) > GPS_DIST_MAX))  // bei zu grossem Abstand abbrechen
620
                                {
623
                                {
621
                                        GPS_Roll        = 0;
624
                                        GPS_Roll        = 0;