Smartcar Shield
Loading...
Searching...
No Matches
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
20namespace smartcarlib
21{
22namespace constants
23{
24namespace gy50
25{
26const uint8_t kDefaultSamplingInterval = 100;
27const int kError = -32767;
29} // namespace gy50
30} // namespace constants
31} // namespace smartcarlib
32
33class GY50 : public HeadingSensor
34{
35public:
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
75private:
76 const int kOffset;
77 const unsigned long kSamplingInterval;
78 Runtime& mRuntime;
79 unsigned long mPreviousSample{ 0 };
80 bool mAttached{ false };
81 float mAngularDisplacement{ 0 };
82
83 void attach();
84 int getAngularVelocity();
85 int readL3G4200DRegister(uint8_t registerAddress);
86 void writeL3G4200DRegister(uint8_t registerAddress, uint8_t value);
87};
88
The class representing a GY-50 gyroscope module based on the L3G4200D sensor.
Definition GY50.hpp:34
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:86
int getHeading() override
Returns the current heading of the vehicle.
Definition GY50.cpp:28
void update() override
Updates the sensor's readings.
Definition GY50.cpp:37
A heading sensor is an interface that can represent all sensors which can provide the vehicle's headi...
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
Definition Runtime.hpp:36
const uint8_t kDefaultSamplingInterval
Definition GY50.hpp:26
const int kDefaultCalibrationMeasurements
Definition GY50.hpp:28