77 #include "autopilot.h"
78 #include "generated/flight_plan.h"
91 float fx1;
float fx2;
float fx3;
92 float fy1;
float fy2;
float fy3;
93 float fz1;
float fz2;
float fz3;
100 #if defined(SHOW_CAM_COORDINATES)
103 uint16_t cam_point_distance_from_home;
104 float cam_point_lon, cam_point_lat;
105 float distance_correction = 1;
118 svA->
fx = svB.
fx - svC.
fx;
119 svA->
fy = svB.
fy - svC.
fy;
120 svA->
fz = svB.
fz - svC.
fz;
164 void vPoint(
float fPlaneEast,
float fPlaneNorth,
float fPlaneAltitude,
165 float fRollAngle,
float fPitchAngle,
float fYawAngle,
166 float fObjectEast,
float fObjectNorth,
float fAltitude,
167 float *fPan,
float *fTilt)
169 static VECTOR svPlanePosition,
171 svObjectPositionForPlane,
172 svObjectPositionForPlane2;
174 static VECTOR sv_cam_projection,
175 sv_cam_projection_buf;
191 #ifdef CAM_TILT_NEUTRAL
193 #if defined(RADIO_TILT)
194 if ((*fbw_state).channels[RADIO_TILT] >= 0) {
195 cam_theta = (float)RadOfDeg(CAM_TILT_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_TILT] / (
float)
MAX_PPRZ) *
199 cam_theta = (float)RadOfDeg(CAM_TILT_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_TILT] / (
float)
MIN_PPRZ) *
202 #elif defined(RADIO_PITCH)
212 #error RADIO_TILT or RADIO_PITCH not defined.
215 #else //#ifdef CAM_TILT_NEUTRAL
217 #if defined(RADIO_TILT)
220 #elif defined(RADIO_PITCH)
224 #error RADIO_TILT or RADIO_PITCH not defined.
227 #endif //#ifdef CAM_TILT_NEUTRAL
231 #ifdef CAM_PAN_NEUTRAL
233 #if defined(RADIO_PAN)
234 if ((*fbw_state).channels[RADIO_PAN] >= 0) {
235 cam_phi = RadOfDeg(CAM_PAN_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_PAN] / (
float)
MAX_PPRZ) *
239 cam_phi = RadOfDeg(CAM_PAN_NEUTRAL) + (((float)(*fbw_state).channels[RADIO_PAN] / (
float)
MIN_PPRZ) *
242 #elif defined(RADIO_ROLL)
252 #error RADIO_PAN or RADIO_ROLL not defined.
255 #else //#ifdef CAM_PAN_NEUTRAL
257 #if defined(RADIO_PAN)
260 #elif defined(RADIO_ROLL)
264 #error RADIO_PAN or RADIO_ROLL not defined.
267 #endif //#ifdef CAM_PAN_NEUTRAL
283 svPlanePosition.
fx = fPlaneEast;
284 svPlanePosition.
fy = fPlaneNorth;
285 svPlanePosition.
fz = fPlaneAltitude;
294 #ifdef SHOW_CAM_COORDINATES
295 cam_point_distance_from_home = 0;
303 sv_cam_projection_buf.
fy = svPlanePosition.
fy;
306 #if defined(WP_CAM_POINT)
313 vSubtractVectors(&sv_cam_projection, sv_cam_projection_buf, svPlanePosition);
315 float heading_radians = RadOfDeg(90) - fYawAngle;
316 if (heading_radians > RadOfDeg(180)) { heading_radians -= RadOfDeg(360); }
317 if (heading_radians < RadOfDeg(-180)) { heading_radians += RadOfDeg(360); }
324 smRotation.
fy1 = -smRotation.
fx2;
325 smRotation.
fy2 = smRotation.
fx1;
334 smRotation.
fx1 = (float)(cos(heading_radians));
335 smRotation.
fx2 = -(float)(sin(heading_radians));
337 smRotation.
fy1 = -smRotation.
fx2;
338 smRotation.
fy2 = smRotation.
fx1;
346 #if defined(RADIO_CAM_LOCK)
347 float radio_cam_lock = imcu_get_radio(RADIO_CAM_LOCK);
353 fObjectEast = (fPlaneEast + sv_cam_projection.
fx) ;
354 fObjectNorth = (fPlaneNorth + sv_cam_projection.
fy) ;
359 #if defined(WP_CAM_POINT)
364 #if defined(SHOW_CAM_COORDINATES)
365 cam_point_x = fObjectEast;
366 cam_point_y = fObjectNorth;
368 cam_point_distance_from_home = distance_correction * (
uint16_t)(sqrt((cam_point_x * cam_point_x) +
369 (cam_point_y * cam_point_y)));
372 utm.
east += sv_cam_projection.
fx;
373 utm.
north += sv_cam_projection.
fy;
376 cam_point_lon = lla.
lon * (180 / M_PI);
377 cam_point_lat = lla.
lat * (180 / M_PI);
384 #if defined(WP_CAM_POINT)
397 #if defined(WP_CAM_POINT)
407 #ifdef SHOW_CAM_COORDINATES
408 cam_point_distance_from_home = distance_correction * (
uint16_t) fabs(((
uint16_t)(sqrt((fObjectNorth * fObjectNorth) +
409 (fObjectEast * fObjectEast)))) -
410 ((
uint16_t)(sqrt((fPlaneNorth * fPlaneNorth) + (fPlaneEast * fPlaneEast)))));
418 cam_point_lon = lla.
lon * (180 / M_PI);
419 cam_point_lat = lla.
lat * (180 / M_PI);
423 #if defined(WP_CAM_POINT)
447 svPlanePosition.
fx = fPlaneNorth;
448 svPlanePosition.
fy = fPlaneEast;
449 svPlanePosition.
fz = fPlaneAltitude;
451 svObjectPosition.
fx = fObjectNorth;
452 svObjectPosition.
fy = fObjectEast;
453 svObjectPosition.
fz = fAltitude;
456 vSubtractVectors(&svObjectPositionForPlane, svObjectPosition, svPlanePosition);
459 smRotation.
fx1 = (float)(cos(fYawAngle));
460 smRotation.
fx2 = (float)(sin(fYawAngle));
462 smRotation.
fy1 = -smRotation.
fx2;
463 smRotation.
fy2 = smRotation.
fx1;
472 smRotation.
fx1 = (float)(cos(fPitchAngle));
474 smRotation.
fx3 = (float)(sin(fPitchAngle));
478 smRotation.
fz1 = -smRotation.
fx3;
480 smRotation.
fz3 = smRotation.
fx1;
489 smRotation.
fy2 = (float)(cos(fRollAngle));
490 smRotation.
fy3 = (float)(-sin(fRollAngle));
492 smRotation.
fz2 = -smRotation.
fy3;
493 smRotation.
fz3 = smRotation.
fy2;
497 #ifdef POINT_CAM_PITCH
522 #if 0 //we roll away anyways
523 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fx,
524 sqrt(svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy
525 + svObjectPositionForPlane2.
fz * svObjectPositionForPlane2.
fz)
528 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fx, -svObjectPositionForPlane2.
fz));
535 #ifdef POINT_CAM_ROLL
553 #if 1 // have to check if it helps
554 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fy,
555 sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
556 + svObjectPositionForPlane2.
fz * svObjectPositionForPlane2.
fz)
559 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fy, -svObjectPositionForPlane2.
fz));
566 #ifdef POINT_CAM_YAW_PITCH_NOSE
586 #if defined(CAM_PAN_MODE) && CAM_PAN_MODE == 360
588 *fPan = (float)(atan2(svObjectPositionForPlane2.
fy, (svObjectPositionForPlane2.
fx)));
590 *fTilt = (float)(atan2(sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
591 + svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy),
592 -svObjectPositionForPlane2.
fz
609 *fPan = (float)(atan2(svObjectPositionForPlane2.
fy, fabs(svObjectPositionForPlane2.
fx)));
611 *fTilt = (float)(atan2(sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
612 + svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy),
613 -svObjectPositionForPlane2.
fz
616 if (svObjectPositionForPlane2.
fx < 0) {
637 #ifdef POINT_CAM_YAW_PITCH
686 *fPan = (float)(atan2(svObjectPositionForPlane2.
fx,
687 fabs(svObjectPositionForPlane2.
fy)));
697 *fTilt = (float)(atan2(sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
698 + svObjectPositionForPlane2.
fy * svObjectPositionForPlane2.
fy),
699 -svObjectPositionForPlane2.
fz
701 if (svObjectPositionForPlane2.
fy < 0) {
707 #ifdef POINT_CAM_PITCH_ROLL
732 *fTilt = (float)(atan2(svObjectPositionForPlane2.
fx, -svObjectPositionForPlane2.
fz));
734 *fPan = (float)(atan2(-svObjectPositionForPlane2.
fy,
735 sqrt(svObjectPositionForPlane2.
fx * svObjectPositionForPlane2.
fx
736 + svObjectPositionForPlane2.
fz * svObjectPositionForPlane2.
fz)
740 #error at least one POINT_CAM_* camera mount has to be defined!
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
#define CAM_MODE_STABILIZED
#define PPRZ_MUTEX_LOCK(_mtx)
#define CAM_MODE_XY_TARGET
void vSubtractVectors(VECTOR *svA, VECTOR svB, VECTOR svC)
position in UTM coordinates Units: meters
struct fbw_state * fbw_state
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)
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
API to get/set the generic vehicle states.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
#define CAM_MODE_WP_TARGET
#define PPRZ_MUTEX_UNLOCK(_mtx)