paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [6196] srf08 telemeter, a good example for delay=""


From: Martin Mueller
Subject: [paparazzi-commits] [6196] srf08 telemeter, a good example for delay=""
Date: Thu, 21 Oct 2010 17:51:40 +0000

Revision: 6196
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=6196
Author:   mmm
Date:     2010-10-21 17:51:40 +0000 (Thu, 21 Oct 2010)
Log Message:
-----------
srf08 telemeter, a good example for delay=""

Modified Paths:
--------------
    paparazzi3/trunk/conf/airframes/mm/fixed-wing/funjetmm.xml
    paparazzi3/trunk/sw/airborne/main_ap.c

Added Paths:
-----------
    paparazzi3/trunk/conf/modules/alt_srf08.xml
    paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.c
    paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.h

Modified: paparazzi3/trunk/conf/airframes/mm/fixed-wing/funjetmm.xml
===================================================================
--- paparazzi3/trunk/conf/airframes/mm/fixed-wing/funjetmm.xml  2010-10-21 
16:03:23 UTC (rev 6195)
+++ paparazzi3/trunk/conf/airframes/mm/fixed-wing/funjetmm.xml  2010-10-21 
17:51:40 UTC (rev 6196)
@@ -24,6 +24,7 @@
       <define name="ALT_KALMAN"/>
       <define name="WIND_INFO"/>
       <define name="WIND_INFO_RET"/>
+      <define name="USE_I2C0"/>
     </target>
 
     <subsystem name="radio_control"    type="ppm"/>
@@ -41,7 +42,7 @@
       <param name="GPS_BAUD"           value="B38400"/>
     </subsystem>
     <subsystem name="navigation"/>
-    <subsystem name="spi"/>
+    <subsystem name="i2c"/>
   </firmware>
 
   <firmware name="setup">
@@ -54,8 +55,9 @@
 
   <!-- modules -->
   <modules>
-    <load name="baro_MS5534A.xml"/>
-    <!--load name="baro_bmp.xml"/>
+    <load name="alt_srf08.xml"/>
+    <!--load name="baro_MS5534A.xml"/>
+    <load name="baro_bmp.xml"/>
     <load name="baro_scp_i2c.xml"/>
     <load name="light_temt.xml"/>
     <load name="humid_hih.xml"/>

Added: paparazzi3/trunk/conf/modules/alt_srf08.xml
===================================================================
--- paparazzi3/trunk/conf/modules/alt_srf08.xml                         (rev 0)
+++ paparazzi3/trunk/conf/modules/alt_srf08.xml 2010-10-21 17:51:40 UTC (rev 
6196)
@@ -0,0 +1,17 @@
+<!DOCTYPE module SYSTEM "module.dtd">
+
+<module name="alt_srf08" dir="sensors">
+  <header>
+    <file name="alt_srf08.h"/>
+  </header>
+  <init fun="srf08_init()"/>
+  <periodic fun="srf08_initiate_ranging()" freq="1"/>
+  <!-- 65ms since initiate_ranging() (the spec ask for 65ms), 
+       delay="4", 60Hz, 4x 16.7ms = 66.7ms -->
+  <periodic fun="srf08_receive()" freq="1" delay="4"/>
+  <event fun="srf08_event"/>
+  <makefile>
+    <file name="alt_srf08.c"/>
+    <flag name="TELEMETER"/>
+  </makefile>
+</module>

Modified: paparazzi3/trunk/sw/airborne/main_ap.c
===================================================================
--- paparazzi3/trunk/sw/airborne/main_ap.c      2010-10-21 16:03:23 UTC (rev 
6195)
+++ paparazzi3/trunk/sw/airborne/main_ap.c      2010-10-21 17:51:40 UTC (rev 
6196)
@@ -75,10 +75,6 @@
 #include "airspeed.h"
 #endif
 
-#ifdef TELEMETER
-#include "srf08.h"
-#endif
-
 #if defined USE_I2C0 || USE_I2C1
 #include "i2c.h"
 #endif
@@ -87,10 +83,6 @@
 #include "spi.h"
 #endif
 
-#ifdef TELEMETER
-#include "srf08.h"
-#endif
-
 #ifdef TRAFFIC_INFO
 #include "traffic_info.h"
 #endif
@@ -446,15 +438,6 @@
     kill_throttle |= launch && (dist2_to_home > Square(KILL_MODE_DISTANCE));
   }
   switch (_1Hz) {
-#ifdef TELEMETER
-  case 1:
-    srf08_initiate_ranging();
-    break;
-  case 5:
-    /** 65ms since initiate_ranging() (the spec ask for 65ms) */
-    srf08_receive();
-    break;
-#endif
 
 #ifdef TCAS
   case 6:
@@ -612,9 +595,6 @@
 #ifdef GPS
   gps_init();
 #endif
-#ifdef TELEMETER
-  srf08_init();
-#endif
 #ifdef USE_UART0
   Uart0Init();
 #endif
@@ -809,19 +789,6 @@
   }
 #endif /** DATALINK */
 
-#ifdef TELEMETER
-  /** Handling of data sent by the device (initiated by srf08_receive() */
-  if (srf08_received) {
-    srf08_received = FALSE;
-    srf08_read();
-  }
-  if (srf08_got) {
-    srf08_got = FALSE;
-    srf08_copy();
-    DOWNLINK_SEND_RANGEFINDER(DefaultChannel, &srf08_range);
-  }
-#endif
-
 #ifdef MCU_SPI_LINK
   if (spi_message_received) {
     /* Got a message on SPI. */

Copied: paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.c (from rev 
3706, paparazzi3/trunk/sw/airborne/srf08.c)
===================================================================
--- paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.c                    
        (rev 0)
+++ paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.c    2010-10-21 
17:51:40 UTC (rev 6196)
@@ -0,0 +1,151 @@
+/*
+ * $Id$
+ *  
+ * Copyright (C) 2005  Pascal Brisset, Antoine Drouin
+ * Copyright (C) 2002  Chris efstathiou address@hidden
+ *
+ * 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. 
+ *
+ */
+/** \file srf08.c
+ *  \brief Basic library for SRF08 telemeter
+ *
+ */
+
+#include "i2c.h"
+#include "alt_srf08.h"
+#include "uart.h"
+#include "messages.h"
+#include "downlink.h"
+#include "led.h" 
+
+#ifndef SRF08_I2C_DEV
+#define SRF08_I2C_DEV i2c0
+#endif
+
+/* Global Variables */
+bool_t srf08_received, srf08_got;
+struct i2c_transaction srf_trans;
+uint16_t srf08_range;
+
+
+/*###########################################################################*/
+
+void srf08_init(void)
+{
+  srf08_received = FALSE;
+  srf08_got = FALSE;
+  
+  srf_trans.buf[0] = 0x00;
+  srf_trans.buf[1] = 0x51;
+  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2);
+
+  /** Setting the gain to the minimun value (to avoid echos ?) */
+  srf_trans.buf[0] = SRF08_SET_GAIN;
+  srf_trans.buf[1] = SRF08_MIN_GAIN;
+  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2);
+
+  return;
+}
+/*###########################################################################*/
+
+void srf08_initiate_ranging(void) {
+LED_ON(2);
+  srf_trans.buf[0] = SRF08_COMMAND;
+  srf_trans.buf[1] = SRF08_CENTIMETERS;
+  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2);
+}
+
+/** Ask the value to the device */
+void srf08_receive(void) {
+LED_OFF(2);
+  srf_trans.buf[0] = SRF08_ECHO_1;
+  srf08_received = TRUE;
+  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 1);
+}
+
+/** Read values on the bus */
+void srf08_read(void) {
+  srf08_got = TRUE;
+  I2CReceive(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2);
+}
+
+/** Copy the I2C buffer */
+void srf08_copy(void) {
+  srf08_range = srf_trans.buf[0] << 8 | srf_trans.buf[1];
+}
+
+void srf08_ping()
+{
+  srf08_initiate_ranging();
+  while (srf_trans.status != I2CTransSuccess);  /* blocking */
+
+  srf08_receive();
+}
+/*###########################################################################*/
+
+uint32_t srf08_read_register(uint8_t srf08_register)
+{
+  uint8_t cnt;
+
+  union i2c_union {
+    uint32_t  rx_word; 
+    uint8_t   rx_byte[2];
+  } i2c;
+
+
+  srf_trans.buf[0] = srf08_register;
+  
+  /* get high byte msb first */ 
+  if (srf08_register>=2)
+    cnt = 2;
+  else
+    cnt = 1;
+
+  I2CTransceive(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 1, cnt);
+       
+  /* get high byte msb first */ 
+  if(srf08_register>=2) {
+    i2c.rx_byte[1]=srf_trans.buf[1];
+  }                         
+       
+  /* get low byte msb first  */ 
+  i2c.rx_byte[0]=srf_trans.buf[0];
+
+  return(i2c.rx_word);
+}
+
+void srf08_event(void)
+{
+  float f=0;
+  uint8_t i=0;
+
+  /** Handling of data sent by the device (initiated by srf08_receive() */
+  if (srf_trans.status == I2CTransSuccess) {
+    if (srf08_received) {
+      srf08_received = FALSE;
+      srf08_read();
+    }
+    else if (srf08_got) {
+      srf08_got = FALSE;
+      srf08_copy();
+      DOWNLINK_SEND_RANGEFINDER(DefaultChannel, &srf08_range, &f, &f, &f, &f, 
&f, &i);
+    }
+  }
+}
+

