Subversion Repositories NaviCtrl

Rev

Rev 483 | Rev 491 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 483 Rev 489
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/*#######################################################################################*/
2
/*#######################################################################################*/
3
 
3
 
4
// IMPORTANT NOTE:
4
// IMPORTANT NOTE:
5
 
5
 
6
// This is only a dummy implementation for errorfree compiling of the NaviCtrl sources.
6
// This is only a dummy implementation for errorfree compiling of the NaviCtrl sources.
7
 
7
 
8
// The GPS navigation routines are NOT included !
8
// The GPS navigation routines are NOT included !
9
 
9
 
10
/*#######################################################################################*/
10
/*#######################################################################################*/
11
/*#######################################################################################*/
11
/*#######################################################################################*/
12
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
12
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
13
/*#######################################################################################*/
13
/*#######################################################################################*/
14
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// + Copyright (c) 2008 Ingo Busker, Holger Buss
15
// + Copyright (c) 2008 Ingo Busker, Holger Buss
16
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
16
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
17
// + FOR NON COMMERCIAL USE ONLY
17
// + FOR NON COMMERCIAL USE ONLY
18
// + www.MikroKopter.com
18
// + www.MikroKopter.com
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
20
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
21
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
21
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
22
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
22
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
23
// + bzgl. der Nutzungsbedingungen aufzunehmen.
23
// + bzgl. der Nutzungsbedingungen aufzunehmen.
24
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
24
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
25
// + Verkauf von Luftbildaufnahmen, usw.
25
// + Verkauf von Luftbildaufnahmen, usw.
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
27
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
28
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
28
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
30
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
31
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
31
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
32
// + eindeutig als Ursprung verlinkt werden
32
// + eindeutig als Ursprung verlinkt werden
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
34
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
35
// + Benutzung auf eigene Gefahr
35
// + Benutzung auf eigene Gefahr
36
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
36
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
37
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
38
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
39
// + mit unserer Zustimmung zulässig
39
// + mit unserer Zustimmung zulässig
40
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
41
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
42
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
43
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
44
// + this list of conditions and the following disclaimer.
44
// + this list of conditions and the following disclaimer.
45
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
45
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
46
// +     from this software without specific prior written permission.
46
// +     from this software without specific prior written permission.
47
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
47
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
48
// +     for non-commercial use (directly or indirectly)
48
// +     for non-commercial use (directly or indirectly)
49
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
49
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
50
// +     with our written permission
50
// +     with our written permission
51
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
51
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
52
// +     clearly linked as origin
52
// +     clearly linked as origin
53
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
53
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
54
//
54
//
55
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
56
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
58
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
59
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65
// +  POSSIBILITY OF SUCH DAMAGE.
65
// +  POSSIBILITY OF SUCH DAMAGE.
66
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67
#include <stdio.h>
67
#include <stdio.h>
68
#include <stdlib.h>
68
#include <stdlib.h>
69
#include <math.h>
69
#include <math.h>
70
#include "91x_lib.h"
70
#include "91x_lib.h"
71
#include "main.h"
71
#include "main.h"
72
#include "uart1.h"
72
#include "uart1.h"
73
#include "GPS.h"
73
#include "GPS.h"
74
#include "timer1.h"
74
#include "timer1.h"
75
#include "spi_slave.h"
75
#include "spi_slave.h"
76
#include "waypoints.h"
76
#include "waypoints.h"
77
#include "i2c1.h"
77
#include "i2c.h"
78
 
78
 
79
 
79
 
80
#define M_PI_180        (M_PI / 180.0f)
80
#define M_PI_180        (M_PI / 180.0f)
81
#define GPS_UPDATETIME_MS 200           // 200ms is 5 Hz
81
#define GPS_UPDATETIME_MS 200           // 200ms is 5 Hz
82
typedef enum
82
typedef enum
83
{
83
{
84
        GPS_FLIGHT_MODE_UNDEF,
84
        GPS_FLIGHT_MODE_UNDEF,
85
        GPS_FLIGHT_MODE_FREE,
85
        GPS_FLIGHT_MODE_FREE,
86
        GPS_FLIGHT_MODE_AID,
86
        GPS_FLIGHT_MODE_AID,
87
        GPS_FLIGHT_MODE_WAYPOINT
87
        GPS_FLIGHT_MODE_WAYPOINT
88
} GPS_FlightMode_t;
88
} GPS_FlightMode_t;
89
 
