API
 
Loading...
Searching...
No Matches
po4ao.hpp
Go to the documentation of this file.
1/** \file po4ao.hpp
2 * \brief The MagAO-X generic ImageStreamIO stream integrator
3 *
4 * \ingroup app_files
5 */
6
7#ifndef po4ao_hpp
8#define po4ao_hpp
9
10#include <NvInfer.h>
11#include <cuda_runtime_api.h>
12#include <iostream>
13#include <fstream>
14#include <vector>
15#include <limits>
16
17#include <mx/improc/eigenCube.hpp>
18#include <mx/improc/eigenImage.hpp>
19
20#include "../../libMagAOX/libMagAOX.hpp" //Note this is included on command line to trigger pch
21#include "../../magaox_git_version.h"
22
23using namespace nvinfer1;
24
25// Logger for TensorRT info/warning/errors
26class Logger : public ILogger {
27 void log(Severity severity, const char* msg) noexcept override {
28 if (severity <= Severity::kWARNING) {
29 std::cout << msg << std::endl;
30 }
31 }
32};
33
34
36 private:
37 size_t num_rows, num_cols; // Dimensions of each image (rows x columns)
38 size_t historySize; // Total number of images the buffer can hold
39 size_t size; // Total number of elements in each image (rows * columns)
40 float* buffer; // Buffer holding the images
41 size_t head; // Index for the next write position
42 size_t tail; // Index for the next read position
43 bool is_full; // Flag to check if buffer is full
44
45 public:
46 CircularBuffer(size_t _num_rows, size_t _num_cols, size_t _historySize)
47 : num_rows(_num_rows), num_cols(_num_cols),
48 historySize(_historySize),
49 size(_num_rows * _num_cols),
50 head(0), tail(0), is_full(false) {
51
52 buffer = new float[size * historySize];
53 }
54
56 delete buffer;
57 }
58
59 // Adds an image (array of floats) to the buffer (overwrites if full)
60 void add(float* image) {
61 //std::cout << "Adding image to buffer" << std::endl;
62 memcpy(&buffer[(head % historySize) * size], image, sizeof(float) * size);
63 //memcpy(buffer + (head % historySize) * size * sizeof(float), image, sizeof(float) * size);
64 head = head + 1;
65 }
66
67
68
69 void add_eigenimage(Eigen::Map<eigenImage<float>> image) {
70 memcpy(buffer + (head % historySize) * size, &image, sizeof(float) * size);
71 //std::cout << "Buffer " << buffer[head] << std::endl;
72 head = head + 1;
73 }
74
75 //void get(float* dest, int index){
76 // if(index < num_elements()){
77 // int data_index = (head - 1 - index) % historySize;
78 // memcpy(dest, buffer[data_index * size], sizeof(float) * size);
79 // }
80 //}
81
82
84 if( head > historySize){
85 return historySize;
86 }else{
87 return head;
88 }
89 }
90 /*
91 void reset_head(){
92 head = 0;
93 }
94 */
95
96 float* getBuffer() {
97 return buffer;
98 }
99
100
101};
102/*
103class CircularBuffer2 {
104 public:
105 CircularBuffer2(size_t Rows, size_t Cols, size_t historySize)
106 : imageRows(Rows), imageCols(Cols),
107 historySize(historySize),
108 size(Rows * Cols),
109 head(0), tail(0), is_full(false) {
110 buffer.resize(historySize, std::vector<float>(size));
111 }
112
113 // Adds an image (array of floats) to the buffer (overwrites if full)
114 void add(float* image) {
115 std::cout << "Adding image" << head % historySize << std::endl;
116 //memcpy(buffer[(head % historySize)], image, sizeof(float) * size)
117 memcpy(buffer[(head % historySize)].data(), image, sizeof(float) * size);
118
119 //for (size_t i = 0; i < imageRows*imageCols; ++i) {
120 std::cout << "Done adding image" << std::endl;
121 // buffer[head][i] = image[i];
122 //}
123 head = (head + 1) % historySize;
124 }
125
126 void add_eigenimage(Eigen::Map<eigenImage<unsigned short>> image) {
127 for (size_t i = 0; i < image.size(); ++i) {
128 buffer[head][i] = image(i); // Cast to float if needed
129 }
130 head = (head + 1) % historySize;
131 }
132
133 void reset_head(){
134 head = 0;
135 }
136
137
138 // Returns the n-th image in the buffer in the order of addition
139 std::vector<float> getItem(size_t n) const {
140 if (n >= head) {
141 std::cout << "Index: " << n << std::endl;
142 std::cout << "Index2: " << head - 1 << std::endl;
143 throw std::runtime_error("Index out of bounds!");
144 return {}; // Return empty vector as error
145 }
146
147 // Calculate the actual index in the buffer
148 //size_t index = (tail + n) % historySize;
149 size_t index = head - n - 1;
150 return buffer[index];
151 }
152
153 const std::vector<float>* getBuffer() const {
154 return buffer.data();
155 }
156
157 private:
158 size_t imageRows, imageCols; // Dimensions of each image (rows x columns)
159 size_t historySize; // Total number of images the buffer can hold
160 size_t size; // Total number of elements in each image (rows * columns)
161 std::vector<std::vector<float>> buffer; // Buffer holding the images
162 size_t head; // Index for the next write position
163 size_t tail; // Index for the next read position
164 bool is_full; // Flag to check if buffer is full
165};
166
167*/
168
169// #define MAGAOX_CURRENT_SHA1 0
170// #define MAGAOX_REPO_MODIFIED 0
171
172namespace MagAOX
173{
174namespace app
175{
176
177class po4ao : public MagAOXApp<true>, public dev::shmimMonitor<po4ao>
178{
179 // Give the test harness access.
180 friend class po4ao_test;
181
182 friend class dev::shmimMonitor<po4ao>;
183
184 // The base shmimMonitor type
186
187 /// Floating point type in which to do all calculations.engine
188 typedef float realT;
189
190 public:
191 /** \name app::dev Configurations
192 *@{reconstructed_buffer
193 */
194
195 ///@}
196
197 protected:
198 /** \name Configurable Parameters
199 *@{
200 */
201 std::string dataDirs; // Location where the data (onnx file, engine, WFS reference) is stored
202 std::string engineName; // Name of the engine
203 std::string engineDirs; // Name of the engine
204
205 Logger logger; // The tensorRT logger
206 std::vector<char> engineData; // for loading the engine file.
207
208 IRuntime* runtime {nullptr};
209 ICudaEngine* engine {nullptr};
213 int inputC {0};
214 int inputH {0};
215 int inputW {0};
216 int inputSize {0};
217 int outputSize {0};
218 int Nact {0};
219 int Nact_across {0};
220 int Nfeatures {0};
221 float max_sigma {0};
222
223 bool reloadEngine {false};
224 bool engineReloaded {false};
225
228
229 float* d_input {nullptr};
230 float* d_output {nullptr};
231 float* integrator_commands {nullptr};
232
233 unsigned long frame_counter{ 0 };
234 unsigned long episode_counter{ 0 };
235
236 uint32_t Nmodes{ 0 }; // Number of modes to reconstruct
237 float *m_output{ nullptr };
238 float *inputState{ nullptr };
239
240 // variables for sending the output to aol_outputs
241 std::string m_outputChannel;
243 uint32_t m_outputWidth {0}; ///< The width of the shmim
244 uint32_t m_outputHeight {0}; ///< The height of the shmim
245 uint8_t m_outputDataType {0}; ///< The ImageStreamIO type code.
246 size_t m_outputTypeSize {0}; ///< The size of the type, in bytes.
247
248 // variables for sending the output to po4ao_observations
249 std::string po4ao_obs_Channel;
251 uint32_t po4ao_obs_Width {0}; ///< The width of the shmim
252 uint32_t po4ao_obs_Height {0}; ///< The height of the shmim
253 uint8_t po4ao_obs_DataType {0}; ///< The ImageStreamIO type code.
254 size_t po4ao_obs_TypeSize {0}; ///< The size of the type, in bytes.
255
256 int Nhist {0};
261
262 std::string po4ao_act_Channel;
263
264
265 bool m_outputOpened {false};
266 bool m_outputRestart {false};
267
268 bool po4ao_obs_Opened {false};
269 bool po4ao_obs_Restart {false};
270
271 pcf::IndiProperty m_indiP_reloadToggle;
273
274 public:
275 /// Default c'tor.
276 po4ao();
277
278 /// D'tor, declared and defined for noexcept.
280 {
281 }
282
283 virtual void setupConfig();
284
285 /// Implementation of loadConfig logic, separated for testing.
286 /** This is called by loadConfig().
287 */
288 int loadConfigImpl(
289 mx::app::appConfigurator &_config /**< [in] an application configuration from which to load values*/ );
290
291 virtual void loadConfig();
292
293 /// Startup function
294 /**
295 *
296 */
297 virtual int appStartup();
298
299 /// Implementation of the FSM for po4ao.
300 /**
301 * \returns 0 on no critical error
302 * \returns -1 on an error requiring shutdown
303 */
304 virtual int appLogic();
305 /// Shutdown the app.
306 /**
307 *
308 */
309 virtual int appShutdown();
310
311 // Custom functions
312 int send_to_shmim();
313 int send_obs_to_shmim();
314
315 void load_engine(const std::string filename);
320 void reload_engine();
321 void switch_engine();
322
323 // void build_engine(){};
324
325 protected:
326 int allocate( const dev::shmimT &dummy /**< [in] tag to differentiate shmimMonitor parents.*/ );
327
328 int processImage( void *curr_src, ///< [in] pointer to start of current frame.
329 const dev::shmimT &dummy ///< [in] tag to differentiate shmimMonitor parents.
330 );
331};
332
333void po4ao::load_engine(const std::string filename) {
334
335 std::ifstream file(filename, std::ios::binary);
336 if (!file) {
337 std::cout << "Error opening " << filename << std::endl;
338 }
339
340 file.seekg(0, std::ios::end);
341
342 engineData = std::vector<char>(file.tellg());
343 file.seekg(0, std::ios::beg);
344 file.read(engineData.data(), engineData.size());
345
346}
347
349
350 // Create the runtime and deserialize the engine
352 if (!runtime) {
353 std::cout << "Failed to createInferRuntime\n";
354 }
355
356 engine = runtime->deserializeCudaEngine(engineData.data(), engineData.size());
357 if (!engine) {
358 std::cout << "Failed to deserialize CUDA engine.\n";
359 } else {
360 std::cout << "Deserialized CUDA engine.\n";
361 }
362
363 context = engine->createExecutionContext();
364
365
366 int numIOTensors = engine->getNbIOTensors();
367 std::cout << "Number of IO Tensors: " << numIOTensors << std::endl;
368
369 auto inputName = engine->getIOTensorName(0);
370 auto outputName = engine->getIOTensorName(1);
371 std::cout << "Tensor IO names: " << inputName << " " << outputName << std::endl;
372
373 const auto inputDims = engine->getTensorShape(inputName);
374 const auto outputDims = engine->getTensorShape(outputName);
375 inputC = inputDims.d[1];
376 inputH = inputDims.d[2];
377 inputW = inputDims.d[3];
379
380 outputSize = outputDims.d[1];
381 std::cout << "Tensor input dimensions: " << inputC << "x" << inputH << "x" << inputW << std::endl;
382 std::cout << "Tensor output dimensions: " << outputSize << std::endl;
383
387
388}
389
391 std::string full_filepath = engineDirs + "/" + engineName;
393
394 engine2 = runtime->deserializeCudaEngine(engineData.data(), engineData.size());
395 if (!engine2) {
396 std::cout << "Failed to deserialize CUDA engine.\n";
397 } else {
398 std::cout << "Deserialized CUDA engine.\n";
399 }
400 context2 = engine2->createExecutionContext();
401 engineReloaded = true;
402}
403
405 std::cout << "Start switching engine" << std::endl;
406 auto temp_engine = engine;
407 auto temp_context = context;
408 engine = engine2;
412 engineReloaded = false;
413 std::cout << "Done switching engine" << std::endl;
414}
415
417
418 // Allocate device memory for input and output
419 cudaMalloc((void**)&d_input, inputSize * sizeof(float));
420 cudaMalloc((void**)&d_output, outputSize * sizeof(float));
421
422}
423
425 if(d_input)
427
428 if(d_output)
430}
431
433 if(context)
434 delete context;
435 if(engine)
436 delete engine;
437 if(runtime)
438 delete runtime;
439 if(context2)
440 delete context2;
441 if(engine2)
442 delete engine2;
443};
444
446{
447 // Check if processImage is running
448 // while(m_dmStream.md[0].write == 1);
449
450 m_outputStream.md[0].write = 1;
452 m_outputStream.md[0].cnt0++;
453 m_outputStream.md[0].write = 0;
454
456
457 return 0;
458}
459
461{
462 // Check if processImage is running
463 // while(m_dmStream.md[0].write == 1);
464
465 po4ao_obs_Stream.md[0].write = 1;
466 //reconstructed_buffer->get(po4ao_obs_Stream.array.raw, 0);
468 po4ao_obs_Stream.md[0].cnt0++;
469 po4ao_obs_Stream.md[0].write = 0;
470
472
473 return 0;
474}
475
476inline po4ao::po4ao() : MagAOXApp( MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED )
477{
478 return;
479}
480
482{
483 std::cout << "setupConfig()" << std::endl;
485
486 config.add( "parameters.dataDirs",
487 "",
488 "parameters.dataDirs",
489 argType::Required,
490 "parameters",
491 "dataDirs",
492 false,
493 "string",
494 "The path to the directory with the onnx model." );
495
496 config.add( "parameters.engineDirs",
497 "",
498 "parameters.engineDirs",
499 argType::Required,
500 "parameters",
501 "engineDirs",
502 false,
503 "string",
504 "The path to the directory with the TRT engine." );
505
506
507 config.add( "parameters.engineName",
508 "",
509 "parameters.engineName",
510 argType::Required,
511 "parameters",
512 "engineName",
513 false,
514 "string",
515 "Name of the TRT engine." );
516
517 config.add( "parameters.channel",
518 "",
519 "parameters.channel",
520 argType::Required,
521 "parameters",
522 "channel",
523 false,
524 "string",
525 "The output channel." );
526
527 config.add( "parameters.observation_channel",
528 "",
529 "parameters.observation_channel",
530 argType::Required,
531 "parameters",
532 "observation_channel",
533 false,
534 "string",
535 "The output channel for the observations." );
536
537 config.add( "parameters.action_channel",
538 "",
539 "parameters.action_channel",
540 argType::Required,
541 "parameters",
542 "action_channel",
543 false,
544 "string",
545 "The output channel for the actions." );
546
547 config.add( "parameters.iterations_per_ep",
548 "",
549 "parameters.iterations_per_ep",
550 argType::Required,
551 "parameters",
552 "iterations_per_ep",
553 false,
554 "int",
555 "Number of iterations per episode." );
556
557 config.add( "parameters.integrator_gain",
558 "",
559 "parameters.integrator_gain",
560 argType::Required,
561 "parameters",
562 "integrator_gain",
563 false,
564 "float",
565 "Gain of the integrator during warmup." );
566
567 config.add( "parameters.warmup_episodes",
568 "",
569 "parameters.warmup_episodes",
570 argType::Required,
571 "parameters",
572 "warmup_episodes",
573 false,
574 "int",
575 "Number of episodes for the warmup." );
576
577 config.add( "parameters.replay_buffer_size",
578 "",
579 "parameters.replay_buffer_size",
580 argType::Required,
581 "parameters",
582 "replay_buffer_size",
583 false,
584 "int",
585 "Number of samples in the real-time buffer." );
586
587 config.add( "parameters.max_sigma",
588 "",
589 "parameters.max_sigma",
590 argType::Required,
591 "parameters",
592 "max_sigma",
593 false,
594 "float",
595 "Standard deviation of the exploration noise." );
596
597 config.add( "parameters.Nhist",
598 "",
599 "parameters.Nhist",
600 argType::Required,
601 "parameters",
602 "Nhist",
603 false,
604 "int",
605 "Number of frames in the history vector." );
606
607 config.add( "parameters.modal_filt_matrix",
608 "",
609 "parameters.modal_filt_matrix",
610 argType::Required,
611 "parameters",
612 "modal_filt_matrix",
613 false,
614 "string",
615 "Name of the model filtering matrix file." );
616
617 config.add( "parameters.reloadEngine",
618 "",
619 "parameters.reloadEngine",
620 argType::Required,
621 "parameters",
622 "reloadEngine",
623 false,
624 "bool",
625 "Whether to reload the engine." );
626
627}
628
629inline int po4ao::loadConfigImpl( mx::app::appConfigurator &_config )
630{
631 std::cout << "loadConfigImpl()" << std::endl;
633
634 _config( dataDirs, "parameters.dataDirs" );
635 _config( engineDirs, "parameters.engineDirs" );
636 _config( engineName, "parameters.engineName" );
637 _config( m_outputChannel, "parameters.channel");
638 _config( po4ao_obs_Channel, "parameters.observation_channel");
639 _config( po4ao_act_Channel, "parameters.observation_channel");
640
641 _config( Nhist, "parameters.Nhist" );
642 _config( iterations_per_ep, "parameters.iterations_per_ep" );
643 _config( warmup_episodes, "parameters.warmup_episodes" );
644 _config( replay_buffer_size, "parameters.replay_buffer_size" );
645 _config( max_sigma, "parameters.max_sigma" );
646 _config( integrator_gain, "parameters.integrator_gain" );
647 _config( reloadEngine, "parameters.reloadEngine" );
648
649 if( true )
650 {
651 std::cout << "Debug configuration loading: " << std::endl;
652 std::cout << "dataDirs: " << dataDirs << std::endl;
653 std::cout << "engineDirs: " << engineDirs << std::endl;
654 std::cout << "engineName: " << engineName << std::endl;
655 std::cout << "output Channel: " << m_outputChannel << std::endl;
656 }
657
658 return 0;
659}
660
661inline void po4ao::loadConfig()
662{
663 loadConfigImpl( config );
664}
665
667{
668 if( shmimMonitorT::appStartup() < 0 )
669 {
670 return log<software_error, -1>( { __FILE__, __LINE__ } );
671 }
674
675 std::string full_filepath = engineDirs + "/" + engineName;
676 std::cout << "file: " << full_filepath << std::endl;
677
681
682 // state(stateCodes::READY);
684 return 0;
685}
686
687inline int po4ao::appLogic()
688{
689 if( shmimMonitorT::appLogic() < 0 )
690 {
691 return log<software_error, -1>( { __FILE__, __LINE__ } );
692 }
693
694 std::unique_lock<std::mutex> lock( m_indiMutex );
695
696 if( shmimMonitorT::updateINDI() < 0 )
697 {
699 }
700
701 if(reloadEngine){
702 updateSwitchIfChanged(m_indiP_reloadToggle, "toggle", pcf::IndiElement::On, INDI_OK);
703 }else{
704 updateSwitchIfChanged(m_indiP_reloadToggle, "toggle", pcf::IndiElement::Off, INDI_IDLE);
705 }
706
707 return 0;
708}
709
711{
713
714 if( inputState )
715 {
716 delete inputState;
717 }
719 {
720 delete integrator_commands;
721 }
722 if ( command_buffer )
723 {
724 delete command_buffer;
725 }
727 {
729 }
730
733
734 return 0;
735}
736
737inline int po4ao::allocate( const dev::shmimT &dummy )
738{
739 std::cout << "allocate()" << std::endl;
740 static_cast<void>( dummy ); // be unused
741
742 inputState = new float[Nfeatures * Nact];
743 memset( inputState, 0, sizeof( float ) * Nfeatures * Nact );
744
745 integrator_commands = new float[Nact];
746 memset( integrator_commands, 0, sizeof( float ) * Nact );
747
748 m_output = new float[Nact];
749 memset( m_output, 0, sizeof( float ) * Nact );
750
753
754 std::cout << "Close shmims" << std::endl;
755 // Allocate the DM shmim interface
756 if(m_outputOpened){
758 }
759
760 std::cout << "Open shmims" << std::endl;
761 m_outputOpened = false;
762 m_outputRestart = false; //Set this up front, since we're about to restart.
763
765 if(m_outputStream.md[0].sem < 10){
767 }else{
768 m_outputOpened = true;
769 }
770 }
771
772 std::cout << "Done!" << std::endl;
773 if(!m_outputOpened){
775 return -1;
776 }else{
777 m_outputWidth = m_outputStream.md->size[0];
778 m_outputHeight = m_outputStream.md->size[1];
779
780 m_outputDataType = m_outputStream.md->datatype;
781 m_outputTypeSize = sizeof(float);
782
783 log<text_log>( "Opened " + m_outputChannel + " " + std::to_string(m_outputWidth) + " x " + std::to_string(m_outputHeight) + " with data type: " + std::to_string(m_outputDataType), logPrio::LOG_NOTICE);
784 }
785
786 // Open PO4AO observation stream
789 }
790
791 po4ao_obs_Opened = false;
792 po4ao_obs_Restart = false; //Set this up front, since we're about to restart.
793
795 if(po4ao_obs_Stream.md[0].sem < 10){
797 }else{
798 po4ao_obs_Opened = true;
799 }
800 }
801
802 if(!po4ao_obs_Opened){
804 return -1;
805 }else{
806 po4ao_obs_Width = po4ao_obs_Stream.md->size[0];
808
810 po4ao_obs_TypeSize = sizeof(float);
811
812 log<text_log>( "Opened " + po4ao_obs_Channel + " " + std::to_string(po4ao_obs_Width) + " x " + std::to_string(po4ao_obs_Height) + " with data type: " + std::to_string(po4ao_obs_DataType), logPrio::LOG_NOTICE);
813 }
814
815
816 return 0;
817}
818
819inline int po4ao::processImage( void *curr_src, const dev::shmimT &dummy )
820{
821 //std::cout << "processImage()" << std::endl;
822 static_cast<void>( dummy ); // be unused
823 Eigen::Map<eigenImage<float>> ReconstructedMap(static_cast<float *>( curr_src ), 1, Nact );
824 //if(false){
826 //reconstructed_buffer->getItem(1);
827 // Assign values to InputState in correct order
829 for( int feat_i =0; feat_i < Nfeatures; ++feat_i)
830 {
831 int ki = 0;
832 for( int col_i = 0; col_i < Nact_across; ++col_i )
833 {
834 for( int row_i = 0; row_i < Nact_across; ++row_i )
835 {
836 inputState[ki + feat_i * Nact] = 0;
837 /*
838 //std::cout << "HELLO:" << reconstructed_buffer->getItem(Nhist - feat_i) << std::endl;
839 //std::cout << "Buffer index: " << Nhist - feat_i << std::endl;
840 //std::cout << "Image index: " << col_i * Nact_across + row_i << std::endl;
841 if (frame_counter > Nhist + 1) {
842 std::cout << Nhist - feat_i << std::endl;
843 std::cout << "Z" << std::endl;
844 if (feat_i < Nhist){
845 std::cout << "A" << std::endl;
846 auto item = reconstructed_buffer->getItem(Nhist - feat_i);
847 std::cout << "B" << std::endl;
848 //This is where the error now is!!!
849 inputState[ki + feat_i * Nact] = item[ki];
850 //inputState[ki + feat_i * Nact] = reconstructed_buffer->getItem(feat_i)[row_i, col_i];
851 }
852 else{
853 std::cout << "C" << std::endl;
854 inputState[ki + feat_i * Nact] = command_buffer->getItem(Nhist - (feat_i - Nhist))[ki];
855 }
856 }nsigned short>> ReconstructedMap(static_cas
857 else {
858 //std::cout << "D" << std::endl;
859 inputState[ki + feat_i * Nact] = 0;
860 }
861 */
862 ++ki;
863 }
864 }
865
866 }
867
868 // Copy input data to device
870
871 // Run inference
872 void* buffers[] = {d_input, d_output};
873 context->executeV2(buffers);
874
875
877
878 }
879 else {
880 // Run with integrator
881 for( int act_i = 0; act_i < Nact; ++act_i ){
883 }
884
886 }
887
888
889 //reconstructed_buffer->add(m_output);
891 std::cout << "Done with episode " << episode_counter << std::endl;
894 }
895
896 if(engineReloaded){
897 switch_engine();
898 }
899 // Send control commands to the correct stream
900 //send_to_shmim();
901
902
904 return 0;
905}
906
907INDI_NEWCALLBACK_DEFN(po4ao, m_indiP_reloadToggle )(const pcf::IndiProperty &ipRecv)
908{
909 if(ipRecv.getName() != m_indiP_reloadToggle.getName())
910 {
911 log<software_error>({__FILE__, __LINE__, "invalid indi property received"});
912 return -1;
913 }
914
915 //switch is toggled to on
916 if( ipRecv["toggle"].getSwitchState() == pcf::IndiElement::On)
917 {
918 std::cout << "Reloading model" << std::endl;
919 log<text_log>("Reloading model", logPrio::LOG_NOTICE);
920 reload_engine();
921 engineReloaded = true;
922 updateSwitchIfChanged(m_indiP_reloadToggle, "toggle", pcf::IndiElement::Off, INDI_BUSY);
923
924 return 0;
925 }
926
927 //switch is toggle to off
928 if( ipRecv["toggle"].getSwitchState() == pcf::IndiElement::Off)
929 {
930 std::cout << "No new model" << std::endl;
931 return 0;
932 }
933
934 return 0;
935}
936
937
938
939} // namespace app
940} // namespace MagAOX
941
942#endif // po4ao_hpp
size_t num_cols
Definition po4ao.hpp:37
CircularBuffer(size_t _num_rows, size_t _num_cols, size_t _historySize)
Definition po4ao.hpp:46
size_t head
Definition po4ao.hpp:41
size_t tail
Definition po4ao.hpp:42
size_t size
Definition po4ao.hpp:39
void add_eigenimage(Eigen::Map< eigenImage< float > > image)
Definition po4ao.hpp:69
size_t historySize
Definition po4ao.hpp:38
int num_elements()
Definition po4ao.hpp:83
float * buffer
Definition po4ao.hpp:40
float * getBuffer()
Definition po4ao.hpp:96
size_t num_rows
Definition po4ao.hpp:37
void add(float *image)
Definition po4ao.hpp:60
void log(Severity severity, const char *msg) noexcept override
Definition po4ao.hpp:27
The base-class for MagAO-X applications.
Definition MagAOXApp.hpp:73
stateCodes::stateCodeT state()
Get the current state code.
int registerIndiPropertyNew(pcf::IndiProperty &prop, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is exposed for others to request a New Property for.
int createStandardIndiToggleSw(pcf::IndiProperty &prop, const std::string &name, const std::string &label="", const std::string &group="")
Create a standard R/W INDI switch with a single toggle element.
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI switch element value if it has changed.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::mutex m_indiMutex
Mutex for locking INDI communications.
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
int updateINDI()
Update the INDI properties for this device controller.
int appLogic()
Checks the shmimMonitor thread.
int appShutdown()
Shuts down the shmimMonitor thread.
int loadConfig(mx::app::appConfigurator &config)
load the configuration system results
std::string engineDirs
Definition po4ao.hpp:203
float realT
Floating point type in which to do all calculations.engine.
Definition po4ao.hpp:188
uint32_t iterations_per_ep
Definition po4ao.hpp:258
float integrator_gain
Definition po4ao.hpp:260
virtual int appStartup()
Startup function.
Definition po4ao.hpp:666
virtual int appShutdown()
Shutdown the app.
Definition po4ao.hpp:710
virtual void setupConfig()
Definition po4ao.hpp:481
void switch_engine()
Definition po4ao.hpp:404
IMAGE po4ao_obs_Stream
Definition po4ao.hpp:250
size_t po4ao_obs_TypeSize
The size of the type, in bytes.
Definition po4ao.hpp:254
float * inputState
Definition po4ao.hpp:238
std::string m_outputChannel
Definition po4ao.hpp:241
IRuntime * runtime
Definition po4ao.hpp:208
uint8_t m_outputDataType
The ImageStreamIO type code.
Definition po4ao.hpp:245
INDI_NEWCALLBACK_DECL(po4ao, m_indiP_reloadToggle)
int allocate(const dev::shmimT &dummy)
Definition po4ao.hpp:737
std::vector< char > engineData
Definition po4ao.hpp:206
float * integrator_commands
Definition po4ao.hpp:231
ICudaEngine * engine2
Definition po4ao.hpp:210
std::string engineName
Definition po4ao.hpp:202
CircularBuffer * reconstructed_buffer
Definition po4ao.hpp:227
CircularBuffer * command_buffer
Definition po4ao.hpp:226
ICudaEngine * engine
Definition po4ao.hpp:209
dev::shmimMonitor< po4ao > shmimMonitorT
Definition po4ao.hpp:185
int send_obs_to_shmim()
Definition po4ao.hpp:460
virtual int appLogic()
Implementation of the FSM for po4ao.
Definition po4ao.hpp:687
uint32_t Nmodes
Definition po4ao.hpp:236
void load_engine(const std::string filename)
Definition po4ao.hpp:333
void cleanup_engine_context()
Definition po4ao.hpp:432
uint32_t po4ao_obs_Height
The height of the shmim.
Definition po4ao.hpp:252
void cleanup_engine_memory()
Definition po4ao.hpp:424
std::string po4ao_act_Channel
Definition po4ao.hpp:262
unsigned long episode_counter
Definition po4ao.hpp:234
void prepare_engine_memory()
Definition po4ao.hpp:416
size_t m_outputTypeSize
The size of the type, in bytes.
Definition po4ao.hpp:246
uint32_t warmup_episodes
Definition po4ao.hpp:259
unsigned long frame_counter
Definition po4ao.hpp:233
IExecutionContext * context
Definition po4ao.hpp:211
po4ao()
Default c'tor.
Definition po4ao.hpp:476
int processImage(void *curr_src, const dev::shmimT &dummy)
Definition po4ao.hpp:819
pcf::IndiProperty m_indiP_reloadToggle
Definition po4ao.hpp:271
uint32_t po4ao_obs_Width
The width of the shmim.
Definition po4ao.hpp:251
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
Definition po4ao.hpp:629
virtual void loadConfig()
Definition po4ao.hpp:661
std::string dataDirs
Definition po4ao.hpp:201
std::string po4ao_obs_Channel
Definition po4ao.hpp:249
IExecutionContext * context2
Definition po4ao.hpp:212
uint8_t po4ao_obs_DataType
The ImageStreamIO type code.
Definition po4ao.hpp:253
uint32_t m_outputHeight
The height of the shmim.
Definition po4ao.hpp:244
friend class po4ao_test
Definition po4ao.hpp:180
~po4ao() noexcept
D'tor, declared and defined for noexcept.
Definition po4ao.hpp:279
void reload_engine()
Definition po4ao.hpp:390
void create_engine_context()
Definition po4ao.hpp:348
uint32_t m_outputWidth
The width of the shmim.
Definition po4ao.hpp:243
#define INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#define INDI_NEWCALLBACK(prop)
Get the name of the static callback wrapper for a new property.
@ OPERATING
The device is operating, other than homing.
#define INDI_IDLE
Definition indiUtils.hpp:27
#define INDI_BUSY
Definition indiUtils.hpp:29
#define INDI_OK
Definition indiUtils.hpp:28
const pcf::IndiProperty & ipRecv
std::unique_lock< std::mutex > lock(m_indiMutex)
Definition dm.hpp:26
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
Software ERR log entry.