download 3dmg.c
Language: C
License: GPL
Copyright: (C) 2005 Pascal Brisset, Antoine Drouin
LOC: 122
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

/*
 * Paparazzi $Id: 3dmg.c,v 1.4 2006/04/13 16:02:54 hecto Exp $
 *  
 * Copyright (C) 2005 Pascal Brisset, Antoine Drouin
 *
 * This file is part of paparazzi.
 *
 * paparazzi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * paparazzi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with paparazzi; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA. 
 *
 */

#include "airframe.h"

#include "std.h"
#include "3dmg.h"
#include "uart.h"

volatile bool_t _3dmg_data_ready;
int16_t   _3dmg_roll, _3dmg_pitch, _3dmg_yaw;
int16_t   _3dmg_roll_dot, _3dmg_pitch_dot, _3dmg_yaw_dot;
uint16_t  _3dmg_timer_tick;
uint8_t   type, state;
uint16_t  checksum_read, checksum_comp;

void _3dmg_set_continuous_mode ( void ) {
#define REQ_CONT_LEN 5
  uint8_t msg[REQ_CONT_LEN] = { 0x10, 0x00, 0x31, 0x00, 0x41};
  uint8_t i;
  for (i=0; i<REQ_CONT_LEN; i++)
    uart0_transmit(msg[i]);
}

void _3dmg_capture_neutral ( void ) {
#define CAP_GYR_LEN 3
  uint8_t msg[REQ_CONT_LEN] = { 0x06, 0x00, 0x06};
  uint8_t i;
  for (i=0; i<CAP_GYR_LEN; i++)
    uart0_transmit(msg[i]);
}


#define READ_MSB(my_short, my_char) {		 \
    {						 \
     my_short = (((int16_t)my_char)<<8)&0xFF00;  \
     state++;					 \
    }						 \
  }
  
#define READ_LSB(my_short, my_char) {		\
    {						\
    my_short += (((int16_t)my_char)&0x00FF);	\
    checksum_comp += (uint16_t)my_short;	\
    state++;					\
    }						\
  }

static inline void on_3dmg_receive(uint8_t c) {
  int16_t foo = 0;
  switch(state) {
  case 0:
    _3dmg_data_ready = FALSE ;
    if(c==0x31) {
      type = c;
      checksum_comp = (int16_t)type;
      state++ ;
    }
    break;
  case 1:
    READ_MSB(_3dmg_roll, c);
    break ;
  case 2:
    READ_LSB(_3dmg_roll, c);
    break ;
  case 3:
    READ_MSB(_3dmg_pitch, c);
    break ;
  case 4:
    READ_LSB(_3dmg_pitch, c);
    break ;
  case 5:
    READ_MSB(_3dmg_yaw, c);
    break ;
  case 6:
    READ_LSB(_3dmg_yaw, c);
    break ;
  case 7:
    READ_MSB(foo, c);
     /* accel_x_msb */
    break ;
  case 8:
    READ_LSB(foo, c);
    /* accel_x_lsb */
    break ;
  case 9:
    READ_MSB(foo, c);
    /* accel_y_msb */
    break ;
  case 10:
    READ_LSB(foo, c);
    /* accel_y_lsb */
    break ;
  case 11:
    READ_MSB(foo, c);
    /* accel_z_msb */
    break ;
  case 12:
    READ_LSB(foo, c);
    /* accel_z_lsb */
    break ;  
  case 13:
    READ_MSB(_3dmg_roll_dot, c);
    break ;
  case 14:
    READ_LSB(_3dmg_roll_dot, c);
    break ;
  case 15:
    READ_MSB(_3dmg_pitch_dot, c);
    break ;
  case 16:
    READ_LSB(_3dmg_pitch_dot, c);
    break ;
  case 17:
    READ_MSB(_3dmg_yaw_dot, c);
    break ;
  case 18:
    READ_LSB(_3dmg_yaw_dot, c);
    break ;  
  case 19:
    READ_MSB(_3dmg_timer_tick, c);
    break ;
  case 20:
    READ_LSB(_3dmg_timer_tick, c);
    break ;
  case 21:
    checksum_read = (((uint16_t)c)&0x00FF)<<8; 
    state++;
    break ;
  case 22:
    checksum_read += ((uint16_t)c)&0x00FF;
    state = 0 ;
    //   if (checksum_read == checksum_comp)
      _3dmg_data_ready = TRUE ;
    break ;
  }
}


#ifdef AVR_ARCH

ReceiveUart(on_3dmg_receive);

#endif /* AVR_ARCH */

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