Skip to content

Commit

Permalink
Merge pull request #31 from lsst-ts/tickets/DM-41336
Browse files Browse the repository at this point in the history
Use MPU runLoop, paraller operations on FlowMeter and VFD
  • Loading branch information
pkubanek authored Nov 18, 2023
2 parents 812d751 + 6fd73e5 commit c6499f1
Show file tree
Hide file tree
Showing 43 changed files with 65,595 additions and 64,784 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Check Actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Changelog check
uses: Zomzog/[email protected]
with:
Expand Down
129,621 changes: 64,984 additions & 64,637 deletions Bitfiles/NiFpga_ts_M1M3ThermalFPGA.lvbitx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN source ~/.crio_setup.sh && cd $TS_XML_DIR \

FROM crio-develop

ARG cRIO_CPP=v1.7.0
ARG cRIO_CPP=v1.10.0
ARG M1M3_SUPPORT=develop
ARG TARGET=simulator

Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ properties(
node {
def SALUSER_HOME = "/home/saluser"
def BRANCH = (env.CHANGE_BRANCH != null) ? env.CHANGE_BRANCH : env.BRANCH_NAME
def SAME_CRIO_BRANCH = ["main", "tickets/DM-40800"]
def SAME_CRIO_BRANCH = ["main", "tickets/DM-41336"]

stage('Cloning sources')
{
Expand Down Expand Up @@ -59,7 +59,7 @@ node {
cd $WORKSPACE/ts_m1m3thermal
LIBS_FLAGS="-L\$CONDA_PREFIX/lib" make simulator
make junit
LSST_DDS_PARTITION_PREFIX=test make junit
"""
}
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ m1m3tscli: src/m1m3tscli.cpp.o src/libM1M3TS.a

# Other Targets
clean:
@$(foreach file,M1M3ThermalCsC src/m1m3thermalcsc.cpp.o doc, echo '[RM ] ${file}'; $(RM) -r $(file);)
@$(foreach file,M1M3ThermalCsC src/m1m3thermalcsc.cpp.o, echo '[RM ] ${file}'; $(RM) -r $(file);)
@$(foreach dir,src tests,$(MAKE) -C ${dir} $@;)

# file targets
Expand Down
11 changes: 8 additions & 3 deletions Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ifndef VERBOSE
silence := --silence-errors
endif

c_opts := -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE
c_opts := -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE # -DSPDLOG_FMT_EXTERNAL

ifdef DEBUG
c_opts += -g
Expand All @@ -22,14 +22,19 @@ else
CPP := g++ -std=c++14 -Wall -fmessage-length=0 ${c_opts} -ldl -lpthread
endif

PKG_CPPFLAGS := $(shell pkg-config yaml-cpp --cflags $(silence)) $(shell pkg-config spdlog --cflags $(silence))
PKG_CPPFLAGS := $(shell pkg-config yaml-cpp --cflags $(silence)) \
$(shell pkg-config spdlog --cflags $(silence)) \
$(shell pkg-config fmt --cflags $(silence))

SAL_CPPFLAGS += $(PKG_CPPFLAGS) -I${OSPL_HOME}/include -I${OSPL_HOME}/include/sys -I${OSPL_HOME}/include/dcps/C++/SACPP -I${SAL_WORK_DIR}/MTM1M3TS/cpp/src -I${SAL_WORK_DIR}/include -I${SAL_HOME}/include -I${LSST_SDK_INSTALL}/include

CRIO_DIR ?= ../ts_cRIOcpp
CRIO_CFLAGS := -I${CRIO_DIR}/include

PKG_LIBS := $(shell pkg-config yaml-cpp --libs $(silence)) $(shell pkg-config spdlog --libs $(silence))
PKG_LIBS := $(shell pkg-config yaml-cpp --libs $(silence)) \
$(shell pkg-config spdlog --libs $(silence)) \
$(shell pkg-config fmt --libs $(silence)) \
-lreadline

ifdef SIMULATOR
LIBS := $(PKG_LIBS) -ldl ${SAL_WORK_DIR}/lib/libSAL_MTM1M3TS.a -ldcpssacpp -ldcpsgapi -lddsuser -lddskernel -lpthread -lddsserialization -lddsconfparser -lddsconf -lddsdatabase -lddsutil -lddsos
Expand Down
1 change: 0 additions & 1 deletion SettingFiles/Sets/Default/1/FCU.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions SettingFiles/Sets/Default/1/MixingValve.yaml

This file was deleted.

21 changes: 21 additions & 0 deletions SettingFiles/v1/_init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FCU:
AutoDisable: true
FailuresToDisable: 3
Disabled: []

FlowMeter:
Enabled: true

GlycolPump:
Enabled: true

MixingValve:
# units are mA (milliamperes)
Commanding:
FullyClosed: 4
FullyOpened: 20

# units are V (Volts)
PositionFeedback:
FullyClosed: 0.03
FullyOpened: 9.64
10 changes: 10 additions & 0 deletions doc/version-history.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _Version_History:

===============
Version History
===============

v0.1.0
=======

* Basic functionality - FCU communication, FlowMeter and Glycol Pump telemetry & commands
25 changes: 18 additions & 7 deletions src/LSST/M1M3/TS/Commands/SAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
#include <cRIO/ControllerThread.h>

#include <Commands/SAL.h>
#include <Events/SummaryState.h>
#include <Events/EngineeringMode.h>
#include <Events/SummaryState.h>
#include <Events/ThermalInfo.h>
#include <Settings/MixingValve.h>
#include <Settings/Controller.h>
#include <Settings/GlycolPump.h>
#include <Settings/MixingValve.h>
#include <TSApplication.h>
#include <TSPublisher.h>

using namespace LSST::cRIO;
using namespace LSST::M1M3::TS;
Expand All @@ -48,17 +50,25 @@ void changeAllILCsMode(uint16_t mode) {
}

bool SAL_start::validate() {
// TODO needs new, single file config
if (params.configurationOverride.empty()) {
params.configurationOverride = "Default";
}
if (params.configurationOverride[0] == '_') {
SPDLOG_ERROR("configurationOverride argument shall not start with _");
return false;
}
return true;
}

void SAL_start::execute() {
SPDLOG_INFO("Starting, settings={}", params.configurationOverride);
Settings::Controller::instance().load(params.configurationOverride);

if (Settings::GlycolPump::instance().enabled) {
IFPGA::get().setCoolantPumpPower(true);
SPDLOG_INFO("Glycol pump turned on.");
}

changeAllILCsMode(ILC::ILCMode::Disabled);

TSApplication::ilc()->clear();
Expand Down Expand Up @@ -86,6 +96,7 @@ void SAL_enable::execute() {
void SAL_disable::execute() {
changeAllILCsMode(ILC::ILCMode::Disabled);
IFPGA::get().setFCUPower(false);
IFPGA::get().setCoolantPumpPower(false);

Events::SummaryState::setState(MTM1M3TS_shared_SummaryStates_DisabledState);
ackComplete();
Expand Down Expand Up @@ -150,13 +161,13 @@ void SAL_coolantPumpPower::execute() {
}

void SAL_coolantPumpStart::execute() {
IFPGA::get().coolantPumpStartStop(true);
IFPGA::get().next_vfd->start();
ackComplete();
SPDLOG_INFO("Glycol coolant pump started");
}

void SAL_coolantPumpStop::execute() {
IFPGA::get().coolantPumpStartStop(false);
IFPGA::get().next_vfd->stop();
ackComplete();
SPDLOG_INFO("Glycol coolant pump stopped");
}
Expand All @@ -170,13 +181,13 @@ bool SAL_coolantPumpFrequency::validate() {
}

void SAL_coolantPumpFrequency::execute() {
IFPGA::get().setCoolantPumpFrequency(params.targetFrequency);
IFPGA::get().next_vfd->setFrequency(params.targetFrequency);
ackComplete();
SPDLOG_INFO("Changed coolant pump target frequency to {:0.02f} Hz", params.targetFrequency);
}

void SAL_coolantPumpReset::execute() {
IFPGA::get().coolantPumpReset();
IFPGA::get().next_vfd->resetCommand();
ackComplete();
SPDLOG_INFO("Coolant pump reseted");
}
3 changes: 2 additions & 1 deletion src/LSST/M1M3/TS/Commands/SAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
#ifndef _TS_Command_SAL
#define _TS_Command_SAL

#include <TSPublisher.h>
#include <SAL_MTM1M3TS.h>

#include <cRIO/SAL/Command.h>

#include <TSPublisher.h>

namespace LSST {
namespace M1M3 {
namespace TS {
Expand Down
31 changes: 23 additions & 8 deletions src/LSST/M1M3/TS/Commands/Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@
#include <cRIO/ThermalILC.h>

#include "Commands/Update.h"
#include "TSApplication.h"

#include "Events/EnabledILC.h"
#include "Events/GlycolPumpStatus.h"
#include "Events/Heartbeat.h"
#include "Events/SummaryState.h"

#include "Settings/FlowMeter.h"
#include "Settings/GlycolPump.h"

#include "Telemetry/VFDSAL.h"
#include "Telemetry/GlycolLoopTemperature.h"
#include "Telemetry/MixingValve.h"
#include "Telemetry/ThermalData.h"
#include "Events/GlycolPumpStatus.h"

#include "TSApplication.h"

using namespace LSST::M1M3::TS::Commands;

Expand All @@ -51,8 +55,13 @@ void Update::execute() {

Events::Heartbeat::instance().tryToggle();

_sendFlowMeter();
_sendVFD();
if (Settings::FlowMeter::instance().enabled) {
_sendFlowMeter();
}

if (Settings::GlycolPump::instance().enabled) {
_sendVFD();
}

SPDLOG_TRACE("Commands::Update leaving execute");
}
Expand Down Expand Up @@ -97,18 +106,24 @@ void Update::_sendFCU() {

void Update::_sendFlowMeter() {
try {
IFPGA::get().flowMeter->runLoop(IFPGA::get());
bool finished = IFPGA::get().flowMeter->runLoop(IFPGA::get());
if (finished) {
IFPGA::get().setNextFlowMeter();
}
} catch (std::exception &e) {
SPDLOG_WARN("Cannot poll Flow Meter: {}", e.what());
IFPGA::get().flowMeter->clearCommanded();
IFPGA::get().setNextFlowMeter();
}
}

void Update::_sendVFD() {
try {
IFPGA::get().vfd->runLoop(IFPGA::get());
bool finished = IFPGA::get().vfd->runLoop(IFPGA::get());
if (finished) {
IFPGA::get().setNextVFD();
}
} catch (std::exception &e) {
SPDLOG_WARN("Cannot poll VFD: {}", e.what());
IFPGA::get().vfd->clearCommanded();
IFPGA::get().setNextVFD();
}
}
24 changes: 21 additions & 3 deletions src/LSST/M1M3/TS/Events/EnabledILC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@
#include <spdlog/spdlog.h>

#include <cRIO/ThermalILC.h>
#include <TSPublisher.h>

#include <Events/EnabledILC.h>
#include <Settings/Thermal.h>
#include <TSPublisher.h>

using namespace LSST::M1M3::TS;
using namespace LSST::M1M3::TS::Events;

EnabledILC::EnabledILC(token) : _updated(true) {
for (int i = 0; i < LSST::cRIO::NUM_TS_ILC; i++) {
EnabledILC::EnabledILC(token) : _updated(true) { reset(); }

void EnabledILC::reset() {
for (size_t i = 0; i < cRIO::NUM_TS_ILC; i++) {
enabled[i] = true;
autoDisabled[i] = false;
errorCount[i] = 0;
}
_updated = true;
}

void EnabledILC::setEnabled(uint8_t ilc, bool newState) {
Expand All @@ -44,6 +51,17 @@ void EnabledILC::setEnabled(uint8_t ilc, bool newState) {

bool EnabledILC::isEnabled(uint8_t ilc) { return enabled[ilc]; }

void EnabledILC::communicationProblem(uint8_t ilc) {
errorCount[ilc]++;
if (Settings::Thermal::instance().autoDisable) {
if (errorCount[ilc] > Settings::Thermal::instance().failuresToDisable) {
autoDisabled[ilc] = true;
setEnabled(ilc, false);
}
}
_updated = true;
}

void EnabledILC::send() {
if (_updated == false) {
return;
Expand Down
15 changes: 15 additions & 0 deletions src/LSST/M1M3/TS/Events/EnabledILC.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,33 @@ class EnabledILC final : MTM1M3TS_logevent_enabledILCC, public cRIO::Singleton<E
public:
EnabledILC(token);

/**
* Clears failed ILC counts.
*/
void reset();

/**
* Enabled / disable ILC.
*/
void setEnabled(uint8_t ilc, bool newState);

bool isEnabled(uint8_t ilc);

/**
* Called when an ILC experienced communication problem. Auto disable ILC
* if communication errors cross a counter.
*/
void communicationProblem(uint8_t ilc);

/**
* Sends updates through SAL/DDS.
*/
void send();

// TODO move to SAL/DDS
int errorCount[cRIO::NUM_TS_ILC];
bool autoDisabled[cRIO::NUM_TS_ILC];

private:
bool _updated;
};
Expand Down
Loading

0 comments on commit c6499f1

Please sign in to comment.