mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/cmake-demo.git
synced 2025-09-28 23:57:33 +00:00
Initial Commit
This commit is contained in:
65
App/Src/tasks/arming.cpp
Normal file
65
App/Src/tasks/arming.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* arming.cpp
|
||||
*
|
||||
* Created on: Jun 17, 2024
|
||||
* Author: carlos
|
||||
*/
|
||||
|
||||
#include <tasks/arming.hpp>
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include "can.h"
|
||||
#include <sta/tacos.hpp>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
namespace tasks
|
||||
{
|
||||
ArmingTask::ArmingTask() : TacosThread("ARMING", osPriorityHigh)
|
||||
{
|
||||
}
|
||||
|
||||
void ArmingTask::init()
|
||||
{
|
||||
// Stop shorting the igniters (NC so they are always shorted until high signal is sent)
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPA, SHORTING_PIN_A, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPB, SHORTING_PIN_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPC, SHORTING_PIN_C, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPD, SHORTING_PIN_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPE, SHORTING_PIN_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPF, SHORTING_PIN_F, GPIO_PIN_SET);
|
||||
|
||||
this->sleep(500); // 500ms delay
|
||||
|
||||
// Arming the igniters
|
||||
HAL_GPIO_WritePin(ARMING_GROUPA, ARMING_PIN_A, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPB, ARMING_PIN_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPC, ARMING_PIN_C, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPD, ARMING_PIN_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPE, ARMING_PIN_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPF, ARMING_PIN_F, GPIO_PIN_SET);
|
||||
|
||||
#ifdef STA_TACOS_CAN_BUS_ENABLED
|
||||
CanSysMsg msg;
|
||||
|
||||
msg.payload[0] = 1; // Send 1 to indicate that the igniters are armed
|
||||
|
||||
msg.header.payloadLength = 1;
|
||||
msg.header.sid = ARMING_CAN_ID;
|
||||
msg.header.eid = 0;
|
||||
msg.header.format = 0;
|
||||
|
||||
sta::tacos::queueCanBusMsg(msg, 0);
|
||||
#endif // STA_TACOS_CAN_BUS_ENABLED
|
||||
|
||||
// Terminate the thread until next state
|
||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||
this->watchdogIgnore();
|
||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||
}
|
||||
|
||||
void ArmingTask::func()
|
||||
{
|
||||
sleep(osWaitForever);
|
||||
}
|
||||
|
||||
} // namespace tasks
|
131
App/Src/tasks/fire.cpp
Normal file
131
App/Src/tasks/fire.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* fire.cpp
|
||||
*
|
||||
* Created on: Jun 17, 2024
|
||||
* Author: carlos
|
||||
*/
|
||||
|
||||
#include <tasks/fire.hpp>
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include "can.h"
|
||||
#include <sta/tacos.hpp>
|
||||
#include <sta/config.hpp>
|
||||
#include <shared.hpp>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
namespace tasks
|
||||
{
|
||||
FireTask::FireTask() : TacosThread("IGNITOR_FIRE", osPriorityHigh)
|
||||
{
|
||||
}
|
||||
|
||||
void FireTask::init()
|
||||
{
|
||||
rres::setFired(0);
|
||||
}
|
||||
|
||||
void FireTask::func()
|
||||
{
|
||||
|
||||
// Firing the igniters
|
||||
|
||||
CanSysMsg msg;
|
||||
|
||||
msg.header.sid = FIRE_CAN_ID;
|
||||
msg.header.eid = 0;
|
||||
msg.header.format = 0;
|
||||
msg.header.payloadLength = 1;
|
||||
|
||||
if (sta::tacos::getState() == stahr::DROGUE)
|
||||
{
|
||||
// Fire
|
||||
HAL_GPIO_WritePin(FIRE_HATCH_GROUP1, FIRE_HATCH_PIN_1, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(FIRE_HATCH_GROUP2, FIRE_HATCH_PIN_2, GPIO_PIN_SET);
|
||||
|
||||
// Send out fire information
|
||||
msg.payload[0] = 1; // Event 1 = HATCH fired / drogue deployed
|
||||
sta::tacos::queueCanBusMsg(msg, 0);
|
||||
|
||||
rres::setFired(1);
|
||||
|
||||
// Only leave on for a second to avoid shorting via the igniter
|
||||
this->sleep(1000); // 1 second
|
||||
|
||||
HAL_GPIO_WritePin(FIRE_HATCH_GROUP1, FIRE_HATCH_PIN_1, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(FIRE_HATCH_GROUP2, FIRE_HATCH_PIN_2, GPIO_PIN_RESET);
|
||||
|
||||
this->sleep(50); // Delay before disarming igniters
|
||||
|
||||
// Disarm the igniters
|
||||
HAL_GPIO_WritePin(ARMING_GROUPE, ARMING_PIN_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPF, ARMING_PIN_F , GPIO_PIN_RESET);
|
||||
|
||||
// Short ignitors
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPE, SHORTING_PIN_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPF, SHORTING_PIN_F, GPIO_PIN_RESET);
|
||||
}
|
||||
else if (sta::tacos::getState() == stahr::MAIN)
|
||||
{
|
||||
HAL_GPIO_WritePin(FIRE_MAIN_GROUP1, FIRE_MAIN_PIN_1, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(FIRE_MAIN_GROUP2, FIRE_MAIN_PIN_2, GPIO_PIN_SET);
|
||||
|
||||
// Send out fire information
|
||||
msg.payload[0] = 2; // Event 2 = MAIN Parachute
|
||||
sta::tacos::queueCanBusMsg(msg, 0);
|
||||
|
||||
rres::setFired(2);
|
||||
|
||||
// Only leave on for a second to avoid shorting via the igniter
|
||||
this->sleep(1000); // 1 second
|
||||
|
||||
HAL_GPIO_WritePin(FIRE_MAIN_GROUP1, FIRE_MAIN_PIN_1, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(FIRE_MAIN_GROUP2, FIRE_MAIN_PIN_2, GPIO_PIN_RESET);
|
||||
|
||||
this->sleep(50); // Delay before disarming igniters
|
||||
|
||||
// Disarm the igniters
|
||||
HAL_GPIO_WritePin(ARMING_GROUPC, ARMING_PIN_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPD, ARMING_PIN_D, GPIO_PIN_RESET);
|
||||
|
||||
// Short ignitors
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPC, SHORTING_PIN_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPD, SHORTING_PIN_D, GPIO_PIN_RESET);
|
||||
}
|
||||
else if (sta::tacos::getState() == stahr::DISREEFING)
|
||||
{
|
||||
HAL_GPIO_WritePin(FIRE_DEREEFING_GROUP1, FIRE_DEREEFING_PIN_1, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(FIRE_DEREEFING_GROUP2, FIRE_DEREEFING_PIN_2, GPIO_PIN_SET);
|
||||
|
||||
// Send out fire information
|
||||
msg.payload[0] = 3; // Event 3 = Drogue Parachute
|
||||
sta::tacos::queueCanBusMsg(msg, 0);
|
||||
|
||||
rres::setFired(3);
|
||||
|
||||
// Only leave on for a second to avoid shorting via the igniter
|
||||
this->sleep(1000); // 1 second
|
||||
|
||||
HAL_GPIO_WritePin(FIRE_DEREEFING_GROUP1, FIRE_DEREEFING_PIN_1, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(FIRE_DEREEFING_GROUP2, FIRE_DEREEFING_PIN_2, GPIO_PIN_RESET);
|
||||
|
||||
this->sleep(50); // Delay before disarming igniters
|
||||
|
||||
// Disarm the igniters
|
||||
HAL_GPIO_WritePin(ARMING_GROUPA, ARMING_PIN_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(ARMING_GROUPB, ARMING_PIN_B, GPIO_PIN_RESET);
|
||||
|
||||
// Short ignitors
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPA, SHORTING_PIN_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(SHORTING_GROUPB, SHORTING_PIN_B, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
// Terminate the thread until next state
|
||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||
this->watchdogIgnore();
|
||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||
|
||||
this->requestTermination();
|
||||
}
|
||||
|
||||
} // namespace tasks
|
153
App/Src/tasks/sense.cpp
Normal file
153
App/Src/tasks/sense.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* sense.cpp
|
||||
*
|
||||
* Created on: Jun 17, 2024
|
||||
* Author: carlos
|
||||
*/
|
||||
|
||||
#include <tasks/sense.hpp>
|
||||
|
||||
#include <sta/tacos.hpp>
|
||||
#include <sta/rtos/signal.hpp>
|
||||
#include <sta/devices/stm32/delay.hpp>
|
||||
#include <shared.hpp>
|
||||
|
||||
#include <tim.h>
|
||||
#include <adc.h>
|
||||
|
||||
namespace tasks
|
||||
{
|
||||
/**
|
||||
* @brief Signal for the ADC conversion complete interrupt to communicate with the ADCTask.
|
||||
*/
|
||||
sta::RtosSignal *adcCompleteSignal = nullptr;
|
||||
|
||||
SenseTask::SenseTask(ADC_HandleTypeDef *handle)
|
||||
: sta::tacos::TacosThread{"Sense", osPriorityNormal},
|
||||
adc_{handle}, result_counter_{0}
|
||||
{
|
||||
}
|
||||
|
||||
void SenseTask::init()
|
||||
{
|
||||
adcCompleteSignal = new sta::RtosSignal(1);
|
||||
|
||||
// Init msg_
|
||||
msg_.header.payloadLength = 8;
|
||||
|
||||
msg_.header.eid = 0;
|
||||
msg_.header.format = 0;
|
||||
|
||||
// Start ADC timer
|
||||
HAL_TIM_Base_Start(&htim3);
|
||||
|
||||
adc_.startDMA((uint32_t *)dmaBuffer_, bufferSize_);
|
||||
}
|
||||
|
||||
void SenseTask::func()
|
||||
{
|
||||
STA_ASSERT(adcCompleteSignal != nullptr);
|
||||
|
||||
// Wait for the conversion to be completed.
|
||||
adcCompleteSignal->wait();
|
||||
|
||||
// Determine wether to send the data or not
|
||||
uint16_t state = sta::tacos::getState();
|
||||
bool logging = !(state == stahr::CALIBRATING || state == stahr::READY_ON_PAD);
|
||||
bool send = result_counter_++ % 4 == 0;
|
||||
|
||||
// Sending the first 4 ADC values (limited by the CAN message size of 8 bytes)
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
{
|
||||
// Send the MSB first.
|
||||
msg_.payload[2 * i] = (uint8_t)(dmaBuffer_[i] >> 8);
|
||||
|
||||
// ... LSB second
|
||||
msg_.payload[2 * i + 1] = (uint8_t)dmaBuffer_[i];
|
||||
}
|
||||
|
||||
// Save the first 4 ADC values for logging
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
result_[i] = msg_.payload[2 * i] << 8 | msg_.payload[2 * i + 1];
|
||||
STA_DEBUG_PRINTF("> ADC[%d]: %d", i, result_[i]);
|
||||
}
|
||||
|
||||
if (send)
|
||||
{
|
||||
// Send it out while on the pad. Otherwise we only log the data.
|
||||
msg_.header.payloadLength = 8;
|
||||
msg_.header.sid = SENSE_CAN_ID;
|
||||
sta::tacos::queueCanBusMsg(msg_, 0);
|
||||
}
|
||||
|
||||
// Send the last 2 ADC values (limited by the CAN message size of 8 bytes)
|
||||
for (size_t i = 4; i < bufferSize_; ++i)
|
||||
{
|
||||
// Send the MSB first.
|
||||
msg_.payload[2 * (i - 4)] = (uint8_t)(dmaBuffer_[i] >> 8);
|
||||
|
||||
// ... LSB second
|
||||
msg_.payload[2 * (i - 4) + 1] = (uint8_t)dmaBuffer_[i];
|
||||
}
|
||||
|
||||
// Save the last 2 ADC values for logging
|
||||
for (size_t i = 4; i < 6; i++)
|
||||
{
|
||||
result_[i] = msg_.payload[2 * (i - 4)] << 8 | msg_.payload[2 * (i - 4) + 1];
|
||||
STA_DEBUG_PRINTF("> ADC[%d]: %d", i, result_[i]);
|
||||
}
|
||||
|
||||
// Get the sense pins on the fire output
|
||||
uint8_t sense_fire = 0;
|
||||
|
||||
uint8_t sense_fire_1 = HAL_GPIO_ReadPin(SENSE_FIRE_GROUP1, SENSE_FIRE_PIN_1);
|
||||
uint8_t sense_fire_2 = HAL_GPIO_ReadPin(SENSE_FIRE_GROUP2, SENSE_FIRE_PIN_2);
|
||||
uint8_t sense_fire_3 = HAL_GPIO_ReadPin(SENSE_FIRE_GROUP3, SENSE_FIRE_PIN_3);
|
||||
uint8_t sense_fire_4 = HAL_GPIO_ReadPin(SENSE_FIRE_GROUP4, SENSE_FIRE_PIN_4);
|
||||
uint8_t sense_fire_5 = HAL_GPIO_ReadPin(SENSE_FIRE_GROUP5, SENSE_FIRE_PIN_5);
|
||||
uint8_t sense_fire_6 = HAL_GPIO_ReadPin(SENSE_FIRE_GROUP6, SENSE_FIRE_PIN_6);
|
||||
|
||||
sense_fire = sense_fire_1 | (sense_fire_2 << 1) | (sense_fire_3 << 2) | (sense_fire_4 << 3) | (sense_fire_5 << 4) | (sense_fire_6 << 5);
|
||||
|
||||
STA_DEBUG_PRINTF("> Sense Fired pins: %d", sense_fire);
|
||||
|
||||
if (send)
|
||||
{
|
||||
msg_.payload[4] = sense_fire; // Send the sense pins on the fire output
|
||||
|
||||
// Send second half of the ADC values, via another CAN ID (+1)
|
||||
msg_.header.sid = SENSE_CAN_ID_2;
|
||||
msg_.header.payloadLength = 5;
|
||||
|
||||
// Send it out while on the pad. Otherwise we only log the data.
|
||||
sta::tacos::queueCanBusMsg(msg_, 0);
|
||||
|
||||
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_10);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_9);
|
||||
}
|
||||
if (logging)
|
||||
{
|
||||
// Log the ADC values and the sense pins on the fire output
|
||||
rres::setSenseFire(sense_fire);
|
||||
rres::setSenseADC(result_);
|
||||
|
||||
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_8);
|
||||
}
|
||||
|
||||
adc_.startDMA((uint32_t *)dmaBuffer_, bufferSize_);
|
||||
}
|
||||
|
||||
} // namespace tasks
|
||||
|
||||
// Callback for HAL ADC
|
||||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
if (tasks::adcCompleteSignal != nullptr && hadc == &hadc1)
|
||||
{
|
||||
tasks::adcCompleteSignal->notify();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user