Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.

Dependencies:   mbed Watchdog SDFileSystem DigoleSerialDisp

Committer:
shimniok
Date:
Fri Nov 30 16:11:53 2018 +0000
Revision:
25:bb5356402687
Parent:
0:a6a169de725f
Initial publish of revised version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:a6a169de725f 1 /* Copyright (c) 2011 Pololu Corporation. For more information, see
shimniok 0:a6a169de725f 2 *
shimniok 0:a6a169de725f 3 * http://www.pololu.com/
shimniok 0:a6a169de725f 4 * http://forum.pololu.com/
shimniok 0:a6a169de725f 5 *
shimniok 0:a6a169de725f 6 * Permission is hereby granted, free of charge, to any person
shimniok 0:a6a169de725f 7 * obtaining a copy of this software and associated documentation
shimniok 0:a6a169de725f 8 * files (the "Software"), to deal in the Software without
shimniok 0:a6a169de725f 9 * restriction, including without limitation the rights to use,
shimniok 0:a6a169de725f 10 * copy, modify, merge, publish, distribute, sublicense, and/or sell
shimniok 0:a6a169de725f 11 * copies of the Software, and to permit persons to whom the
shimniok 0:a6a169de725f 12 * Software is furnished to do so, subject to the following
shimniok 0:a6a169de725f 13 * conditions:
shimniok 0:a6a169de725f 14 *
shimniok 0:a6a169de725f 15 * The above copyright notice and this permission notice shall be
shimniok 0:a6a169de725f 16 * included in all copies or substantial portions of the Software.
shimniok 0:a6a169de725f 17 *
shimniok 0:a6a169de725f 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
shimniok 0:a6a169de725f 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
shimniok 0:a6a169de725f 20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
shimniok 0:a6a169de725f 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
shimniok 0:a6a169de725f 22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
shimniok 0:a6a169de725f 23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
shimniok 0:a6a169de725f 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
shimniok 0:a6a169de725f 25 * OTHER DEALINGS IN THE SOFTWARE.
shimniok 0:a6a169de725f 26 */
shimniok 0:a6a169de725f 27
shimniok 0:a6a169de725f 28 #ifndef __L3G4200D_H
shimniok 0:a6a169de725f 29 #define __L3G4200D_H
shimniok 0:a6a169de725f 30
shimniok 0:a6a169de725f 31 #include "mbed.h"
shimniok 0:a6a169de725f 32
shimniok 0:a6a169de725f 33 // register addresses
shimniok 0:a6a169de725f 34
shimniok 0:a6a169de725f 35 #define L3G4200D_WHO_AM_I 0x0F
shimniok 0:a6a169de725f 36
shimniok 0:a6a169de725f 37 #define L3G4200D_CTRL_REG1 0x20
shimniok 0:a6a169de725f 38 #define L3G4200D_CTRL_REG2 0x21
shimniok 0:a6a169de725f 39 #define L3G4200D_CTRL_REG3 0x22
shimniok 0:a6a169de725f 40 #define L3G4200D_CTRL_REG4 0x23
shimniok 0:a6a169de725f 41 #define L3G4200D_CTRL_REG5 0x24
shimniok 0:a6a169de725f 42 #define L3G4200D_REFERENCE 0x25
shimniok 0:a6a169de725f 43 #define L3G4200D_OUT_TEMP 0x26
shimniok 0:a6a169de725f 44 #define L3G4200D_STATUS_REG 0x27
shimniok 0:a6a169de725f 45
shimniok 0:a6a169de725f 46 #define L3G4200D_OUT_X_L 0x28
shimniok 0:a6a169de725f 47 #define L3G4200D_OUT_X_H 0x29
shimniok 0:a6a169de725f 48 #define L3G4200D_OUT_Y_L 0x2A
shimniok 0:a6a169de725f 49 #define L3G4200D_OUT_Y_H 0x2B
shimniok 0:a6a169de725f 50 #define L3G4200D_OUT_Z_L 0x2C
shimniok 0:a6a169de725f 51 #define L3G4200D_OUT_Z_H 0x2D
shimniok 0:a6a169de725f 52
shimniok 0:a6a169de725f 53 #define L3G4200D_FIFO_CTRL_REG 0x2E
shimniok 0:a6a169de725f 54 #define L3G4200D_FIFO_SRC_REG 0x2F
shimniok 0:a6a169de725f 55
shimniok 0:a6a169de725f 56 #define L3G4200D_INT1_CFG 0x30
shimniok 0:a6a169de725f 57 #define L3G4200D_INT1_SRC 0x31
shimniok 0:a6a169de725f 58 #define L3G4200D_INT1_THS_XH 0x32
shimniok 0:a6a169de725f 59 #define L3G4200D_INT1_THS_XL 0x33
shimniok 0:a6a169de725f 60 #define L3G4200D_INT1_THS_YH 0x34
shimniok 0:a6a169de725f 61 #define L3G4200D_INT1_THS_YL 0x35
shimniok 0:a6a169de725f 62 #define L3G4200D_INT1_THS_ZH 0x36
shimniok 0:a6a169de725f 63 #define L3G4200D_INT1_THS_ZL 0x37
shimniok 0:a6a169de725f 64 #define L3G4200D_INT1_DURATION 0x38
shimniok 0:a6a169de725f 65
shimniok 0:a6a169de725f 66 typedef char byte;
shimniok 0:a6a169de725f 67
shimniok 0:a6a169de725f 68 /** Interface library for the ST L3G4200D 3-axis gyro
shimniok 0:a6a169de725f 69 *
shimniok 0:a6a169de725f 70 * Ported from Pololu L3G4200D library for Arduino by
shimniok 0:a6a169de725f 71 * Michael Shimniok http://bot-thoughts.com
shimniok 0:a6a169de725f 72 *
shimniok 0:a6a169de725f 73 * @code
shimniok 0:a6a169de725f 74 * #include "mbed.h"
shimniok 0:a6a169de725f 75 * #include "L3G4200D.h"
shimniok 0:a6a169de725f 76 * L3G4200D gyro(p28, p27);
shimniok 0:a6a169de725f 77 * ...
shimniok 0:a6a169de725f 78 * int g[3];
shimniok 0:a6a169de725f 79 * gyro.read(g);
shimniok 0:a6a169de725f 80 * @endcode
shimniok 0:a6a169de725f 81 */
shimniok 0:a6a169de725f 82 class L3G4200D
shimniok 0:a6a169de725f 83 {
shimniok 0:a6a169de725f 84 public:
shimniok 0:a6a169de725f 85 /** Create a new L3G4200D I2C interface
shimniok 0:a6a169de725f 86 * @param sda is the pin for the I2C SDA line
shimniok 0:a6a169de725f 87 * @param scl is the pin for the I2C SCL line
shimniok 0:a6a169de725f 88 */
shimniok 0:a6a169de725f 89 L3G4200D(PinName sda, PinName scl);
shimniok 0:a6a169de725f 90
shimniok 0:a6a169de725f 91 /** Read gyro values
shimniok 0:a6a169de725f 92 * @param g Array containing x, y, and z gyro values
shimniok 0:a6a169de725f 93 * @return g Array containing x, y, and z gyro values
shimniok 0:a6a169de725f 94 */
shimniok 0:a6a169de725f 95 void read(int g[3]);
shimniok 0:a6a169de725f 96
shimniok 0:a6a169de725f 97 /** Read raw temperature value
shimniok 0:a6a169de725f 98 * @return temperature value in raw byte form
shimniok 0:a6a169de725f 99 */
shimniok 0:a6a169de725f 100 byte readTemp(void);
shimniok 0:a6a169de725f 101
shimniok 0:a6a169de725f 102 private:
shimniok 0:a6a169de725f 103 byte data[6];
shimniok 0:a6a169de725f 104 int _rates[3];
shimniok 0:a6a169de725f 105 I2C _device;
shimniok 0:a6a169de725f 106 void writeReg(byte reg, byte value);
shimniok 0:a6a169de725f 107 byte readReg(byte reg);
shimniok 0:a6a169de725f 108 void enableDefault(void);
shimniok 0:a6a169de725f 109 };
shimniok 0:a6a169de725f 110
shimniok 0:a6a169de725f 111 #endif