IMTQ: Lower Integration Time #552

Merged
muellerr merged 9 commits from imtq_lower_integration_time into develop 2023-04-03 15:43:31 +02:00
10 changed files with 141 additions and 54 deletions

View File

@ -18,6 +18,10 @@ will consitute of a breaking change warranting a new major release:
- q7s-package: v2.4.0
## Added
- Version of thermal controller which performs basic control tasks.
## Fixed
- PTME was not reset after configuration changes.
@ -26,6 +30,9 @@ will consitute of a breaking change warranting a new major release:
- Poll threshold configuration of the PTME IP core is now configurable via a parameter command
and is set to 0b010 (4 polls) instead of 0b001 (1 poll) per default.
- EIVE system fallback and COM system fallback: Perform general subsystem handling first, then
event reception, and finally any new transition handling.
- IMTQ MGM integration time lowered to 6 ms. This relaxes scheduling requirements a bit.
# [v1.42.0] 2023-04-01
@ -100,7 +107,6 @@ will consitute of a breaking change warranting a new major release:
## Added
- Version of thermal controller which performs basic control tasks.
- The event `MEKF_RECOVERY` will be triggered in case the `MEKF` does manage to recover itself.
- The persistent TM stores now have low priorities and behave like background threads now. This
should prevent them from blocking or slowing down the system even during dumps
@ -112,8 +118,6 @@ will consitute of a breaking change warranting a new major release:
## Changed
- EIVE system fallback and COM system fallback: Perform general subsystem handling first, then
event reception, and finally any new transition handling.
- Rework FSFW OSALs to properly support regular scheduling (NICE priorities) and real-time
scheduling.
- STR: Move datalink layer to `StrComHandler` completely. DLL is now completely hidden from
@ -137,7 +141,6 @@ will consitute of a breaking change warranting a new major release:
- Bugfix for STR: Some action commands wrongfully declined.
- STR: No normal command handling while a special request like an image upload is active.
- RS485 data line was not enabled when the transmitter was switched on.
>>>>>>> origin/develop
# [v1.39.0] 2023-03-21

View File

