A
download anemotaxis.c
Language: C
LOC: 76
Project Info
paparazzi
Server: Savannah NonGNU
Type: cvs
...zzi\paparazzi3\sw\airborne\
   3dmg.c
   3dmg.h
   actuators.c
   actuators.h
   adc.h
   adc_generic.c
   adc_generic.h
   ahrs.c
   ahrs.h
   ahrs_new.c
   ahrs_new.h
   anemotaxis.c
   anemotaxis.h
   ap_downlink.h
   autopilot.h
   bomb.c
   bomb.h
   cam.c
   cam.h
   cam_roll.c
   cam_roll.h
   chemo_detect.c
   chemo_detect.h
   chemotaxis.c
   chemotaxis.h
   commands.c
   commands.h
   control_grz.c
   control_grz.h
   datalink.c
   datalink.h
   dc.c
   dc.h
   discsurvey.c
   discsurvey.h
   downlink.c
   downlink.h
   dpicco.c
   dpicco.h
   enose.c
   enose.h
   estimator.c
   estimator.h
   fbw_downlink.h
   frames.h
   fw_h_ctl.c
   fw_h_ctl.h
   fw_v_ctl.c
   fw_v_ctl.h
   gps.c
   gps.h
   gps_ubx.c
   gps_ubx.h
   gyro.c
   gyro.h
   i2c.c
   i2c.h
   imu.c
   imu.h
   imu_v3.c
   imu_v3.h
   infrared.c
   infrared.h
   inter_mcu.c
   inter_mcu.h
   latlong.c
   latlong.h
   led.h
   link_imu.c
   link_imu.h
   link_mcu.c
   link_mcu.h
   main.c
   main_antenna.c
   main_ap.c
   main_ap.h
   main_demo1.c
   main_demo2.c
   main_demo3.c
   main_demo4.c
   main_demo5.c
   main_demo6.c
   main_fbw.c
   main_fbw.h
   main_grz.c
   main_imu.c
   main_motor_bench.c
   modem.h
   nav.c
   nav.h
   nav_line.c
   nav_line.h
   nav_survey_rectangle.c
   nav_survey_rectangle.h
   paparazzi.h
   point.c
   point.h
   ppm.h
   pprz_transport.c
   pprz_transport.h
   print.h
   radio_control.c
   radio_control.h
   rc_settings.c
   rc_settings.h
   setup_actuators.c
   spi.c
   spi.h
   srf08.c
   srf08.h
   sys_time.c
   sys_time.h
   test_adcs.c
   traffic_info.c
   traffic_info.h
   uart.h
   usb_serial.h
   wavecard.c
   wavecard.h
   xbee.c
   xbee.h

#include "anemotaxis.h"
#include "airframe.h"
#include "estimator.h"
#include "std.h"
#include "nav.h"
#include "flight_plan.h"
#include "ap_downlink.h"
#include "chemo_detect.h"

enum status { UTURN, CROSSWIND };
static enum status status;
static int8_t sign;
static struct point last_plume;

static void last_plume_was_here( void ) {
  last_plume.x = estimator_x;
  last_plume.y = estimator_y;
}

bool_t nav_anemotaxis_downwind( uint8_t c, float radius ) {
  float wind_dir = atan2(wind_north, wind_east);
  waypoints[c].x = waypoints[WP_HOME].x + radius*cos(wind_dir);
  waypoints[c].y = waypoints[WP_HOME].y + radius*sin(wind_dir);
  return FALSE;
}

bool_t nav_anemotaxis_init( uint8_t c ) {
  status = UTURN;
  sign = 1;
  float wind_dir = atan2(wind_north, wind_east);
  waypoints[c].x = estimator_x + DEFAULT_CIRCLE_RADIUS*cos(wind_dir+M_PI);
  waypoints[c].y = estimator_y + DEFAULT_CIRCLE_RADIUS*sin(wind_dir+M_PI);
  last_plume_was_here();
  return FALSE;
}

bool_t nav_anemotaxis( uint8_t c, uint8_t c1, uint8_t c2, uint8_t plume ) {
  if (chemo_sensor) {
    last_plume_was_here();
    waypoints[plume].x = estimator_x;
    waypoints[plume].y = estimator_y;
    //    DownlinkSendWp(plume);
  }

  float wind_dir = atan2(wind_north, wind_east) + M_PI;

  /** Not null even if wind_east=wind_north=0 */
  float upwind_x = cos(wind_dir);
  float upwind_y = sin(wind_dir);

  switch (status) {
  case UTURN:
    NavCircleWaypoint(c, DEFAULT_CIRCLE_RADIUS*sign);
    if (NavQdrCloseTo(DegOfRad(M_PI_2-wind_dir))) {
      float crosswind_x = - upwind_y;
      float crosswind_y = upwind_x;
      waypoints[c1].x = waypoints[c].x + DEFAULT_CIRCLE_RADIUS*upwind_x;
      waypoints[c1].y = waypoints[c].y + DEFAULT_CIRCLE_RADIUS*upwind_y;

      float width = Max(2*ScalarProduct(upwind_x, upwind_y, estimator_x-last_plume.x, estimator_y-last_plume.y), DEFAULT_CIRCLE_RADIUS);

      waypoints[c2].x = waypoints[c1].x - width*crosswind_x*sign;
      waypoints[c2].y = waypoints[c1].y - width*crosswind_y*sign;

      //      DownlinkSendWp(c1);
      //      DownlinkSendWp(c2);

      status = CROSSWIND;
      nav_init_stage();
    }
    break;

  case CROSSWIND:
    NavSegment(c1, c2);
    if (NavApproaching(c2, CARROT)) {
      waypoints[c].x = waypoints[c2].x + DEFAULT_CIRCLE_RADIUS*upwind_x;
      waypoints[c].y = waypoints[c2].y + DEFAULT_CIRCLE_RADIUS*upwind_y;

      // DownlinkSendWp(c);
     
      sign = -sign;
      status = UTURN;
      nav_init_stage();
    }

    if (chemo_sensor) {
      waypoints[c].x = estimator_x + DEFAULT_CIRCLE_RADIUS*upwind_x;
      waypoints[c].y = estimator_y + DEFAULT_CIRCLE_RADIUS*upwind_y;

      // DownlinkSendWp(c);
     
      sign = -sign;
      status = UTURN;
      nav_init_stage();
    }
    break;
  }
  chemo_sensor = 0;
  return TRUE;
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us