89
 
90
typedef struct
90
typedef struct
91
{
91
{
92
        float Gain;
92
        float Gain;
93
        float P;
93
        float P;
94
        float I;
94
        float I;
95
        float D;
95
        float D;
96
        float A;
96
        float A;
97
        float ACC;
97
        float ACC;
98
        s32 P_Limit;
98
        s32 P_Limit;
99
        s32 I_Limit;
99
        s32 I_Limit;
100
        s32 D_Limit;
100
        s32 D_Limit;
101
        s32 PID_Limit;
101
        s32 PID_Limit;
102
        u32 BrakingDuration;
102
        u32 BrakingDuration;
103
        u8 MinSat;
103
        u8 MinSat;
104
        s8 StickThreshold;
104
        s8 StickThreshold;
105
        float WindCorrection;
105
        float WindCorrection;
106
        float SpeedCompensation;
106
        float SpeedCompensation;
107
        s32 OperatingRadius;
107
        s32 OperatingRadius;
108
        GPS_FlightMode_t  FlightMode;
108
        GPS_FlightMode_t  FlightMode;
109
} __attribute__((packed)) GPS_Parameter_t;
109
} __attribute__((packed)) GPS_Parameter_t;
110
 
110
 
111
typedef struct
111
typedef struct
112
{
112
{
113
        u8  Status;             // invalid, newdata, processed
113
        u8  Status;             // invalid, newdata, processed
114
        s32 North;              // in cm
114
        s32 North;              // in cm
115
        s32 East;               // in cm
115
        s32 East;               // in cm
116
        s32 Bearing;    // in deg
116
        s32 Bearing;    // in deg
117
        s32 Distance;   // in cm
117
        s32 Distance;   // in cm
118
} __attribute__((packed)) GPS_Deviation_t;
118
} __attribute__((packed)) GPS_Deviation_t;
119
GPS_Deviation_t CurrentTargetDeviation;         // Deviation from Target
119
GPS_Deviation_t CurrentTargetDeviation;         // Deviation from Target
120
GPS_Deviation_t CurrentHomeDeviation;           // Deviation from Home
120
GPS_Deviation_t CurrentHomeDeviation;           // Deviation from Home
121
GPS_Deviation_t TargetHomeDeviation;            // Deviation from Target to Home
121
GPS_Deviation_t TargetHomeDeviation;            // Deviation from Target to Home
122
 
122
 
123
GPS_Stick_t             GPS_Stick;
123
GPS_Stick_t             GPS_Stick;
124
 
124
 
125
// the CAM orientation
125
// the CAM orientation
126
CAM_Orientation_t CAM_Orientation;
126
CAM_Orientation_t CAM_Orientation;
127
 
127
 
128
GPS_Parameter_t GPS_Parameter;
128
GPS_Parameter_t GPS_Parameter;
129
 
129
 
130
// the gps reference positions
130
// the gps reference positions
131
GPS_Pos_t GPS_HoldPosition      = {0,0,0, INVALID};                     // the hold position
131
GPS_Pos_t GPS_HoldPosition      = {0,0,0, INVALID};                     // the hold position
132
GPS_Pos_t GPS_HomePosition      = {0,0,0, INVALID};                     // the home position
132
GPS_Pos_t GPS_HomePosition      = {0,0,0, INVALID};                     // the home position
133
GPS_Pos_t * GPS_pTargetPosition = NULL;                             // pointer to the actual target position
133
GPS_Pos_t * GPS_pTargetPosition = NULL;                             // pointer to the actual target position
134
u32 GPS_TargetRadius = 0;                                                               // catch radius for target area
134
u32 GPS_TargetRadius = 0;                                                               // catch radius for target area
135
Point_t* GPS_pWaypoint = NULL;                                          // pointer to the actual waypoint
135
Point_t* GPS_pWaypoint = NULL;                                          // pointer to the actual waypoint
136
 
136
 
137
//-------------------------------------------------------------
137
//-------------------------------------------------------------
138
// Update GPSParamter
138
// Update GPSParamter
139
void GPS_UpdateParameter(void)
139
void GPS_UpdateParameter(void)
140
{
140
{
141
}
141
}
142
 
142
 
143
//-------------------------------------------------------------
143
//-------------------------------------------------------------
144
// This function defines a good GPS signal condition
144
// This function defines a good GPS signal condition
145
u8 GPS_IsSignalOK(void)
145
u8 GPS_IsSignalOK(void)
146
{
146
{
147
        return 0;
147
        return 0;
148
}
148
}
149
 
