Rev 89 | Rev 93 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 89 | Rev 92 | ||
---|---|---|---|
Line 93... | Line 93... | ||
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 | u32 P_Limit; |
99 | s32 I_Limit; |
99 | u32 I_Limit; |
100 | s32 D_Limit; |
100 | u32 D_Limit; |
101 | s32 PID_Limit; |
101 | u32 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 | u32 OperatingRadius; |
108 | GPS_FlightMode_t FlightMode; |
108 | GPS_FlightMode_t FlightMode; |
109 | } __attribute__((packed)) GPS_Parameter_t; |
109 | } __attribute__((packed)) GPS_Parameter_t; |
Line 110... | Line 110... | ||
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 | u32 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 |
Line 125... | Line 125... | ||
125 | 125 | ||
126 | // the gps reference positions |
126 | // the gps reference positions |
127 | GPS_Pos_t GPS_HoldPosition = {0,0,0, INVALID}; // the hold position |
127 | GPS_Pos_t GPS_HoldPosition = {0,0,0, INVALID}; // the hold position |
128 | GPS_Pos_t GPS_HomePosition = {0,0,0, INVALID}; // the home position |
128 | GPS_Pos_t GPS_HomePosition = {0,0,0, INVALID}; // the home position |
- | 129 | GPS_Pos_t * GPS_pTargetPosition = NULL; // pointer to the actual target position |
|
129 | GPS_Pos_t * GPS_pTargetPosition = NULL; // pointer to the actual target position |
130 | u32 GPS_TargetRadius = 0; // catch radius for target area |
Line 130... | Line 131... | ||
130 | Waypoint_t* GPS_pWaypoint = NULL; // pointer to the actual waypoint |
131 | Waypoint_t* GPS_pWaypoint = NULL; // pointer to the actual waypoint |
131 | 132 | ||
132 | //------------------------------------------------------------- |
133 | //------------------------------------------------------------- |
Line 160... | Line 161... | ||
160 | { |
161 | { |
161 | // update parameter from FC |
162 | // update parameter from FC |
162 | if(StopNavigation) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
163 | if(StopNavigation) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
163 | else |
164 | else |
164 | { |
165 | { |
165 | if (Parameter.NaviGpsModeControl < 50) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_AID; |
166 | if (Parameter.NaviGpsModeControl < 50) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
166 | else if(Parameter.NaviGpsModeControl < 180) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
167 | else if(Parameter.NaviGpsModeControl < 180) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_AID; |
167 | else GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT; |
168 | else GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT; |
168 | } |
169 | } |
169 | GPS_Parameter.Gain = (float)Parameter.NaviGpsGain; |
170 | GPS_Parameter.Gain = (float)Parameter.NaviGpsGain; |
170 | GPS_Parameter.P = (float)Parameter.NaviGpsP; |
171 | GPS_Parameter.P = (float)Parameter.NaviGpsP; |
171 | GPS_Parameter.I = (float)Parameter.NaviGpsI; |
172 | GPS_Parameter.I = (float)Parameter.NaviGpsI; |
172 | GPS_Parameter.D = (float)Parameter.NaviGpsD; |
173 | GPS_Parameter.D = (float)Parameter.NaviGpsD; |
173 | GPS_Parameter.A = (float)Parameter.NaviGpsD; |
174 | GPS_Parameter.A = (float)Parameter.NaviGpsD; |
174 | GPS_Parameter.ACC = (float)Parameter.NaviGpsACC; |
175 | GPS_Parameter.ACC = (float)Parameter.NaviGpsACC; |
175 | GPS_Parameter.P_Limit = (s32)Parameter.NaviGpsPLimit; |
176 | GPS_Parameter.P_Limit = (u32)Parameter.NaviGpsPLimit; |
176 | GPS_Parameter.I_Limit = (s32)Parameter.NaviGpsILimit; |
177 | GPS_Parameter.I_Limit = (u32)Parameter.NaviGpsILimit; |
177 | GPS_Parameter.D_Limit = (s32)Parameter.NaviGpsDLimit; |
178 | GPS_Parameter.D_Limit = (u32)Parameter.NaviGpsDLimit; |
178 | GPS_Parameter.PID_Limit = 2* (s32)Parameter.NaviAngleLimitation; |
179 | GPS_Parameter.PID_Limit = 2* (u32)Parameter.NaviAngleLimitation; |
179 | GPS_Parameter.BrakingDuration = (u32)Parameter.NaviPH_LoginTime; |
180 | GPS_Parameter.BrakingDuration = (u32)Parameter.NaviPH_LoginTime; |
180 | GPS_Parameter.SpeedCompensation = (float)Parameter.NaviSpeedCompensation; |
181 | GPS_Parameter.SpeedCompensation = (float)Parameter.NaviSpeedCompensation; |
181 | GPS_Parameter.MinSat = (u8)Parameter.NaviGpsMinSat; |
182 | GPS_Parameter.MinSat = (u8)Parameter.NaviGpsMinSat; |
182 | GPS_Parameter.StickThreshold = (s8)Parameter.NaviStickThreshold; |
183 | GPS_Parameter.StickThreshold = (s8)Parameter.NaviStickThreshold; |
183 | GPS_Parameter.WindCorrection = (float)Parameter.NaviWindCorrection; |
184 | GPS_Parameter.WindCorrection = (float)Parameter.NaviWindCorrection; |
184 | GPS_Parameter.OperatingRadius = (s32)Parameter.NaviOperatingRadius * 100; // conversion of m to cm |
185 | GPS_Parameter.OperatingRadius = (u32)Parameter.NaviOperatingRadius * 100; // conversion of m to cm |
185 | } |
186 | } |
186 | // FlightMode changed? |
187 | // FlightMode changed? |
187 | if(GPS_Parameter.FlightMode != FlightMode_Old) BeepTime = 100; // beep to indicate that mode has switched |
188 | if(GPS_Parameter.FlightMode != FlightMode_Old) BeepTime = 100; // beep to indicate that mode has switched |
188 | FlightMode_Old = GPS_Parameter.FlightMode; |
189 | FlightMode_Old = GPS_Parameter.FlightMode; |
189 | } |
190 | } |
Line 275... | Line 276... | ||
275 | } |
276 | } |
Line 276... | Line 277... | ||
276 | 277 | ||
277 | 278 | ||
278 | //------------------------------------------------------------ |
279 | //------------------------------------------------------------ |
279 | // Rescale xy-vector length if length limit is violated |
280 | // Rescale xy-vector length if length limit is violated |
280 | void GPS_LimitXY(s32 *x, s32 *y, s32 limit) |
281 | void GPS_LimitXY(s32 *x, s32 *y, u32 limit) |
281 | { |
282 | { |
282 | s32 dist; |
283 | u32 dist; |
283 | dist = (s32)hypot(*x,*y); // the length of the vector |
284 | dist = (u32)hypot(*x,*y); // the length of the vector |
284 | if (dist == 0) |
285 | if (dist == 0) |
285 | { |
286 | { |
286 | *x = 0; |
287 | *x = 0; |
Line 343... | Line 344... | ||
343 | pDeviationFromTarget->North = (s32)(11119492.7f * temp2); |
344 | pDeviationFromTarget->North = (s32)(11119492.7f * temp2); |
344 | pDeviationFromTarget->East = (s32)(11119492.7f * temp1); |
345 | pDeviationFromTarget->East = (s32)(11119492.7f * temp1); |
345 | // If the position deviation is small enough to neglect the earth curvature |
346 | // If the position deviation is small enough to neglect the earth curvature |
346 | // (this is for our application always fulfilled) the distance to target |
347 | // (this is for our application always fulfilled) the distance to target |
347 | // can be calculated by the pythagoras of north and east deviation. |
348 | // can be calculated by the pythagoras of north and east deviation. |
348 | pDeviationFromTarget->Distance = (s32)(11119492.7f * hypot(temp1, temp2)); |
349 | pDeviationFromTarget->Distance = (u32)(11119492.7f * hypot(temp1, temp2)); |
349 | if (pDeviationFromTarget->Distance == 0L) pDeviationFromTarget->Bearing = 0L; |
350 | if (pDeviationFromTarget->Distance == 0L) pDeviationFromTarget->Bearing = 0L; |
350 | else pDeviationFromTarget->Bearing = DirectionToTarget_N_E(temp2, temp1); |
351 | else pDeviationFromTarget->Bearing = DirectionToTarget_N_E(temp2, temp1); |
351 | pDeviationFromTarget->Status = NEWDATA; |
352 | pDeviationFromTarget->Status = NEWDATA; |
352 | return TRUE; |
353 | return TRUE; |
Line 369... | Line 370... | ||
369 | // pointer to current target position |
370 | // pointer to current target position |
370 | static GPS_Pos_t * pTargetPositionOld = NULL; |
371 | static GPS_Pos_t * pTargetPositionOld = NULL; |
371 | static Waypoint_t* GPS_pWaypointOld = NULL; |
372 | static Waypoint_t* GPS_pWaypointOld = NULL; |
Line 372... | Line 373... | ||
372 | 373 | ||
373 | static GPS_Pos_t RangedTargetPosition = {0,0,0, INVALID}; // the limited target position, this is derived from the target position with repect to the operating radius |
374 | static GPS_Pos_t RangedTargetPosition = {0,0,0, INVALID}; // the limited target position, this is derived from the target position with repect to the operating radius |
374 | static s32 OperatingRadiusOld = -1; |
- | |
375 | static u8 WPArrived = FALSE; |
375 | static u32 OperatingRadiusOld = -1; |
Line 376... | Line 376... | ||
376 | static u32 WPTime = 0; |
376 | static u32 WPTime = 0; |
377 | 377 | ||
378 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
378 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 399... | Line 399... | ||
399 | // wait maximum of 3 times the normal data update time before data timemout |
399 | // wait maximum of 3 times the normal data update time before data timemout |
400 | GPSDataTimeout = SetDelay(3 * GPS_UPDATETIME_MS); |
400 | GPSDataTimeout = SetDelay(3 * GPS_UPDATETIME_MS); |
401 | beep_rythm++; |
401 | beep_rythm++; |
Line 402... | Line 402... | ||
402 | 402 | ||
403 | // debug |
403 | // debug |
404 | DebugOut.Analog[21] = (u16)GPSData.Speed_North; |
404 | DebugOut.Analog[21] = (s16)GPSData.Speed_North; |
405 | DebugOut.Analog[22] = (u16)GPSData.Speed_East; |
405 | DebugOut.Analog[22] = (s16)GPSData.Speed_East; |
Line 406... | Line 406... | ||
406 | DebugOut.Analog[31] = (u16)GPSData.NumOfSats; |
406 | DebugOut.Analog[31] = (s16)GPSData.NumOfSats; |
407 | 407 | ||
408 | // If GPS signal condition is sufficient for a reliable position measurement |
408 | // If GPS signal condition is sufficient for a reliable position measurement |
409 | if(GPS_IsSignalOK()) |
409 | if(GPS_IsSignalOK()) |
Line 427... | Line 427... | ||
427 | // check for current flight mode and set the target pointer GPS_pTargetPosition respectively |
427 | // check for current flight mode and set the target pointer GPS_pTargetPosition respectively |
428 | switch(GPS_Parameter.FlightMode) |
428 | switch(GPS_Parameter.FlightMode) |
429 | { |
429 | { |
430 | // the GPS control is deactived |
430 | // the GPS control is deactived |
431 | case GPS_FLIGHT_MODE_FREE: |
431 | case GPS_FLIGHT_MODE_FREE: |
432 | NaviData.NCFlags &= ~(NC_FLAG_PH | NC_FLAG_CH); |
432 | NCFlags &= ~(NC_FLAG_PH | NC_FLAG_CH); |
433 | NaviData.NCFlags |= NC_FLAG_FREE; |
433 | NCFlags |= NC_FLAG_FREE; |
434 | GPS_Parameter.PID_Limit = 0; // disables PID output |
434 | GPS_Parameter.PID_Limit = 0; // disables PID output |
435 | // update hold position |
435 | // update hold position |
436 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
436 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
437 | // no target position |
437 | // no target position |
438 | GPS_pTargetPosition = NULL; |
438 | GPS_pTargetPosition = NULL; |
- | 439 | GPS_TargetRadius = 0; |
|
439 | break; |
440 | break; |
Line 440... | Line 441... | ||
440 | 441 | ||
441 | // the GPS supports the position hold, if the pilot takes no action |
442 | // the GPS supports the position hold, if the pilot takes no action |
442 | case GPS_FLIGHT_MODE_AID: |
443 | case GPS_FLIGHT_MODE_AID: |
443 | NaviData.NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_CH); |
444 | NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_CH); |
444 | NaviData.NCFlags |= NC_FLAG_PH; |
445 | NCFlags |= NC_FLAG_PH; |
445 | // reset WPList to begin |
446 | // reset WPList to begin |
Line 446... | Line 447... | ||
446 | GPS_pWaypoint = WPList_Begin(); |
447 | GPS_pWaypoint = WPList_Begin(); |
447 | 448 | ||
448 | if(GPS_IsManuallyControlled()) |
449 | if(GPS_IsManuallyControlled()) |
449 | { |
450 | { |
450 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
451 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
- | 452 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
|
451 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
453 | GPS_pTargetPosition = NULL; |
452 | GPS_pTargetPosition = NULL; |
454 | GPS_TargetRadius = 0; |
453 | } |
455 | } |
454 | else |
456 | else |
- | 457 | { |
|
455 | { |
458 | GPS_pTargetPosition = &GPS_HoldPosition; |
456 | GPS_pTargetPosition = &GPS_HoldPosition; |
459 | GPS_TargetRadius = 100; // 1 meter |
Line 457... | Line 460... | ||
457 | } |
460 | } |
458 | break; |
461 | break; |
459 | 462 | ||
460 | // the GPS control is directed to a target position |
463 | // the GPS control is directed to a target position |
461 | // given by a waypoint or by the home position |
464 | // given by a waypoint or by the home position |
Line 462... | Line 465... | ||
462 | case GPS_FLIGHT_MODE_WAYPOINT: |
465 | case GPS_FLIGHT_MODE_WAYPOINT: |
463 | NaviData.NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_PH); |
466 | NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_PH); |
464 | NaviData.NCFlags |= NC_FLAG_CH; |
467 | NCFlags |= NC_FLAG_CH; |
465 | 468 | ||
466 | if(GPS_IsManuallyControlled()) // the human pilot takes the action |
469 | if(GPS_IsManuallyControlled()) // the human pilot takes the action |
- | 470 | { |
|
467 | { |
471 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
468 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
472 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); // update hold position |
469 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); // update hold position |
473 | GPS_pTargetPosition = NULL; // set target position invalid |
470 | GPS_pTargetPosition = NULL; // set target position invalid |
474 | GPS_TargetRadius = 0; |
471 | } |
475 | } |
472 | else // no manual control -> gps position hold active |
476 | else // no manual control -> gps position hold active |
473 | { |
477 | { |
474 | // waypoint trigger logic |
478 | // waypoint trigger logic |
475 | if(GPS_pWaypoint != NULL) // waypoint exist |
479 | if(GPS_pWaypoint != NULL) // waypoint exist |
476 | { |
- | |
477 | if(GPS_pWaypoint->Position.Status == INVALID) // should never happen |
480 | { |
478 | { |
481 | if(GPS_pWaypoint->Position.Status == INVALID) // should never happen |
479 | GPS_pWaypoint = WPList_Next(); // goto to next WP |
482 | { |
480 | WPArrived = FALSE; |
483 | GPS_pWaypoint = WPList_Next(); // goto to next WP |
481 | BeepTime = 255; |
484 | BeepTime = 255; |
482 | } |
485 | } |
483 | else // waypoint position is valid |
486 | else // waypoint position is valid |
484 | { |
487 | { |
485 | // check if the pointer to the waypoint has been changed or the data have been updated |
- | |
486 | if((GPS_pWaypoint != GPS_pWaypointOld) || (GPS_pWaypoint->Position.Status == NEWDATA)) |
- | |
487 | { |
- | |
488 | GPS_pWaypointOld = GPS_pWaypoint; |
- | |
489 | // reset the arrived bit to break a pending HoldTime of the old WP |
- | |
490 | WPArrived = FALSE; |
- | |
491 | } |
- | |
492 | - | ||
493 | if(CurrentTargetDeviation.Status != INVALID) |
- | |
494 | { // if the waypoint was not catched and the target area has been reached |
- | |
495 | if(!WPArrived && (CurrentTargetDeviation.Distance < (GPS_pWaypoint->ToleranceRadius * 100))) |
- | |
496 | { |
488 | // check if the pointer to the waypoint has been changed or the data have been updated |
497 | WPArrived = TRUE; |
489 | if((GPS_pWaypoint != GPS_pWaypointOld) || (GPS_pWaypoint->Position.Status == NEWDATA)) |
498 | WPTime = SetDelay(GPS_pWaypoint->HoldTime * 1000); // set hold time stamp |
490 | { |
499 | } |
491 | GPS_pWaypointOld = GPS_pWaypoint; |
500 | } |
492 | } |
501 | // if WP has been reached once, wait hold time before trigger to next one |
493 | // if WP has been reached once, wait hold time before trigger to next one |
502 | if(WPArrived) |
494 | if(NCFlags & NC_FLAG_TARGET_REACHED) |
503 | { |
495 | { |
504 | /* ToDo: Adjust GPS_pWaypoint->Heading, GPS_pWaypoint->Event handling */ |
- | |
505 | if(CheckDelay(WPTime)) |
496 | /* ToDo: Adjust GPS_pWaypoint->Heading, GPS_pWaypoint->Event handling */ |
506 | { |
497 | if(CheckDelay(WPTime)) |
- | 498 | { |
|
- | 499 | GPS_pWaypoint = WPList_Next(); // goto to next waypoint, return NULL if end of list has been reached |
|
- | 500 | } |
|
- | 501 | } // EOF if(WPArrived) |
|
507 | GPS_pWaypoint = WPList_Next(); // goto to next waypoint, return NULL if end of list has been reached |
502 | else |
508 | WPArrived = FALSE; // which is not arrived |
503 | { |
Line 509... | Line 504... | ||
509 | } |
504 | WPTime = SetDelay(GPS_pWaypoint->HoldTime * 1000); // set hold time stamp |
510 | } // EOF if(WPArrived) |
505 | } |
511 | } |
506 | } |
512 | } // EOF waypoint trigger logic |
507 | } // EOF waypoint trigger logic |
513 | 508 | ||
- | 509 | if(GPS_pWaypoint != NULL) // Waypoint exist |
|
- | 510 | { |
|
514 | if(GPS_pWaypoint != NULL) // Waypoint exist |
511 | // update the hold position |
515 | { |
512 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
516 | // update the hold position |
513 | GPS_pTargetPosition = &(GPS_pWaypoint->Position); |
517 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
514 | GPS_TargetRadius = (u32)(GPS_pWaypoint->ToleranceRadius) * 100L; |
518 | GPS_pTargetPosition = &(GPS_pWaypoint->Position); |
515 | |
519 | } |
516 | } |
520 | else // no waypoint info available, i.e. the WPList is empty or the end of the list has been reached |
517 | else // no waypoint info available, i.e. the WPList is empty or the end of the list has been reached |
- | 518 | { |
|
521 | { |
519 | // fly back to home postion |
522 | // fly back to home postion |
520 | if(GPS_HomePosition.Status == INVALID) |
523 | if(GPS_HomePosition.Status == INVALID) |
521 | { |
524 | { |
522 | GPS_pTargetPosition = &GPS_HoldPosition; // fall back to hold mode if home position is not available |
525 | GPS_pTargetPosition = &GPS_HoldPosition; // fall back to hold mode if home position is not available |
523 | GPS_TargetRadius = 100; |
526 | BeepTime = 255; // beep to indicate missin home position |
524 | BeepTime = 255; // beep to indicate missin home position |
527 | } |
525 | } |
528 | else // the home position is valid |
526 | else // the home position is valid |
- | 527 | { |
|
529 | { |
528 | // update the hold position |
530 | // update the hold position |
529 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
531 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
530 | // set target to home position |
532 | // set target to home position |
531 | GPS_pTargetPosition = &GPS_HomePosition; |
Line 541... | Line 540... | ||
541 | GPS_Parameter.PID_Limit = 0; // disables PID output |
540 | GPS_Parameter.PID_Limit = 0; // disables PID output |
542 | // update hold position |
541 | // update hold position |
543 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
542 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
544 | // no target position |
543 | // no target position |
545 | GPS_pTargetPosition = NULL; |
544 | GPS_pTargetPosition = NULL; |
- | 545 | GPS_TargetRadius = 0; |
|
546 | break; |
546 | break; |
Line 547... | Line 547... | ||
547 | 547 | ||
Line 555... | Line 555... | ||
555 | else |
555 | else |
556 | { // if the target position has been changed or the value has been updated or the OperatingRadius has changed |
556 | { // if the target position has been changed or the value has been updated or the OperatingRadius has changed |
557 | if((GPS_pTargetPosition != pTargetPositionOld) || (GPS_pTargetPosition->Status == NEWDATA) || (GPS_Parameter.OperatingRadius != OperatingRadiusOld) ) |
557 | if((GPS_pTargetPosition != pTargetPositionOld) || (GPS_pTargetPosition->Status == NEWDATA) || (GPS_Parameter.OperatingRadius != OperatingRadiusOld) ) |
558 | { |
558 | { |
559 | BeepTime = 255; // beep to indicate setting of a new target position |
559 | BeepTime = 255; // beep to indicate setting of a new target position |
- | 560 | NCFlags &= ~NC_FLAG_TARGET_REACHED; // clear target reached flag |
|
560 | // calculate deviation of new target position from home position |
561 | // calculate deviation of new target position from home position |
561 | if(GPS_CalculateDeviation(GPS_pTargetPosition, &GPS_HomePosition, &TargetHomeDeviation)) |
562 | if(GPS_CalculateDeviation(GPS_pTargetPosition, &GPS_HomePosition, &TargetHomeDeviation)) |
562 | { |
563 | { |
563 | // check distance from home position |
564 | // check distance from home position |
564 | if(TargetHomeDeviation.Distance > GPS_Parameter.OperatingRadius) |
565 | if(TargetHomeDeviation.Distance > GPS_Parameter.OperatingRadius) |
565 | { |
566 | { |
566 | //calculate ranged target position to be within the operation radius area |
567 | //calculate ranged target position to be within the operation radius area |
567 | NaviData.NCFlags |= NC_FLAG_RANGE_LIMIT; |
568 | NCFlags |= NC_FLAG_RANGE_LIMIT; |
Line 568... | Line 569... | ||
568 | 569 | ||
569 | TargetHomeDeviation.North *= GPS_Parameter.OperatingRadius; |
570 | TargetHomeDeviation.North *= GPS_Parameter.OperatingRadius; |
570 | TargetHomeDeviation.North /= TargetHomeDeviation.Distance; |
571 | TargetHomeDeviation.North /= TargetHomeDeviation.Distance; |
571 | TargetHomeDeviation.East *= GPS_Parameter.OperatingRadius; |
572 | TargetHomeDeviation.East *= GPS_Parameter.OperatingRadius; |
Line 582... | Line 583... | ||
582 | } |
583 | } |
583 | else |
584 | else |
584 | { // the target is located within the operation radius area |
585 | { // the target is located within the operation radius area |
585 | // simple copy the loaction to the ranged target position |
586 | // simple copy the loaction to the ranged target position |
586 | GPS_CopyPosition(GPS_pTargetPosition, &RangedTargetPosition); |
587 | GPS_CopyPosition(GPS_pTargetPosition, &RangedTargetPosition); |
587 | NaviData.NCFlags &= ~NC_FLAG_RANGE_LIMIT; |
588 | NCFlags &= ~NC_FLAG_RANGE_LIMIT; |
588 | } |
589 | } |
589 | } |
590 | } |
590 | else |
591 | else |
591 | { // deviation could not be determined |
592 | { // deviation could not be determined |
592 | GPS_ClearPosition(&RangedTargetPosition); |
593 | GPS_ClearPosition(&RangedTargetPosition); |
Line 600... | Line 601... | ||
600 | 601 | ||
Line 601... | Line 602... | ||
601 | /* Calculate position deviation from ranged target */ |
602 | /* Calculate position deviation from ranged target */ |
602 | 603 | ||
- | 604 | // calculate deviation of current position to ranged target position in cm |
|
- | 605 | if(GPS_CalculateDeviation(&(GPSData.Position), &RangedTargetPosition, &CurrentTargetDeviation)) |
|
603 | // calculate deviation of current position to ranged target position in cm |
606 | { // set target reached flag of we once reached the target point |
- | 607 | if(!(NCFlags |= NC_FLAG_TARGET_REACHED) && (CurrentTargetDeviation.Distance < GPS_TargetRadius)) |
|
- | 608 | { |
|
604 | if(GPS_CalculateDeviation(&(GPSData.Position), &RangedTargetPosition, &CurrentTargetDeviation)) |
609 | NCFlags |= NC_FLAG_TARGET_REACHED; // set target reached flag |
605 | { |
610 | } |
606 | // implement your control code here based |
611 | // implement your control code here based |
607 | // in the info available in the CurrentTargetDeviation, GPSData and FromFlightCtrl.GyroHeading |
612 | // in the info available in the CurrentTargetDeviation, GPSData and FromFlightCtrl.GyroHeading |
608 | GPS_Stick.Nick = 0; |
613 | GPS_Stick.Nick = 0; |
Line 649... | Line 654... | ||
649 | NaviData.CompassHeading = (s16)FromFlightCtrl.GyroHeading/10; // in deg |
654 | NaviData.CompassHeading = (s16)FromFlightCtrl.GyroHeading/10; // in deg |
650 | NaviData.AngleNick = FromFlightCtrl.AngleNick / 10; // in deg |
655 | NaviData.AngleNick = FromFlightCtrl.AngleNick / 10; // in deg |
651 | NaviData.AngleRoll = FromFlightCtrl.AngleRoll / 10; // in deg |
656 | NaviData.AngleRoll = FromFlightCtrl.AngleRoll / 10; // in deg |
652 | NaviData.RC_Quality = (u8) FC.RC_Quality; |
657 | NaviData.RC_Quality = (u8)FC.RC_Quality; |
653 | NaviData.MKFlags = (u8)FC.MKFlags; |
658 | NaviData.MKFlags = (u8)FC.MKFlags; |
- | 659 | NaviData.NCFlags = NCFlags; |
|
654 | NaviData.OperatingRadius = Parameter.NaviOperatingRadius; |
660 | NaviData.OperatingRadius = Parameter.NaviOperatingRadius; |
655 | NaviData.TopSpeed = (s16)GPSData.Speed_Top; // in cm/s |
661 | NaviData.TopSpeed = (s16)GPSData.Speed_Top; // in cm/s |
656 | - | ||
- | 662 | NaviData.TargetHoldTime = (u16)GetDelay(WPTime); |
|
657 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
663 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
658 | return; |
664 | return; |
659 | } |
665 | } |