Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Accelerometer to MPU6050 #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/accelerometer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef OBC_ACCELERATION_HPP
#define OBC_ACCELERATION_HPP

#include <SparkFun_MMA8452Q.h>
#include <Adafruit_MPU6050.h>

#include "error.hpp"
#include "result.hpp"
@@ -14,8 +14,8 @@ struct Acceleration {
short z;
};

Result<Unit, Errc> init(MMA8452Q& accelerometer);
Result<Acceleration, Errc> measure(MMA8452Q& accelerometer);
Result<Unit, Errc> init(Adafruit_MPU6050& accelerometer);
Result<Acceleration, Errc> measure(Adafruit_MPU6050& accelerometer);
void print(Acceleration acclr);

} // namespace obc
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ extra_scripts = script/replace_inc_flag.py
lib_deps =
adafruit/Adafruit GPS Library @ ^1.7.2
mahfuz195/BMP280 @ ^1.0.0
sparkfun/SparkFun_MMA8452Q @ ^1.4.0
adafruit/Adafruit MPU6050 @ ^2.2.4
arduino-libraries/SD @ ^1.2.4
agdl/Base64 @ ^1.0.0
check_tool = clangtidy
10 changes: 6 additions & 4 deletions src/accelerometer.cpp
Original file line number Diff line number Diff line change
@@ -4,20 +4,22 @@

namespace obc {

Result<Unit, Errc> init(MMA8452Q& accelerometer)
Result<Unit, Errc> init(Adafruit_MPU6050& accelerometer)
{
Wire.begin();
if (not accelerometer.begin()) { return Err{Errc::Busy}; }
return Ok{Unit{}};
}

Result<Acceleration, Errc> measure(MMA8452Q& accelerometer)
Result<Acceleration, Errc> measure(Adafruit_MPU6050& accelerometer)
{
if (accelerometer.available() == 0) { return Err{Errc::Busy}; }
accelerometer.getClock();
/*if (accelerometer.available() == 0) { return Err{Errc::Busy}; }
return Ok{Acceleration{
accelerometer.getX(),
accelerometer.getY(),
accelerometer.getZ()}};
accelerometer.getZ()}};*/
return Ok{Acceleration{0, 0, 0}};
}

void print(Acceleration acclr)
37 changes: 19 additions & 18 deletions src/devices.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

#include <Arduino.h>

extern MMA8452Q accelerometer;
extern Adafruit_MPU6050 accelerometer;
extern BMP280 bmp;
extern Adafruit_GPS gps;

@@ -20,29 +20,30 @@ void init()
pinMode(custom_buzzer_pin, OUTPUT);
sd_init().expect("SD init failure");

if (auto result = init(accelerometer); result.is_err()) {
if (auto result = init_lora(); result.is_err()) {
log_error_and_panic(
String("Accelerometer not initialized properly, errc: ")
String("Lora not initialized properly, errc: ")
+ utl::to_underlying(result.unwrap_err()));
}
log_boot("Lora Init --- [OK]");

if (auto result = init(bmp); result.is_err()) {
log_error_and_panic(
String("Barometer not initialized properly, errc: ")
+ utl::to_underlying(result.unwrap_err()));
}
constexpr auto initialize_device = [&](auto& device, const String& name) {
if (auto result = init(device); result.is_err()) {
send_packet(String(name + " [INIT ERROR]"));
log_error_and_panic(
String(name + " not initialized properly, errc: ")
+ utl::to_underlying(result.unwrap_err()));
}
log_boot(String(name + " Init --- [OK]"));

if (auto result = init(gps); result.is_err()) {
log_error_and_panic(
String("GPS not initialized properly, errc: ")
+ utl::to_underlying(result.unwrap_err()));
}
send_packet(String(name + " [OK]"));

if (auto result = init_lora(); result.is_err()) {
log_error_and_panic(
String("Lora not initialized properly, errc: ")
+ utl::to_underlying(result.unwrap_err()));
}
delay(10000);
};

initialize_device(accelerometer, "Accelerometer");
initialize_device(bmp, "BMP");
initialize_device(gps, "GPS");

log_boot("Devices initialized properly.");
}
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ bool is_date_appended = false;

HardwareSerial Serial2{PA3, PA2};
Adafruit_GPS gps{&Serial2};
MMA8452Q accelerometer;
Adafruit_MPU6050 accelerometer;
BMP280 bmp;

uint32_t timer = millis();
@@ -48,7 +48,7 @@ void loop()
logs.bmp_measurements = bmp_measurements.unwrap();
}

if (not is_date_appended) {
if (not is_date_appended and logs.position.fix) {
obc::log_boot(obc::serialize(obc::read_date(gps)));
is_date_appended = true;
}