Smartcar Shield
GY50.hpp
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <stdint.h> // NOLINT(modernize-deprecated-headers)
16 
17 #include "../../../runtime/Runtime.hpp"
18 #include "../HeadingSensor.hpp"
19 
20 namespace smartcarlib
21 {
22 namespace constants
23 {
24 namespace gy50
25 {
26 const uint8_t kDefaultSamplingInterval = 100;
27 const int kError = -32767;
29 } // namespace gy50
30 } // namespace constants
31 } // namespace smartcarlib
32 
33 class GY50 : public HeadingSensor
34 {
35 public:
50  GY50(Runtime& runtime,
51  int offset,
52  unsigned long samplingInterval = smartcarlib::constants::gy50::kDefaultSamplingInterval);
53 
54  /* Check `HeadingSensor` interface for documentation */
55  int getHeading() override;
56 
57  /* Check `HeadingSensor` interface for documentation */
58  void update() override;
59 
74 
75 private:
76  const int kOffset;
77  const unsigned long kSamplingInterval;
78  Runtime& mRuntime;
79  unsigned long mPreviousSample;
80  bool mAttached;
81  float mAngularDisplacement;
82 
83  void attach();
84  int getAngularVelocity();
85  int readL3G4200DRegister(uint8_t registerAddress);
86  void writeL3G4200DRegister(uint8_t registerAddress, uint8_t value);
87 };
88 
smartcarlib::constants::gy50::kDefaultCalibrationMeasurements
const int kDefaultCalibrationMeasurements
Definition: GY50.hpp:28
smartcarlib
Definition: DistanceCar.hpp:11
GY50
Definition: GY50.hpp:33
GY50::GY50
GY50(Runtime &runtime, int offset, unsigned long samplingInterval=smartcarlib::constants::gy50::kDefaultSamplingInterval)
Constructs a GY50 gyroscope.
Definition: GY50.cpp:21
Runtime
Definition: Runtime.hpp:35
smartcarlib::constants::gy50::kDefaultSamplingInterval
const uint8_t kDefaultSamplingInterval
Definition: GY50.hpp:26
HeadingSensor
Definition: HeadingSensor.hpp:8
smartcarlib::constants::gy50::kError
const int kError
Definition: GY50.hpp:27
GY50::getOffset
int getOffset(int measurements=smartcarlib::constants::gy50::kDefaultCalibrationMeasurements)
Get the sensor's offset which is the value the sensor returns when still.
Definition: GY50.cpp:89
GY50::getHeading
int getHeading() override
Returns the current heading of the vehicle.
Definition: GY50.cpp:31
GY50::update
void update() override
Updates the sensor's readings.
Definition: GY50.cpp:40