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
6 changed files with 53 additions and 33 deletions
Showing only changes of commit 847e3bb51d - Show all commits

View File

@ -27,7 +27,7 @@ ReturnValue_t ImtqPollingTask::performOperation(uint8_t operationCode) {
comStatus = returnvalue::OK; comStatus = returnvalue::OK;
// Stopwatch watch; // Stopwatch watch;
switch (currentRequest) { switch (currentRequest.requestType) {
case imtq::RequestType::MEASURE_NO_ACTUATION: { case imtq::RequestType::MEASURE_NO_ACTUATION: {
// Measured to take 24 ms for debug and release builds. // Measured to take 24 ms for debug and release builds.
// Stopwatch watch; // Stopwatch watch;
@ -51,6 +51,9 @@ void ImtqPollingTask::handleMeasureStep() {
uint8_t* replyPtr; uint8_t* replyPtr;
ImtqRepliesDefault replies(replyBuf.data()); ImtqRepliesDefault replies(replyBuf.data());
// If some startup handling is added later, set configured after it was done once. // If some startup handling is added later, set configured after it was done once.
if (performStartup) {
performStartup = false;
}
replies.setConfigured(); replies.setConfigured();
// Can be used later to verify correct timing (e.g. all data has been read) // Can be used later to verify correct timing (e.g. all data has been read)
@ -73,7 +76,7 @@ void ImtqPollingTask::handleMeasureStep() {
return; return;
} }
if (specialRequest != imtq::SpecialRequest::NONE) { if (currentRequest.specialRequest != imtq::SpecialRequest::NONE) {
auto executeSelfTest = [&](imtq::selfTest::Axis axis) { auto executeSelfTest = [&](imtq::selfTest::Axis axis) {
cmdBuf[0] = imtq::CC::SELF_TEST_CMD; cmdBuf[0] = imtq::CC::SELF_TEST_CMD;
cmdBuf[1] = axis; cmdBuf[1] = axis;
@ -81,7 +84,7 @@ void ImtqPollingTask::handleMeasureStep() {
}; };
// If a self-test is already ongoing, ignore the request. // If a self-test is already ongoing, ignore the request.
if (replies.getSystemState()[2] != static_cast<uint8_t>(imtq::mode::SELF_TEST)) { 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): { case (imtq::SpecialRequest::DO_SELF_TEST_POS_X): {
executeSelfTest(imtq::selfTest::Axis::X_POSITIVE); executeSelfTest(imtq::selfTest::Axis::X_POSITIVE);
break; break;
@ -234,18 +237,21 @@ ReturnValue_t ImtqPollingTask::initializeInterface(CookieIF* cookie) {
ReturnValue_t ImtqPollingTask::sendMessage(CookieIF* cookie, const uint8_t* sendData, ReturnValue_t ImtqPollingTask::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) { size_t sendLen) {
const auto* imtqReq = reinterpret_cast<const imtq::Request*>(sendData); const auto* imtqReq = reinterpret_cast<const imtq::Request*>(sendData);
if (sendLen != sizeof(imtq::Request)) {
return returnvalue::FAILED;
}
{ {
MutexGuard mg(ipcLock); 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) { if (state != InternalState::IDLE) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
state = InternalState::IS_BUSY; state = InternalState::IS_BUSY;
if (currentRequest.mode != imtqReq->mode) {
if (imtqReq->mode == acs::SimpleSensorMode::NORMAL) {
performStartup = true;
}
}
std::memcpy(&currentRequest, imtqReq, sendLen);
} }
semaphore->release(); semaphore->release();
@ -345,10 +351,10 @@ void ImtqPollingTask::buildDipoleCommand() {
uint8_t* serPtr = cmdBuf.data() + 1; uint8_t* serPtr = cmdBuf.data() + 1;
size_t serLen = 0; size_t serLen = 0;
for (uint8_t idx = 0; idx < 3; idx++) { 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); SerializeIF::Endianness::LITTLE);
} }
SerializeAdapter::serialize(&torqueDuration, &serPtr, &serLen, cmdBuf.size(), SerializeAdapter::serialize(&currentRequest.torqueDuration, &serPtr, &serLen, cmdBuf.size(),
SerializeIF::Endianness::LITTLE); SerializeIF::Endianness::LITTLE);
// sif::debug << "Dipole X: " << dipoles[0] << std::endl; // sif::debug << "Dipole X: " << dipoles[0] << std::endl;
// sif::debug << "Torqeu Dur: " << torqueDuration << std::endl; // sif::debug << "Torqeu Dur: " << torqueDuration << std::endl;
@ -357,23 +363,29 @@ void ImtqPollingTask::buildDipoleCommand() {
ReturnValue_t ImtqPollingTask::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, ReturnValue_t ImtqPollingTask::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
size_t* size) { size_t* size) {
imtq::RequestType currentRequest; imtq::Request currentRequest;
{ {
MutexGuard mg(ipcLock); MutexGuard mg(ipcLock);
currentRequest = this->currentRequest; std::memcpy(&currentRequest, &this->currentRequest, sizeof(currentRequest));
} }
size_t replyLen = 0; size_t replyLen = 0;
{
MutexGuard mg(bufLock); MutexGuard mg(bufLock);
if (currentRequest == imtq::RequestType::MEASURE_NO_ACTUATION) { if (currentRequest.requestType == imtq::RequestType::MEASURE_NO_ACTUATION) {
replyLen = getExchangeBufLen(specialRequest); replyLen = getExchangeBufLen(currentRequest.specialRequest);
memcpy(exchangeBuf.data(), replyBuf.data(), replyLen); memcpy(exchangeBuf.data(), replyBuf.data(), replyLen);
} else if (currentRequest == imtq::RequestType::ACTUATE) { } else if (currentRequest.requestType == imtq::RequestType::ACTUATE) {
replyLen = ImtqRepliesWithTorque::BASE_LEN; replyLen = ImtqRepliesWithTorque::BASE_LEN;
memcpy(exchangeBuf.data(), replyBufActuation.data(), replyLen); memcpy(exchangeBuf.data(), replyBufActuation.data(), replyLen);
} else { } else {
*size = 0; *size = 0;
} }
}
{
MutexGuard mg(ipcLock);
this->currentRequest.requestType = imtq::RequestType::DO_NOTHING;
}
*buffer = exchangeBuf.data(); *buffer = exchangeBuf.data();
*size = replyLen; *size = replyLen;
return comStatus; return comStatus;

View File

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

View File

@ -178,7 +178,7 @@ ReturnValue_t ImtqHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
} }
default: { default: {
*id = imtq::cmdIds::REQUEST; *id = imtq::cmdIds::REQUEST;
request.request = imtq::RequestType::DO_NOTHING; request.requestType = imtq::RequestType::DO_NOTHING;
request.specialRequest = imtq::SpecialRequest::NONE; request.specialRequest = imtq::SpecialRequest::NONE;
expectedReply = DeviceHandlerIF::NO_COMMAND_ID; expectedReply = DeviceHandlerIF::NO_COMMAND_ID;
rawPacket = reinterpret_cast<uint8_t*>(&request); rawPacket = reinterpret_cast<uint8_t*>(&request);
@ -201,7 +201,7 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma
const uint8_t* commandData, const uint8_t* commandData,
size_t commandDataLen) { size_t commandDataLen) {
auto genericSpecialRequest = [&](imtq::SpecialRequest specialRequest) { auto genericSpecialRequest = [&](imtq::SpecialRequest specialRequest) {
request.request = imtq::RequestType::MEASURE_NO_ACTUATION; request.requestType = imtq::RequestType::MEASURE_NO_ACTUATION;
request.specialRequest = specialRequest; request.specialRequest = specialRequest;
expectedReply = imtq::cmdIds::REPLY_NO_TORQUE; expectedReply = imtq::cmdIds::REPLY_NO_TORQUE;
specialRequestActive = true; specialRequestActive = true;
@ -238,7 +238,7 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma
return returnvalue::OK; return returnvalue::OK;
} }
case (imtq::cmdIds::REQUEST): { case (imtq::cmdIds::REQUEST): {
request.request = imtq::RequestType::MEASURE_NO_ACTUATION; request.requestType = imtq::RequestType::MEASURE_NO_ACTUATION;
request.specialRequest = imtq::SpecialRequest::NONE; request.specialRequest = imtq::SpecialRequest::NONE;
expectedReply = imtq::cmdIds::REPLY_NO_TORQUE; expectedReply = imtq::cmdIds::REPLY_NO_TORQUE;
rawPacket = reinterpret_cast<uint8_t*>(&request); rawPacket = reinterpret_cast<uint8_t*>(&request);
@ -267,7 +267,7 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma
} }
expectedReply = imtq::cmdIds::REPLY_WITH_TORQUE; expectedReply = imtq::cmdIds::REPLY_WITH_TORQUE;
request.request = imtq::RequestType::ACTUATE; request.requestType = imtq::RequestType::ACTUATE;
request.specialRequest = imtq::SpecialRequest::NONE; request.specialRequest = imtq::SpecialRequest::NONE;
std::memcpy(request.dipoles, dipoleSet.dipoles.value, sizeof(request.dipoles)); std::memcpy(request.dipoles, dipoleSet.dipoles.value, sizeof(request.dipoles));
request.torqueDuration = dipoleSet.currentTorqueDurationMs.value; request.torqueDuration = dipoleSet.currentTorqueDurationMs.value;

View File

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

View File

@ -6,6 +6,8 @@
namespace acs { 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. // These modes are the submodes of the ACS controller and the modes of the ACS subsystem.
enum AcsMode : Mode_t { enum AcsMode : Mode_t {
OFF = HasModesIF::MODE_OFF, OFF = HasModesIF::MODE_OFF,

View File

@ -5,6 +5,7 @@
#include <fsfw/datapool/PoolReadGuard.h> #include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h> #include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h> #include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <mission/acs/defs.h>
class ImtqHandler; class ImtqHandler;
@ -27,7 +28,8 @@ enum class SpecialRequest : uint8_t {
}; };
struct Request { 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; imtq::SpecialRequest specialRequest = imtq::SpecialRequest::NONE;
uint8_t integrationTimeSel = 3; uint8_t integrationTimeSel = 3;
int16_t dipoles[3]{}; int16_t dipoles[3]{};