149
 
150
//------------------------------------------------------------
150
//------------------------------------------------------------
151
// Checks for manual control action
151
// Checks for manual control action
152
u8 GPS_IsManuallyControlled(void)
152
u8 GPS_IsManuallyControlled(void)
153
{
153
{
154
        return 0;
154
        return 0;
155
}
155
}
156
 
156
 
157
//------------------------------------------------------------
157
//------------------------------------------------------------
158
// copy GPS position from source position to target position
158
// copy GPS position from source position to target position
159
u8 GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt)
159
u8 GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt)
160
{
160
{
161
        return 0;
161
        return 0;
162
}
162
}
163
 
163
 
164
//------------------------------------------------------------
164
//------------------------------------------------------------
165
// clear position data
165
// clear position data
166
u8 GPS_ClearPosition(GPS_Pos_t * pGPSPos)
166
u8 GPS_ClearPosition(GPS_Pos_t * pGPSPos)
167
{
167
{
168
        return 0;
168
        return 0;
169
}
169
}
170
 
170
 
171
 
171
 
172
//------------------------------------------------------------
172
//------------------------------------------------------------
173
void GPS_Neutral(void)
173
void GPS_Neutral(void)
174
{
174
{
175
}
175
}
176
 
176
 
177
//------------------------------------------------------------
177
//------------------------------------------------------------
178
void GPS_Init(void)
178
void GPS_Init(void)
179
{
179
{
180
}
180
}
181
 
181
 
182
//------------------------------------------------------------
182
//------------------------------------------------------------
183
// calculate the bearing to target position from its deviation
183
// calculate the bearing to target position from its deviation
184
s32 DirectionToTarget_N_E(float northdev, float eastdev)
184
s32 DirectionToTarget_N_E(float northdev, float eastdev)
185
{
185
{
186
        return 0;
186
        return 0;
187
}
187
}
188
 
188
 
189
 
189
 
190
//------------------------------------------------------------
190
//------------------------------------------------------------
191
// Rescale xy-vector length if length limit is violated
191
// Rescale xy-vector length if length limit is violated
192
// returns vector len after scaling
192
// returns vector len after scaling
193
s32 GPS_LimitXY(s32 *x, s32 *y, s32 limit)
193
s32 GPS_LimitXY(s32 *x, s32 *y, s32 limit)
194
{
194
{
195
        return 0;
195
        return 0;
196
}
196
}
197
 
197
 
198
//------------------------------------------------------------
198
//------------------------------------------------------------
199
// transform the integer deg into float radians
199
// transform the integer deg into float radians
200
inline double RadiansFromGPS(s32 deg)
200
inline double RadiansFromGPS(s32 deg)
201
{
201
{
202
        return 0.0;
202
        return 0.0;
203
}
203
}
204
 
204
 
205
//------------------------------------------------------------
205
//------------------------------------------------------------
206
// transform the integer deg into float deg
206
// transform the integer deg into float deg
207
inline double DegFromGPS(s32 deg)
207
inline double DegFromGPS(s32 deg)
208
{
208
{
209
        return 0.0;
209
        return 0.0;
210
}
210
}
211
 
211
 
212
//------------------------------------------------------------
212
//------------------------------------------------------------
213
// calculate the deviation from the current position to the target position
213
// calculate the deviation from the current position to the target position
214
u8 GPS_CalculateDeviation(GPS_Pos_t * pCurrentPos, GPS_Pos_t * pTargetPos, GPS_Deviation_t* pDeviationFromTarget)
214
u8 GPS_CalculateDeviation(GPS_Pos_t * pCurrentPos, GPS_Pos_t * pTargetPos, GPS_Deviation_t* pDeviationFromTarget)
215
{
215
{
216
        return 0;
216
        return 0;
217
}
217
}
218
 
218
 
219
void GPS_Navigation(gps_data_t *pGPS_Data, GPS_Stick_t* pGPS_Stick)
219
void GPS_Navigation(gps_data_t *pGPS_Data, GPS_Stick_t* pGPS_Stick)
220
{
220
{
221
        return;
221
        return;
222
}
222
}
223
 
223
 
224
void CalcHeadFree(void)
224
void CalcHeadFree(void)
225
{
225
{
226
  return;
226
  return;
227
}
227
}
228
 
228