@ -27,7 +27,7 @@ ReturnValue_t ImtqPollingTask::performOperation(uint8_t operationCode) {
comStatus = returnvalue::OK;
// Stopwatch watch;
switch (currentRequest) {
switch (currentRequest.requestType) {
case imtq::RequestType::MEASURE_NO_ACTUATION: {
// Measured to take 24 ms for debug and release builds.
// Stopwatch watch;
@ -51,6 +51,30 @@ void ImtqPollingTask::handleMeasureStep() {
uint8_t* replyPtr;
ImtqRepliesDefault replies(replyBuf.data());
// If some startup handling is added later, set configured after it was done once.
if (performStartup) {
// Set integration time for the MGM.
cmdBuf[0] = imtq::CC::SET_PARAM;
size_t dummy = 0;
SerializeAdapter::serialize(&imtq::param::INTEGRATION_TIME_SELECT, cmdBuf.data() + 1, &dummy,
cmdBuf.size(), SerializeIF::Endianness::LITTLE);
cmdBuf[3] = currentRequest.integrationTimeSel;
cmdLen = 4;
ReturnValue_t result = performI2cFullRequest(replyBuf.data(), 5);
if (result != returnvalue::OK) {
comStatus = imtq::STARTUP_CFG_ERROR;
}
if (replyBuf[0] != imtq::CC::SET_PARAM) {
sif::error << "ImtqPollingTask: First byte of reply not equal to sent CC" << std::endl;
comStatus = imtq::STARTUP_CFG_ERROR;
}
if (replyBuf[4] != currentRequest.integrationTimeSel) {
sif::error << "ImtqPollingTask: Integration time configuration failed" << std::endl;
comStatus = imtq::STARTUP_CFG_ERROR;
}
currentIntegrationTimeMs =
imtq::integrationTimeFromSelectValue(currentRequest.integrationTimeSel);
performStartup = false;
}
replies.setConfigured();
// Can be used later to verify correct timing (e.g. all data has been read)
@ -73,7 +97,7 @@ void ImtqPollingTask::handleMeasureStep() {
return;
}
if (specialRequest != imtq::SpecialRequest::NONE) {
if (currentRequest.specialRequest != imtq::SpecialRequest::NONE) {
auto executeSelfTest = [&](imtq::selfTest::Axis axis) {
cmdBuf[0] = imtq::CC::SELF_TEST_CMD;
cmdBuf[1] = axis;
@ -81,7 +105,7 @@ void ImtqPollingTask::handleMeasureStep() {
};
// If a self-test is already ongoing, ignore the request.
if (replies.getSystemState()[2] != static_cast<uint8_t>(imtq::mode::SELF_TEST)) {
switch (specialRequest) {
switch (currentRequest.specialRequest) {
case (imtq::SpecialRequest::DO_SELF_TEST_POS_X): {
executeSelfTest(imtq::selfTest::Axis::X_POSITIVE);
break;
@ -234,18 +258,21 @@ ReturnValue_t ImtqPollingTask::initializeInterface(CookieIF* cookie) {
ReturnValue_t ImtqPollingTask::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) {
const auto* imtqReq = reinterpret_cast<const imtq::Request*>(sendData);
if (sendLen != sizeof(imtq::Request)) {
return returnvalue::FAILED;
}
{
MutexGuard mg(ipcLock);
if (imtqReq->request == imtq::RequestType::ACTUATE) {
std::memcpy(dipoles, imtqReq->dipoles, sizeof(dipoles));
torqueDuration = imtqReq->torqueDuration;
}
currentRequest = imtqReq->request;
specialRequest = imtqReq->specialRequest;
if (state != InternalState::IDLE) {
return returnvalue::FAILED;
}
state = InternalState::IS_BUSY;
if (currentRequest.mode != imtqReq->mode) {
if (imtqReq->mode == acs::SimpleSensorMode::NORMAL) {
performStartup = true;
}
}
std::memcpy(&currentRequest, imtqReq, sendLen);
}
semaphore->release();
@ -345,10 +372,10 @@ void ImtqPollingTask::buildDipoleCommand() {
uint8_t* serPtr = cmdBuf.data() + 1;
size_t serLen = 0;
for (uint8_t idx = 0; idx < 3; idx++) {
SerializeAdapter::serialize(&dipoles[idx], &serPtr, &serLen, cmdBuf.size(),
SerializeAdapter::serialize(&currentRequest.dipoles[idx], &serPtr, &serLen, cmdBuf.size(),
SerializeIF::Endianness::LITTLE);
}
SerializeAdapter::serialize(&torqueDuration, &serPtr, &serLen, cmdBuf.size(),
SerializeAdapter::serialize(&currentRequest.torqueDuration, &serPtr, &serLen, cmdBuf.size(),
SerializeIF::Endianness::LITTLE);
// sif::debug << "Dipole X: " << dipoles[0] << std::endl;
// sif::debug << "Torqeu Dur: " << torqueDuration << std::endl;
@ -357,22 +384,28 @@ void ImtqPollingTask::buildDipoleCommand() {
ReturnValue_t ImtqPollingTask::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
size_t* size) {
imtq::RequestType currentRequest;
imtq::Request currentRequest;
{
MutexGuard mg(ipcLock);
currentRequest = this->currentRequest;
std::memcpy(&currentRequest, &this->currentRequest, sizeof(currentRequest));
}
size_t replyLen = 0;
MutexGuard mg(bufLock);
if (currentRequest == imtq::RequestType::MEASURE_NO_ACTUATION) {
replyLen = getExchangeBufLen(specialRequest);
memcpy(exchangeBuf.data(), replyBuf.data(), replyLen);
} else if (currentRequest == imtq::RequestType::ACTUATE) {
replyLen = ImtqRepliesWithTorque::BASE_LEN;
memcpy(exchangeBuf.data(), replyBufActuation.data(), replyLen);
} else {
*size = 0;
{
MutexGuard mg(bufLock);
if (currentRequest.requestType == imtq::RequestType::MEASURE_NO_ACTUATION) {
replyLen = getExchangeBufLen(currentRequest.specialRequest);
memcpy(exchangeBuf.data(), replyBuf.data(), replyLen);
} else if (currentRequest.requestType == imtq::RequestType::ACTUATE) {
replyLen = ImtqRepliesWithTorque::BASE_LEN;
memcpy(exchangeBuf.data(), replyBufActuation.data(), replyLen);
} else {
*size = 0;
}
}
{
MutexGuard mg(ipcLock);
this->currentRequest.requestType = imtq::RequestType::DO_NOTHING;
}
*buffer = exchangeBuf.data();
*size = replyLen;
@ -417,6 +450,7 @@ void ImtqPollingTask::clearReadFlagsWithTorque(ImtqRepliesWithTorque& replies) {
ReturnValue_t ImtqPollingTask::performI2cFullRequest(uint8_t* reply, size_t replyLen) {
int fd = 0;
if (cmdLen == 0 or reply == nullptr) {
sif::error << "ImtqPollingTask: Command lenght is zero or reply PTR is invalid" << std::endl;
return returnvalue::FAILED;
}

View File

@ -3,6 +3,7 @@
#include <fsfw/tasks/SemaphoreIF.h>
#include <fsfw_hal/linux/i2c/I2cCookie.h>
#include <mission/acs/acsBoardPolling.h>
#include <atomic>
@ -24,7 +25,6 @@ class ImtqPollingTask : public SystemObject,
static constexpr ReturnValue_t NO_REPLY_AVAILABLE = returnvalue::makeCode(2, 0);
enum class InternalState { IDLE, IS_BUSY } state = InternalState::IDLE;
imtq::RequestType currentRequest = imtq::RequestType::MEASURE_NO_ACTUATION;
SemaphoreIF* semaphore;
ReturnValue_t comStatus = returnvalue::OK;
@ -38,10 +38,9 @@ class ImtqPollingTask : public SystemObject,
// Required in addition to integration time, otherwise old data might be read.
static constexpr uint32_t MGM_READ_BUFFER_TIME_MS = 6;
bool ignoreNextActuateRequest = false;
bool performStartup = false;
imtq::SpecialRequest specialRequest = imtq::SpecialRequest::NONE;
int16_t dipoles[3] = {};
uint16_t torqueDuration = 0;
imtq::Request currentRequest{};
std::array<uint8_t, 32> cmdBuf;
std::array<uint8_t, 524> replyBuf;

View File

@ -151,19 +151,25 @@ void ImtqHandler::doStartUp() {
}
void ImtqHandler::doShutDown() {
updatePeriodicReply(false, imtq::cmdIds::REPLY_NO_TORQUE);
updatePeriodicReply(false, imtq::cmdIds::REPLY_WITH_TORQUE);
specialRequestActive = false;
firstReplyCycle = true;
internalState = InternalState::NONE;
commandExecuted = false;
statusSet.setValidity(false, true);
rawMtmNoTorque.setValidity(false, true);
rawMtmWithTorque.setValidity(false, true);
hkDatasetNoTorque.setValidity(false, true);
hkDatasetWithTorque.setValidity(false, true);
calMtmMeasurementSet.setValidity(false, true);
setMode(_MODE_POWER_DOWN);
if (internalState != InternalState::SHUTDOWN) {
commandExecuted = false;
internalState = InternalState::SHUTDOWN;
}
if (internalState == InternalState::SHUTDOWN and commandExecuted) {
updatePeriodicReply(false, imtq::cmdIds::REPLY_NO_TORQUE);
updatePeriodicReply(false, imtq::cmdIds::REPLY_WITH_TORQUE);
specialRequestActive = false;
firstReplyCycle = true;
internalState = InternalState::NONE;
commandExecuted = false;
statusSet.setValidity(false, true);
rawMtmNoTorque.setValidity(false, true);
rawMtmWithTorque.setValidity(false, true);
hkDatasetNoTorque.setValidity(false, true);
hkDatasetWithTorque.setValidity(false, true);
calMtmMeasurementSet.setValidity(false, true);
setMode(_MODE_POWER_DOWN);
}
}
ReturnValue_t ImtqHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
@ -178,7 +184,7 @@ ReturnValue_t ImtqHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
}
default: {
*id = imtq::cmdIds::REQUEST;
request.request = imtq::RequestType::DO_NOTHING;
request.requestType = imtq::RequestType::DO_NOTHING;
request.specialRequest = imtq::SpecialRequest::NONE;
expectedReply = DeviceHandlerIF::NO_COMMAND_ID;
rawPacket = reinterpret_cast<uint8_t*>(&request);
@ -190,7 +196,7 @@ ReturnValue_t ImtqHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
}
ReturnValue_t ImtqHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
if (internalState == InternalState::STARTUP) {
if (internalState == InternalState::STARTUP or internalState == InternalState::SHUTDOWN) {
*id = imtq::cmdIds::REQUEST;
return buildCommandFromCommand(*id, nullptr, 0);
}
@ -201,7 +207,7 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma
const uint8_t* commandData,
size_t commandDataLen) {
auto genericSpecialRequest = [&](imtq::SpecialRequest specialRequest) {
request.request = imtq::RequestType::MEASURE_NO_ACTUATION;
request.requestType = imtq::RequestType::MEASURE_NO_ACTUATION;
request.specialRequest = specialRequest;
expectedReply = imtq::cmdIds::REPLY_NO_TORQUE;
specialRequestActive = true;
@ -238,9 +244,16 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma
return returnvalue::OK;
}
case (imtq::cmdIds::REQUEST): {
request.request = imtq::RequestType::MEASURE_NO_ACTUATION;
request.requestType = imtq::RequestType::MEASURE_NO_ACTUATION;
request.specialRequest = imtq::SpecialRequest::NONE;
// 6 ms integration time instead of 10 ms.
request.integrationTimeSel = 2;
expectedReply = imtq::cmdIds::REPLY_NO_TORQUE;
if (internalState == InternalState::SHUTDOWN) {
request.mode = acs::SimpleSensorMode::OFF;
} else {
request.mode = acs::SimpleSensorMode::NORMAL;
}
rawPacket = reinterpret_cast<uint8_t*>(&request);
rawPacketLen = sizeof(imtq::Request);
return returnvalue::OK;
@ -267,7 +280,7 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma
}
expectedReply = imtq::cmdIds::REPLY_WITH_TORQUE;
request.request = imtq::RequestType::ACTUATE;
request.requestType = imtq::RequestType::ACTUATE;
request.specialRequest = imtq::SpecialRequest::NONE;
std::memcpy(request.dipoles, dipoleSet.dipoles.value, sizeof(request.dipoles));
request.torqueDuration = dipoleSet.currentTorqueDurationMs.value;
@ -309,6 +322,9 @@ ReturnValue_t ImtqHandler::scanForReply(const uint8_t* start, size_t remainingSi
if (getMode() == _MODE_WAIT_OFF or getMode() == _MODE_WAIT_ON or getMode() == _MODE_POWER_DOWN) {
return IGNORE_FULL_PACKET;
}
if (internalState == InternalState::SHUTDOWN) {
commandExecuted = true;
}
if (remainingSize > 0) {
*foundLen = remainingSize;
*foundId = expectedReply;

View File

@ -1,13 +1,13 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_ACSPOLLING_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_ACSPOLLING_H_
#include <mission/acs/defs.h>
#include "fsfw/thermal/tcsDefinitions.h"
#include "gyroAdisHelpers.h"
namespace acs {
enum SimpleSensorMode { NORMAL = 0, OFF = 1 };
struct Adis1650XRequest {
SimpleSensorMode mode;
adis1650x::Type type;

View File

@ -6,6 +6,8 @@
namespace acs {
enum class SimpleSensorMode { NORMAL = 0, OFF = 1 };
// These modes are the submodes of the ACS controller and the modes of the ACS subsystem.
enum AcsMode : Mode_t {
OFF = HasModesIF::MODE_OFF,

View File

@ -1,5 +1,26 @@
#include "imtqHelpers.h"
uint16_t imtq::integrationTimeFromSelectValue(uint8_t value) {
switch (value) {
case (0):
return 2;
case (1):
return 3;
case (2):
return 6;
case (3):
return 10;
case (4):
return 20;
case (5):
return 40;
case (6):
return 80;
default:
return 10;
}
}
size_t imtq::getReplySize(CC::CC cc, size_t* optSecondSize) {
switch (cc) {
// Software reset is a bit special and can also cause a I2C NAK because

View File

@ -5,6 +5,7 @@
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <mission/acs/defs.h>
class ImtqHandler;
@ -13,6 +14,8 @@ class ImtqHandler;
namespace imtq {
uint16_t integrationTimeFromSelectValue(uint8_t value);
enum class RequestType : uint8_t { MEASURE_NO_ACTUATION, ACTUATE, DO_NOTHING };
enum class SpecialRequest : uint8_t {
@ -27,7 +30,8 @@ enum class SpecialRequest : uint8_t {
};
struct Request {
imtq::RequestType request = imtq::RequestType::MEASURE_NO_ACTUATION;
acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF;
imtq::RequestType requestType = imtq::RequestType::MEASURE_NO_ACTUATION;
imtq::SpecialRequest specialRequest = imtq::SpecialRequest::NONE;
uint8_t integrationTimeSel = 3;
int16_t dipoles[3]{};
@ -57,9 +61,10 @@ static const ReturnValue_t CC_UNAVAILABLE = MAKE_RETURN_CODE(5);
static const ReturnValue_t INTERNAL_PROCESSING_ERROR = MAKE_RETURN_CODE(6);
static const ReturnValue_t REJECTED_WITHOUT_REASON = MAKE_RETURN_CODE(7);
static const ReturnValue_t CMD_ERR_UNKNOWN = MAKE_RETURN_CODE(8);
static constexpr ReturnValue_t STARTUP_CFG_ERROR = MAKE_RETURN_CODE(9);
//! [EXPORT] : [COMMENT] The status reply to a self test command was received but no self test
//! command has been sent. This should normally never happen.
static const ReturnValue_t UNEXPECTED_SELF_TEST_REPLY = MAKE_RETURN_CODE(0xA7);
static const ReturnValue_t UNEXPECTED_SELF_TEST_REPLY = MAKE_RETURN_CODE(10);
namespace cmdIds {
@ -162,6 +167,13 @@ enum CC : uint8_t {
} // namespace CC
namespace param {
static constexpr uint16_t SEL_MTM = 0x2002;
static constexpr uint16_t INTEGRATION_TIME_SELECT = 0x2003;
} // namespace param
size_t getReplySize(CC::CC cc, size_t* optSecondSize = nullptr);
namespace mode {

View File

@ -129,7 +129,7 @@ void ThermalController::performControlOperation() {
hpaLimits.opUpperLimit = 0;
hpaLimits.nopUpperLimit = 0;
#endif
if(changedLimits) {
if (changedLimits) {
sif::debug << "ThermalController: changing limits" << std::endl; // TODO: rausschmeissen
}
}

View File

@ -293,7 +293,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
// Just waiting for the main switch being set on
return;
} else if (mainSwitchState == PowerSwitchIF::SWITCH_OFF or
mainSwitchState == PowerSwitchIF::SWITCH_UNKNOWN) {
mainSwitchState == PowerSwitchIF::SWITCH_UNKNOWN) {
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_ON);
heater.mainSwitchCountdown.setTimeout(mainLineSwitcher->getSwitchDelayMs());
heater.waitMainSwitchOn = true;