77 #include "autopilot.h"
78 #include "generated/flight_plan.h"
90 float fx1;
float fx2;
float fx3;
91 float fy1;
float fy2;
float fy3;
92 float fz1;
float fz2;
float fz3;
99 #if defined(SHOW_CAM_COORDINATES)
102 uint16_t cam_point_distance_from_home;
103 float cam_point_lon, cam_point_lat;
104 float distance_correction = 1;
117 svA->
fx = svB.
fx - svC.
fx;
118 svA->
fy = svB.
fy - svC.
fy;
119 svA->
fz = svB.
fz - svC.
fz;
163 void vPoint(
float fPlaneEast,
float fPlaneNorth,
float fPlaneAltitude,
164 float fRollAngle,
float fPitchAngle,
float fYawAngle,
165 float fObjectEast,
float fObjectNorth,
float fAltitude,
166 float *fPan,
float *fTilt)
168 static VECTOR svPlanePosition,
170 svObjectPositionForPlane,
171 svObjectPositionForPlane2;
173 static VECTOR sv_cam_projection,
174 sv_cam_projection_buf;
188 #ifdef CAM_TILT_NEUTRAL
190 #if defined(RADIO_TILT)
191 if ((*fbw_state).channels[RADIO_TILT] >= 0) {
192 cam_theta = (float)RadOfDeg(CAM_TILT_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_TILT] / (
float)
MAX_PPRZ) *
196 cam_theta = (float)RadOfDeg(CAM_TILT_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_TILT] / (
float)
MIN_PPRZ) *
199 #elif defined(RADIO_PITCH)
209 #error RADIO_TILT or RADIO_PITCH not defined.
212 #else //#ifdef CAM_TILT_NEUTRAL
214 #if defined(RADIO_TILT)
217 #elif defined(RADIO_PITCH)
221 #error RADIO_TILT or RADIO_PITCH not defined.
224 #endif //#ifdef CAM_TILT_NEUTRAL
228 #ifdef CAM_PAN_NEUTRAL
230 #if defined(RADIO_PAN)
231 if ((*fbw_state).channels[RADIO_PAN] >= 0) {
232 cam_phi = RadOfDeg(CAM_PAN_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_PAN] / (
float)
MAX_PPRZ) *
236 cam_phi = RadOfDeg(CAM_PAN_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_PAN] / (
float)
MIN_PPRZ) *
239 #elif defined(RADIO_ROLL)
249 #error RADIO_PAN or RADIO_ROLL not defined.
252 #else //#ifdef CAM_PAN_NEUTRAL
254 #if defined(RADIO_PAN)
257 #elif defined(RADIO_ROLL)
261 #error RADIO_PAN or RADIO_ROLL not defined.
264 #endif //#ifdef CAM_PAN_NEUTRAL
279 svPlanePosition.
fx = fPlaneEast;
280 svPlanePosition.
fy = fPlaneNorth;
281 svPlanePosition.
fz = fPlaneAltitude;
290 #ifdef SHOW_CAM_COORDINATES
291 cam_point_distance_from_home = 0;
299 sv_cam_projection_buf.
fy = svPlanePosition.
fy;
302 #if defined(WP_CAM_POINT)
309 vSubtractVectors(&sv_cam_projection, sv_cam_projection_buf, svPlanePosition);
311 float heading_radians = RadOfDeg(90) - fYawAngle;
312 if (heading_radians > RadOfDeg(180)) { heading_radians -= RadOfDeg(360); }
313 if (heading_radians < RadOfDeg(-180)) { heading_radians += RadOfDeg(360); }
320 smRotation.
fy1 = -smRotation.
fx2;
321 smRotation.
fy2 = smRotation.
fx1;
330 smRotation.
fx1 = (float)(cos(heading_radians));
331 smRotation.
fx2 = -(float)(sin(heading_radians));
333 smRotation.
fy1 = -smRotation.
fx2;
334 smRotation.
fy2 = smRotation.
fx1;
342 #if defined(RADIO_CAM_LOCK)
348 fObjectEast = (fPlaneEast + sv_cam_projection.
fx) ;
349 fObjectNorth = (fPlaneNorth + sv_cam_projection.
fy) ;
354 #if defined(WP_CAM_POINT)
359 #if defined(SHOW_CAM_COORDINATES)
360 cam_point_x = fObjectEast;
361 cam_point_y = fObjectNorth;
363 cam_point_distance_from_home = distance_correction * (
uint16_t)(sqrt((cam_point_x * cam_point_x) +
364 (cam_point_y * cam_point_y)));
372 cam_point_lon = lla.
lon * (180 / M_PI);
373 cam_point_lat = lla.
lat * (180 / M_PI);
380 #if defined(WP_CAM_POINT)
393 #if defined(WP_CAM_POINT)
403 #ifdef SHOW_CAM_COORDINATES
404 cam_point_distance_from_home = distance_correction * (
uint16_t) fabs(((
uint16_t)(sqrt((fObjectNorth * fObjectNorth) +
405 (fObjectEast * fObjectEast)))) -
406 ((
uint16_t)(sqrt((fPlaneNorth * fPlaneNorth) + (fPlaneEast * fPlaneEast)))));
414 cam_point_lon = lla.
lon * (180 / M_PI);
415 cam_point_lat = lla.
lat * (180 / M_PI);
419 #if defined(WP_CAM_POINT)
443 svPlanePosition.
fx = fPlaneNorth;
444 svPlanePosition.
fy = fPlaneEast;
445 svPlanePosition.
fz = fPlaneAltitude;
447 svObjectPosition.
fx = fObjectNorth;
448 svObjectPosition.
fy = fObjectEast;
449 svObjectPosition.
fz = fAltitude;
452 vSubtractVectors(&svObjectPositionForPlane, svObjectPosition, svPlanePosition);
455 smRotation.
fx1 = (float)(cos(fYawAngle));
456 smRotation.
fx2 = (float)(sin(fYawAngle));
458 smRotation.
fy1 = -smRotation.
fx2;
459 smRotation.
fy2 = smRotation.
fx1;
468 smRotation.
fx1 = (float)(cos(fPitchAngle));
470 smRotation.
fx3 = (float)(sin(fPitchAngle));
474 smRotation.
fz1 = -smRotation.
fx3;
476 smRotation.
fz3 = smRotation.
fx1;
485 smRotation.
fy2 = (float)(cos(fRollAngle));
486 smRotation.
fy3 = (float)(-sin(fRollAngle));
488 smRotation.
fz2 = -smRotation.
fy3;
489 smRotation.
fz3 = smRotation.
fy2;
493 #ifdef POINT_CAM_PITCH
518 #if 0 //we roll away anyways
519 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fx,
520 sqrt(svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy
521 + svObjectPositionForPlane2.
fz * svObjectPositionForPlane2.
fz)
524 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fx, -svObjectPositionForPlane2.
fz));
531 #ifdef POINT_CAM_ROLL
549 #if 1 // have to check if it helps
550 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fy,
551 sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
552 + svObjectPositionForPlane2.
fz * svObjectPositionForPlane2.
fz)
555 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fy, -svObjectPositionForPlane2.
fz));
562 #ifdef POINT_CAM_YAW_PITCH_NOSE
582 #if defined(CAM_PAN_MODE) && CAM_PAN_MODE == 360
584 *fPan = (float)(atan2(svObjectPositionForPlane2.
fy, (svObjectPositionForPlane2.
fx)));
586 *fTilt = (float)(atan2(sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
587 + svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy),
588 -svObjectPositionForPlane2.
fz
605 *fPan = (float)(atan2(svObjectPositionForPlane2.
fy, fabs(svObjectPositionForPlane2.
fx)));
607 *fTilt = (float)(atan2(sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
608 + svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy),
609 -svObjectPositionForPlane2.
fz
612 if (svObjectPositionForPlane2.
fx < 0) {
633 #ifdef POINT_CAM_YAW_PITCH
682 *fPan = (float)(atan2(svObjectPositionForPlane2.
fx,
683 fabs(svObjectPositionForPlane2.
fy)));
693 *fTilt = (float)(atan2(sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
694 + svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy),
695 -svObjectPositionForPlane2.
fz
697 if (svObjectPositionForPlane2.
fy < 0) {
703 #ifdef POINT_CAM_PITCH_ROLL
728 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fx, -svObjectPositionForPlane2.
fz));
730 *fPan = (float)(atan2(-svObjectPositionForPlane2.
fy,
731 sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
732 + svObjectPositionForPlane2.
fz * svObjectPositionForPlane2.
fz)
736 #error at least one POINT_CAM_* camera mount has to be defined!
int32_t north
in centimeters
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
#define CAM_MODE_STABILIZED
#define CAM_MODE_XY_TARGET
void vSubtractVectors(VECTOR *svA, VECTOR svB, VECTOR svC)
position in UTM coordinates Units: meters
int32_t east
in centimeters
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over ellipsoid)
struct fbw_state * fbw_state
uint8_t zone
UTM zone number.
Paparazzi floating point math for geodetic calculations.
vector in Latitude, Longitude and Altitude
Device independent GPS code (interface)
void lla_of_utm_f(struct LlaCoor_f *lla, struct UtmCoor_f *utm)
void vMultiplyMatrixByVector(VECTOR *svA, MATRIX smB, VECTOR svC)
uint8_t zone
UTM zone number.
void vPoint(float fPlaneEast, float fPlaneNorth, float fPlaneAltitude, float fRollAngle, float fPitchAngle, float fYawAngle, float fObjectEast, float fObjectNorth, float fAltitude, float *fPan, float *fTilt)
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
#define CAM_MODE_WP_TARGET
struct GpsState gps
global GPS state