Skip to content
Snippets Groups Projects
Commit fb6b68af authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

Fixed thermocouples, added telecommands and solenoid control

parent d160e166
Branches
Tags
No related merge requests found
...@@ -112,6 +112,7 @@ ...@@ -112,6 +112,7 @@
"Alain", "Alain",
"ARPE", "ARPE",
"BDTR", "BDTR",
"Boardcore",
"Carlucci", "Carlucci",
"CCER", "CCER",
"CCMR", "CCMR",
...@@ -123,6 +124,7 @@ ...@@ -123,6 +124,7 @@
"fedetft's", "fedetft's",
"Gpio", "Gpio",
"GPIOB", "GPIOB",
"GPIOC",
"GPIOD", "GPIOD",
"GPIOG", "GPIOG",
"HSCMAND", "HSCMAND",
...@@ -132,6 +134,7 @@ ...@@ -132,6 +134,7 @@
"Matteo", "Matteo",
"miosix", "miosix",
"mosi", "mosi",
"Nidasio",
"nsamples", "nsamples",
"OSSI", "OSSI",
"OSSR", "OSSR",
...@@ -151,7 +154,8 @@ ...@@ -151,7 +154,8 @@
"USART", "USART",
"WWDG", "WWDG",
"WWDGEN", "WWDGEN",
"Xbee" "Xbee",
"Zangari"
], ],
"C_Cpp.errorSquiggles": "Disabled", "C_Cpp.errorSquiggles": "Disabled",
"cSpell.enabled": true "cSpell.enabled": true
......
Subproject commit e61a8fc6d279c0681434c3dca161215a3758916c Subproject commit 19f3ea9886246d9e9d8080d789e967b08330a25f
...@@ -43,6 +43,9 @@ void Actuators::init() ...@@ -43,6 +43,9 @@ void Actuators::init()
servo1.enable(); servo1.enable();
servo2.enable(); servo2.enable();
solenoid.mode(Mode::OUTPUT);
solenoid.low();
// Register the buttons callback // Register the buttons callback
ButtonHandler::getInstance().registerButtonCallback( ButtonHandler::getInstance().registerButtonCallback(
ui::button1::getPin(), std::bind(&Actuators::buttonCallback, this, _1)); ui::button1::getPin(), std::bind(&Actuators::buttonCallback, this, _1));
......
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
Boardcore::Servo servo1; Boardcore::Servo servo1;
Boardcore::Servo servo2; Boardcore::Servo servo2;
Boardcore::Buzzer buzzer; Boardcore::Buzzer buzzer;
miosix::GpioPin solenoid = miosix::GpioPin(GPIOC_BASE, 3);
void init(); void init();
......
...@@ -24,8 +24,10 @@ ...@@ -24,8 +24,10 @@
#include <board/Actuators/Actuators.h> #include <board/Actuators/Actuators.h>
#include <board/Configs.h> #include <board/Configs.h>
#include <board/Events.h>
#include <board/Sensors/Sensors.h> #include <board/Sensors/Sensors.h>
#include <drivers/timer/TimestampTimer.h> #include <drivers/timer/TimestampTimer.h>
#include <events/EventBroker.h>
#include <iostream> #include <iostream>
...@@ -78,13 +80,57 @@ void CLI::printStep() ...@@ -78,13 +80,57 @@ void CLI::printStep()
void CLI::run() void CLI::run()
{ {
int servoNum = 0;
float percentage = 0;
while (!shouldStop()) while (!shouldStop())
{ {
std::string line; std::string line;
std::getline(std::cin, line); std::getline(std::cin, line);
if (line.c_str()[0] == '?')
{
printf("Configured load cell: %d\n",
static_cast<uint16_t>(Sensors::getInstance().loadCellScale));
}
else if (line.c_str()[0] == 'L')
{
uint16_t loadCellScale = 0;
int result = sscanf(line.c_str(), "L%hu", &loadCellScale);
if (result == 1)
Sensors::getInstance().setLoadCellScale(
static_cast<LoadCell>(loadCellScale));
else
printf("Unrecognized command\n");
}
else if (line.compare("START_REC") == 0)
{
EventBroker::getInstance().post(Events::EV_BTN_SWITCH_ON,
Topics::TOPIC_BTN);
}
else if (line.compare("STOP_REC") == 0)
{
EventBroker::getInstance().post(Events::EV_BTN_SWITCH_OFF,
Topics::TOPIC_BTN);
}
else if (line.compare("SOL_ON") == 0)
{
Actuators::getInstance().solenoid.high();
printf("Solenoid turned on\n");
}
else if (line.compare("SOL_OFF") == 0)
{
Actuators::getInstance().solenoid.low();
printf("Solenoid turned off\n");
}
else if (line.compare("CALIBRATE") == 0)
{
EventBroker::getInstance().post(Events::EV_BTN_BUTTON_LONG_PRESS,
Topics::TOPIC_BTN);
}
else
{
int servoNum = 0;
float percentage = 0;
int result = sscanf(line.c_str(), "%d.%f", &servoNum, &percentage); int result = sscanf(line.c_str(), "%d.%f", &servoNum, &percentage);
// Move the servo if applicable // Move the servo if applicable
...@@ -102,5 +148,6 @@ void CLI::run() ...@@ -102,5 +148,6 @@ void CLI::run()
} }
} }
} }
}
} // namespace HRETestStand } // namespace HRETestStand
...@@ -54,15 +54,38 @@ bool Sensors::start() ...@@ -54,15 +54,38 @@ bool Sensors::start()
void Sensors::stop() { sensorManager->stop(); } void Sensors::stop() { sensorManager->stop(); }
void Sensors::setLoadCellScale(LoadCell loadCellScale)
{
switch (loadCellScale)
{
case LoadCell::KG_20:
loadCell->setScale(4.552863e-6);
break;
case LoadCell::KG_110:
loadCell->setScale(23.376577e-6);
break;
case LoadCell::KG_2000:
loadCell->setScale(453.914981e-6);
break;
default:
printf("Unrecognized load cell!\n");
return;
}
printf("Changed load cell scale to %dKg\n",
static_cast<uint16_t>(loadCellScale));
}
Sensors::Sensors() : averageLoad(100) {} Sensors::Sensors() : averageLoad(100) {}
void Sensors::loadCellInit() void Sensors::loadCellInit()
{ {
loadCell = loadCell =
new HX711(Buses::getInstance().spi4, sensors::hx711::sck::getPin()); new HX711(Buses::getInstance().spi4, sensors::hx711::sck::getPin());
loadCell->setOffset(-53873); loadCell->setOffset(-53873);
// loadCell->setScale(4.552863e-6); // 20Kg load cell setLoadCellScale(loadCellScale);
loadCell->setScale(23.376577e-6); // 100Kg load cell
SensorInfo infoLoadCell(LOAD_CELL_NAME, LOAD_CELL_SAMPLE_PERIOD, SensorInfo infoLoadCell(LOAD_CELL_NAME, LOAD_CELL_SAMPLE_PERIOD,
std::bind(&Sensors::loadCellCallback, this)); std::bind(&Sensors::loadCellCallback, this));
...@@ -110,12 +133,12 @@ void Sensors::thermocouplesInit() ...@@ -110,12 +133,12 @@ void Sensors::thermocouplesInit()
{ {
Buses& buses = Buses::getInstance(); Buses& buses = Buses::getInstance();
thermocouple1 = new MAX6675(buses.spi5, sensors::max31855::cs1::getPin()); thermocouple1 = new MAX31855(buses.spi5, sensors::max31855::cs1::getPin());
thermocouple2 = new MAX6675(buses.spi5, sensors::max31855::cs2::getPin()); thermocouple2 = new MAX31855(buses.spi5, sensors::max31855::cs2::getPin());
thermocouple3 = new MAX6675(buses.spi5, sensors::max31855::cs3::getPin()); thermocouple3 = new MAX31855(buses.spi5, sensors::max31855::cs3::getPin());
thermocouple4 = new MAX6675(buses.spi5, sensors::max31855::cs4::getPin()); thermocouple4 = new MAX31855(buses.spi5, sensors::max31855::cs4::getPin());
thermocouple5 = new MAX6675(buses.spi5, sensors::max31855::cs5::getPin()); thermocouple5 = new MAX31855(buses.spi5, sensors::max31855::cs5::getPin());
thermocouple6 = new MAX6675(buses.spi5, sensors::max31855::cs6::getPin()); thermocouple6 = new MAX31855(buses.spi5, sensors::max31855::cs6::getPin());
SensorInfo info1(THERMOCOUPLE_1_NAME, THERMOCOUPLE_SAMPLE_PERIOD, SensorInfo info1(THERMOCOUPLE_1_NAME, THERMOCOUPLE_SAMPLE_PERIOD,
std::bind(&Sensors::thermocouple1Callback, this)); std::bind(&Sensors::thermocouple1Callback, this));
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <miosix.h> #include <miosix.h>
#include <sensors/ADS131M04/ADS131M04.h> #include <sensors/ADS131M04/ADS131M04.h>
#include <sensors/HX711/HX711.h> #include <sensors/HX711/HX711.h>
#include <sensors/MAX6675/MAX6675.h> #include <sensors/MAX31855/MAX31855.h>
#include <sensors/SensorManager.h> #include <sensors/SensorManager.h>
#include <sensors/analog/AnalogLoadCell.h> #include <sensors/analog/AnalogLoadCell.h>
#include <sensors/analog/pressure/AnalogPressureSensor.h> #include <sensors/analog/pressure/AnalogPressureSensor.h>
...@@ -40,6 +40,13 @@ ...@@ -40,6 +40,13 @@
namespace HRETestStand namespace HRETestStand
{ {
enum class LoadCell : uint16_t
{
KG_20 = 20,
KG_110 = 110,
KG_2000 = 2000,
};
struct Sensors : Boardcore::Singleton<Sensors> struct Sensors : Boardcore::Singleton<Sensors>
{ {
friend class Boardcore::Singleton<Sensors>; friend class Boardcore::Singleton<Sensors>;
...@@ -48,12 +55,12 @@ struct Sensors : Boardcore::Singleton<Sensors> ...@@ -48,12 +55,12 @@ struct Sensors : Boardcore::Singleton<Sensors>
Boardcore::ADS131M04* adcPressureSensors = nullptr; Boardcore::ADS131M04* adcPressureSensors = nullptr;
PressureSensors* pressureSensors = nullptr; PressureSensors* pressureSensors = nullptr;
Boardcore::MAX6675* thermocouple1 = nullptr; Boardcore::MAX31855* thermocouple1 = nullptr;
Boardcore::MAX6675* thermocouple2 = nullptr; Boardcore::MAX31855* thermocouple2 = nullptr;
Boardcore::MAX6675* thermocouple3 = nullptr; Boardcore::MAX31855* thermocouple3 = nullptr;
Boardcore::MAX6675* thermocouple4 = nullptr; Boardcore::MAX31855* thermocouple4 = nullptr;
Boardcore::MAX6675* thermocouple5 = nullptr; Boardcore::MAX31855* thermocouple5 = nullptr;
Boardcore::MAX6675* thermocouple6 = nullptr; Boardcore::MAX31855* thermocouple6 = nullptr;
ThermocouplesData thermocouplesData; ThermocouplesData thermocouplesData;
Boardcore::SensorManager* sensorManager = nullptr; Boardcore::SensorManager* sensorManager = nullptr;
...@@ -64,12 +71,16 @@ struct Sensors : Boardcore::Singleton<Sensors> ...@@ -64,12 +71,16 @@ struct Sensors : Boardcore::Singleton<Sensors>
Boardcore::MovingAverage<float> averagePressure3; Boardcore::MovingAverage<float> averagePressure3;
Boardcore::MovingAverage<float> averagePressure4; Boardcore::MovingAverage<float> averagePressure4;
LoadCell loadCellScale = LoadCell::KG_2000;
void init(); void init();
bool start(); bool start();
void stop(); void stop();
void setLoadCellScale(LoadCell loadCellScale);
private: private:
/** /**
* @brief Initializes all the board sensors. * @brief Initializes all the board sensors.
......
/* Copyright (c) 2021 Skyward Experimental Rocketry /* Copyright (c) 2021 Skyward Experimental Rocketry
* Author: Matteo Pignataro * Author: Alberto Nidasio
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment