Skip to content
Snippets Groups Projects
Commit 3b32411d authored by xiyehu2's avatar xiyehu2
Browse files

dirty test files sync

parent d47c7308
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <set>
#include "../lib/waveform.h"
#include "../lib/AWG.h"
#include "../lib/devices/AWG.h"
#include "../lib/devices/basler.h"
int main() {
auto sr = 614.4e6;
auto wfm = ArrayWaveform();
// auto sr = 614.4e6;
// auto wfm = ArrayWaveform();
// idealy, waveform param setting here are loaded from
// another waveform via some sort of config file
wfm.setSamplingRate(sr);
wfm.setFreqResolution(1e3);
wfm.setFreqTone(
105e6,
1e6,
5
);
wfm.setAmplitude(std::vector<double> (5, 2000));
wfm.setPhase(std::vector<double> (5, 0));
wfm.printParam();
// wfm.setSamplingRate(sr);
// wfm.setFreqResolution(1e3);
// wfm.loadParam("testParam.csv");
// wfm.saveParam(("testParam2.csv"));
// wfm.setFreqTone(
// 105e6,
// 1e6,
// 5
// );
// wfm.setAmplitude(std::vector<double> (5, 2000));
// wfm.setPhase(std::vector<double> (5, 0));
// wfm.printParam();
// generate waveform
auto wfmData = wfm.getStaticWaveform();
auto awg = AWG();
awg.open(0); // open card at index 0
awg.setSampleRate(sr); // set card sampling rate
awg.setActiveChannels(std::set<int> {0}); // set output channels
awg.setChannel( // set channel output params
0,
2500,
AWG::CHANNEL_STOPLVL::ZERO,
true
);
awg.setTrigMode(
0,
AWG::TRIGGER_MODE::POS
); // set trigger channel 0 (EXT0) mode to be positve edge
awg.setTrigMaskOr({
AWG::TRIGGER_MASK::EXT0,
// AWG::TRIGGER_MASK::EXT1
}); // set the trigger engine to be OR and enable both
// channel EXT0 and/or EXT1
awg.initReplayModeSeq(2); // intializes card for sequence replay mode
// with two memory segments
awg.writeSeqModeSegment(
0,
wfmData.first,
wfmData.second
);
awg.writeSeqModeSegment(
1,
wfmData.first,
wfmData.second * 2
); // load wfms onto both memory segements for simplicity,
// a memory segment needs only be initialized with data
// if it is configured as part of the step sequence below
awg.setSeqModeStep(
0,
0,
1,
1,
AWG::SEQ_LOOPCONDITION::ONTRIG
);
awg.setSeqModeStep(
1,
1,
0,
1,
AWG::SEQ_LOOPCONDITION::ONTRIG
);
awg.cardRun();
awg.cardStop();
awg.close();
// auto wfmData = wfm.getStaticWaveform();
// wfm.getStaticWaveform();
// wfm.saveParam(("testParam.csv"));
// wfm.saveWaveform("testWfm.csv");
// auto awg = AWG();
// awg.open(0); // open card at index 0
// awg.setSampleRate(sr); // set card sampling rate
// awg.setActiveChannels(std::set<int> {0}); // set output channels
// awg.setChannel( // set channel output params
// 0,
// 2500,
// AWG::CHANNEL_STOPLVL::ZERO,
// true
// );
// awg.setTrigMode(
// 0,
// AWG::TRIGGER_MODE::POS
// ); // set trigger channel 0 (EXT0) mode to be positve edge
// awg.setTrigMaskOr({
// AWG::TRIGGER_MASK::EXT0,
// // AWG::TRIGGER_MASK::EXT1
// }); // set the trigger engine to be OR and enable both
// // channel EXT0 and/or EXT1
// awg.initReplayModeSeq(2); // intializes card for sequence replay mode
// // with two memory segments
// awg.writeSeqModeSegment(
// 0,
// wfmData.first,
// wfmData.second
// );
// awg.writeSeqModeSegment(
// 1,
// wfmData.first,
// wfmData.second * 2
// ); // load wfms onto both memory segements for simplicity,
// // a memory segment needs only be initialized with data
// // if it is configured as part of the step sequence below
// awg.setSeqModeStep(
// 0,
// 0,
// 1,
// 1,
// AWG::SEQ_LOOPCONDITION::ONTRIG
// );
// awg.setSeqModeStep(
// 1,
// 1,
// 0,
// 1,
// AWG::SEQ_LOOPCONDITION::ONTRIG
// );
// awg.cardRun();
// awg.cardStop();
// awg.close();
return 0;
}
\ No newline at end of file
#include "../lib/waveform.h"
#include "../lib/devices/AWG.h"
#include "../lib/devices/basler.h"
#include "../lib/image_process.h"
#include "../lib/uniformization.h"
#include "../lib/external/npy.hpp"
#include <filesystem>
#include <unistd.h>
#include <chrono>
#include <ctime>
template <typename T>
void printVec(std::vector<T>& vec) {
for (auto i : vec) {
std::cout << i << ",";
}
std::cout << "\n";
}
Eigen::ArrayXd getWeightedMask(
Eigen::Ref<Eigen::ArrayXd> detProbe,
Eigen::Ref<Eigen::ArrayXd> initPower,
double polarizability,
double meanDepth
) {
auto depths = meanDepth + (detProbe - detProbe.mean()) / polarizability;
Eigen::ArrayXd mask = depths / depths.mean()
* initPower.mean() / initPower;
return mask;
}
int main() {
double polarz = -5.6e-3;
double meanDepth = 575;
std::filesystem::path savePath("/home/simon/Documents/lab/"
"/code/awg-control/Cpp/");
std::filesystem::path probeScanPath("/home/simon/Documents/lab/"
"data/probe-det.npy");
std::filesystem::path testImgPath("/home/simon/Documents/lab/"
"data/peak.tiff");
// auto detProbe = npy::read_npy<double> (probeScanPath).data;
// Eigen::Map<Eigen::ArrayXd> detProbeEigen(detProbe.data(), detProbe.size());
// cv::Mat twzrImage = cv::imread(testImgPath, cv::IMREAD_GRAYSCALE);
// auto peaks = ImageProcessing::getPeaks(twzrImage, -1, savePath);
// auto twzrCrops = ImageProcessing::getSubImgs(twzrImage, peaks, savePath);
// auto power = ImageProcessing::getPowers(twzrCrops);
// Eigen::Map<Eigen::ArrayXd> powersEigen(power.data(), power.size());
// auto weightedMask = getWeightedMask(
// detProbeEigen,
// powersEigen,
// polarz,
// meanDepth
// );
// auto powerErrs = (
// weightedMask * powersEigen
// - (weightedMask * powersEigen).mean()
// ) / (weightedMask * powersEigen).mean();
// auto now{std::chrono::system_clock::now()};
// std::chrono::time_z
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment