David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.
Dependencies: PololuEncoder Pacer mbed GeneralDebouncer
turn_sensor.h
00001 #pragma once 00002 00003 #include <mbed.h> 00004 00005 class TurnSensor 00006 { 00007 // TODO: for production code, you would want a way to set the gyro offset 00008 00009 public: 00010 00011 void reset(); 00012 void start(); 00013 void update(); 00014 00015 int32_t getAngle() 00016 { 00017 return (int32_t)angleUnsigned; 00018 } 00019 00020 uint32_t getAngleUnsigned() 00021 { 00022 return angleUnsigned; 00023 } 00024 00025 int16_t getAngleDegrees() 00026 { 00027 return (((int32_t)angleUnsigned >> 16) * 360) >> 16; 00028 } 00029 00030 int32_t getAngleMillidegrees() 00031 { 00032 return ((int64_t)(int32_t)angleUnsigned * 360000) >> 32; 00033 } 00034 00035 int16_t getRate() 00036 { 00037 return rate; 00038 } 00039 00040 private: 00041 00042 Timer timer; 00043 uint32_t angleUnsigned; 00044 int16_t rate; 00045 uint16_t gyroLastUpdate; 00046 }; 00047 00048 00049 // This constant represents a turn of 45 degrees. 00050 const int32_t turnAngle45 = 0x20000000; 00051 00052 // This constant represents a turn of 90 degrees. 00053 const int32_t turnAngle90 = turnAngle45 * 2; 00054 00055 // This constant represents a turn of approximately 1 degree. 00056 const int32_t turnAngle1 = (turnAngle45 + 22) / 45;
Generated on Sun Jul 17 2022 15:45:15 by 1.7.2