Copied: paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.h (from rev 
3706, paparazzi3/trunk/sw/airborne/srf08.h)
===================================================================
--- paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.h                    
        (rev 0)
+++ paparazzi3/trunk/sw/airborne/modules/sensors/alt_srf08.h    2010-10-21 
17:51:40 UTC (rev 6196)
@@ -0,0 +1,119 @@
+/*
+ * $Id$
+ *  
+ * Copyright (C) 2005  Pascal Brisset, Antoine Drouin
+ * Copyright (C) 2002  Chris efstathiou address@hidden
+ *
+ * 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. 
+ *
+ */
+/** \file srf08.h
+ *  \brief Basic library for SRF08 telemeter
+ *
+ */
+
+
+#ifndef SRF08_H
+#define SRF08_H     1
+
+/*###########################################################################*/
+/*                      START OF CONFIGURATION BLOCK                         */
+/*###########################################################################*/
+/* Normally you shouldn't need to change anything */
+
+#define SRF08_UNIT_0   0xE0  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_1   0xE2  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_2   0xE4  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_3   0xE6  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_4   0xE8  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_5   0xEA  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_6   0xEC  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_7   0xEE  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_8   0xF0  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_9   0xF2  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_10  0xF4  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_11  0xF6  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_12  0xF8  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_13  0xFA  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_14  0xFC  /* the SRF08 MODULE I2C address */
+#define SRF08_UNIT_15  0xFE  /* the SRF08 MODULE I2C address */
+
+/*###########################################################################*/
+/*                    END OF CONFIGURATION BLOCK                             */
+/*###########################################################################*/
+
+#define SRF08_I2C_BROADCAST_ADDRESS   0X00
+
+#define SRF08_MIN_GAIN        0      /* sets gain to 94   */
+#define SRF08_MAX_GAIN        31     /* sets gain to 1025 */
+#define SRF08_MIN_RANGE       0      /* in millimeters    */
+#define SRF08_MAX_RANGE       11008  /* in millimeters    */
+
+#define SRF08_INCHES          0X50
+#define SRF08_CENTIMETERS     0X51
+#define SRF08_MICROSECONDS    0X52
+
+/* register positions */
+#define SRF08_COMMAND         0
+#define SRF08_SET_GAIN        1
+#define SRF08_LIGHT           1
+#define SRF08_ECHO_1          2
+#define SRF08_ECHO_2          4
+#define SRF08_ECHO_3          6
+#define SRF08_ECHO_4          8
+#define SRF08_ECHO_5          10
+#define SRF08_ECHO_6          12
+#define SRF08_ECHO_7          14
+#define SRF08_ECHO_8          16
+#define SRF08_ECHO_9          18
+#define SRF08_ECHO_10         20
+#define SRF08_ECHO_11         22
+#define SRF08_ECHO_12         24
+#define SRF08_ECHO_13         26
+#define SRF08_ECHO_14         28
+#define SRF08_ECHO_15         30
+#define SRF08_ECHO_16         32
+#define SRF08_ECHO_17         34
+
+/* Function Declaration */
+
+extern void srf08_select_unit(uint8_t srf08_address);
+extern void srf08_init(void);
+
+extern void srf08_set_gain(uint8_t gain);
+extern void srf08_set_range(uint32_t millimeters);
+
+extern void srf08_ping(void);
+extern uint32_t srf08_read_register(uint8_t srf08_register);
+
+extern void srf08_change_i2c_address(uint8_t new_i2c_address);
+
+extern void srf08_initiate_ranging(void);
+extern void srf08_receive(void);
+
+extern uint16_t srf08_range;
+extern bool_t srf08_received, srf08_got;
+/** Read values on the bus */
+extern void srf08_read(void);
+/** Copy the I2C buffer */
+extern void srf08_copy(void);
+
+extern void srf08_event(void);
+
+#endif  /* #ifndef SRF08_H */
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]