From 3f8407d52b302e864315151c60de86c3ca04a28e Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Thu, 30 Jul 2015 12:20:42 +0200 Subject: [PATCH 01/16] LPM initial commit in IRIS. Working comm. with firmware --- CMakeLists.txt | 4 ++++ lib/serial.cc | 2 +- lib/serial.h | 4 ++++ tools/lpm.cc | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/lpm.h | 27 ++++++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tools/lpm.cc create mode 100644 tools/lpm.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 36de6ad..cfb0685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,10 @@ target_link_libraries(iris PUBLIC ${LINK_LIBS}) ####################################### # tools +set(lpm_SOURCES tools/lpm.cc) +add_executable(lpm ${lpm_SOURCES}) +target_link_libraries(lpm iris) + set(pr655_SOURCES tools/pr655.cc) add_executable(pr655 ${pr655_SOURCES}) target_link_libraries(pr655 iris) diff --git a/lib/serial.cc b/lib/serial.cc index f4003ee..153253e 100644 --- a/lib/serial.cc +++ b/lib/serial.cc @@ -149,7 +149,7 @@ std::string serial::recv_line(sleeper::rep read_timeout) { } if (!timeout.maybe_sleep(nread == 0)) { - throw std::runtime_error("w failed: timeout"); + throw std::runtime_error("r failed: timeout"); } } while (ch != '\n'); diff --git a/lib/serial.h b/lib/serial.h index 7e3480a..e962f73 100644 --- a/lib/serial.h +++ b/lib/serial.h @@ -142,6 +142,10 @@ class serial { std::this_thread::sleep_for(dura); } + int printfd() { + return fd; + } + private: int fd; }; diff --git a/tools/lpm.cc b/tools/lpm.cc new file mode 100644 index 0000000..36c80f9 --- /dev/null +++ b/tools/lpm.cc @@ -0,0 +1,61 @@ +#include +#include +#include +#include "lpm.h" + + +int main(int argc, char **argv) { + + std::string device; + char in2put; + std::string input2; + + namespace po = boost::program_options; + + po::options_description opts("LED Pseudo Monochromatic Command Line tool"); + opts.add_options() + ("help", "Some help stuff") + ("device", po::value(&device), "device file for aurdrino") + ("input", po::value(&input2), "send r/g/b"); + + std::stringstream ss; + ss << input2 << "\n"; + input2 = ss.str(); + + std::cout << "setting input2:" << input2 << std::endl; + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); + po::notify(vm); + + if(vm.count("help")) { + std::cout << opts << std::endl; + } else if (vm.count("device")) { + std::cout << "Opening device: " << vm["device"].as() << std::endl; + + device::serial a = device::arduino::open(device); + + std::cout << "val of fd: " << a.printfd() << std::endl; + + std:: cout << "input: " << input2 << std::endl; + + a.send_data(input2); + //write(a.printfd(), &input, 1); + + char output; + int index = 0; + std::cout << "from arduino: "; + + while(1) { + std::string data = a.recv_line(1000); + std::cout << data << std::endl; + + if(data == std::string("*")) { + break; + } + } + } else { + std::cout << "Not Enough Arguments. ./lpm --device --input " << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/tools/lpm.h b/tools/lpm.h new file mode 100644 index 0000000..2c46c8b --- /dev/null +++ b/tools/lpm.h @@ -0,0 +1,27 @@ +#include + + +namespace device { + + class arduino { + + public: + + static device::serial open(const std::string &path) { + return serial::open(path); + } + + void sendToArduino(const std::string &cmd) { + io.send_data(cmd); + } + + void recvFromArduino() { + std::string line = io.recv_line(); + std::cout << line < Date: Thu, 30 Jul 2015 14:21:33 +0200 Subject: [PATCH 02/16] [lpm]: Comm. with TLC5947. Setting pin & PWM or reset all --- tools/lpm.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/lpm.cc b/tools/lpm.cc index 36c80f9..46df7e2 100644 --- a/tools/lpm.cc +++ b/tools/lpm.cc @@ -7,7 +7,6 @@ int main(int argc, char **argv) { std::string device; - char in2put; std::string input2; namespace po = boost::program_options; @@ -18,10 +17,6 @@ int main(int argc, char **argv) { ("device", po::value(&device), "device file for aurdrino") ("input", po::value(&input2), "send r/g/b"); - std::stringstream ss; - ss << input2 << "\n"; - input2 = ss.str(); - std::cout << "setting input2:" << input2 << std::endl; po::variables_map vm; @@ -33,21 +28,24 @@ int main(int argc, char **argv) { } else if (vm.count("device")) { std::cout << "Opening device: " << vm["device"].as() << std::endl; - device::serial a = device::arduino::open(device); + device::serial io = device::arduino::open(device); - std::cout << "val of fd: " << a.printfd() << std::endl; + std::cout << "val of fd: " << io.printfd() << std::endl; std:: cout << "input: " << input2 << std::endl; - a.send_data(input2); + if(input2 == "reset") { + input2 = "-1,-1"; + std::cout << "sending: " << input2 << std::endl; + } + + io.send_data(input2); //write(a.printfd(), &input, 1); - char output; - int index = 0; std::cout << "from arduino: "; while(1) { - std::string data = a.recv_line(1000); + std::string data = io.recv_line(1000); std::cout << data << std::endl; if(data == std::string("*")) { From a51c52afc9087b98f1260a4c51c6dafd366556a8 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Mon, 3 Aug 2015 13:22:05 +0200 Subject: [PATCH 03/16] LPM class with Abstraction for PWM, INFO, RESET commands --- tools/lpm.cc | 55 ++++++++++++++++++++++++++++++---------------------- tools/lpm.h | 53 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 30 deletions(-) diff --git a/tools/lpm.cc b/tools/lpm.cc index 46df7e2..b5a49c4 100644 --- a/tools/lpm.cc +++ b/tools/lpm.cc @@ -1,59 +1,68 @@ #include #include + #include + #include "lpm.h" +// info +// reset +// pwm 10,2000 +// shoot int main(int argc, char **argv) { + namespace po = boost::program_options; std::string device; - std::string input2; - - namespace po = boost::program_options; + std::string input; po::options_description opts("LED Pseudo Monochromatic Command Line tool"); opts.add_options() ("help", "Some help stuff") ("device", po::value(&device), "device file for aurdrino") - ("input", po::value(&input2), "send r/g/b"); - - std::cout << "setting input2:" << input2 << std::endl; + ("input", po::value(&input), "send r/g/b"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); po::notify(vm); if(vm.count("help")) { + //show program options std::cout << opts << std::endl; + } else if (vm.count("device")) { + std::cout << "Opening device: " << vm["device"].as() << std::endl; - device::serial io = device::arduino::open(device); + device::io = device::arduino::open(device); - std::cout << "val of fd: " << io.printfd() << std::endl; + std::cout << "val of fd: " << device::io.printfd() << std::endl; + std::cout << "input: " << input << std::endl; - std:: cout << "input: " << input2 << std::endl; + if(device::lpm::isCommandPWM(input) == 0) { + // handle PWM + device::lpm::setPWM(input); - if(input2 == "reset") { - input2 = "-1,-1"; - std::cout << "sending: " << input2 << std::endl; - } + } else if(device::lpm::isCommandInfo(input) == 0) { + //handle info + device::lpm::getInfo(); + + } else if(device::lpm::isCommandReset(input) == 0) { + //handle reset + device::lpm::reset(); - io.send_data(input2); - //write(a.printfd(), &input, 1); + } else { + std::cout <<"Error: Incorrect command! " << std::endl; + return -1; + } - std::cout << "from arduino: "; + std::cout << "from arduino: " << std::endl; + device::lpm::receiveArduinoOutput(); //print stream from arduino - while(1) { - std::string data = io.recv_line(1000); - std::cout << data << std::endl; - if(data == std::string("*")) { - break; - } - } } else { std::cout << "Not Enough Arguments. ./lpm --device --input " << std::endl; } + return 0; } \ No newline at end of file diff --git a/tools/lpm.h b/tools/lpm.h index 2c46c8b..b02f718 100644 --- a/tools/lpm.h +++ b/tools/lpm.h @@ -3,6 +3,9 @@ namespace device { + + device::serial io; + class arduino { public: @@ -11,17 +14,53 @@ namespace device { return serial::open(path); } - void sendToArduino(const std::string &cmd) { - io.send_data(cmd); + }; + + + class lpm { + + public: + + static void setPWM(std::string cmd) { + device::io.send_data(cmd); } - void recvFromArduino() { - std::string line = io.recv_line(); - std::cout << line < Date: Mon, 3 Aug 2015 16:15:57 +0200 Subject: [PATCH 04/16] Removed Arduino class. Not really required anymore. --- tools/lpm.cc | 18 +++++++++--------- tools/lpm.h | 40 ++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/tools/lpm.cc b/tools/lpm.cc index b5a49c4..b78815e 100644 --- a/tools/lpm.cc +++ b/tools/lpm.cc @@ -34,22 +34,22 @@ int main(int argc, char **argv) { std::cout << "Opening device: " << vm["device"].as() << std::endl; - device::io = device::arduino::open(device); + device::lpm lpm = device::lpm::open(device); - std::cout << "val of fd: " << device::io.printfd() << std::endl; + std::cout << "val of fd: " << lpm.io.printfd() << std::endl; std::cout << "input: " << input << std::endl; - if(device::lpm::isCommandPWM(input) == 0) { + if(lpm.isCommandPWM(input) == 0) { // handle PWM - device::lpm::setPWM(input); + lpm.setPWM(input); - } else if(device::lpm::isCommandInfo(input) == 0) { + } else if(lpm.isCommandInfo(input) == 0) { //handle info - device::lpm::getInfo(); + lpm.getInfo(); - } else if(device::lpm::isCommandReset(input) == 0) { + } else if(lpm.isCommandReset(input) == 0) { //handle reset - device::lpm::reset(); + lpm.reset(); } else { std::cout <<"Error: Incorrect command! " << std::endl; @@ -57,7 +57,7 @@ int main(int argc, char **argv) { } std::cout << "from arduino: " << std::endl; - device::lpm::receiveArduinoOutput(); //print stream from arduino + lpm.receiveArduinoOutput(); //print stream from arduino } else { diff --git a/tools/lpm.h b/tools/lpm.h index b02f718..2ad8bdd 100644 --- a/tools/lpm.h +++ b/tools/lpm.h @@ -4,54 +4,50 @@ namespace device { - device::serial io; - - class arduino { + class lpm { public: - static device::serial open(const std::string &path) { - return serial::open(path); - } - - }; + device::serial io; + lpm(const device::serial &io) : io(io) { } - class lpm { - - public: + static lpm open(const std::string &path) { + lpm lpm(serial::open(path)); + return lpm; + } - static void setPWM(std::string cmd) { - device::io.send_data(cmd); + void setPWM(std::string cmd) { + io.send_data(cmd); } - static void getInfo() { - device::io.send_data("info"); + void getInfo() { + io.send_data("info"); } - static void reset() { - device::io.send_data("reset"); + void reset() { + io.send_data("reset"); } - static int isCommandPWM(std::string cmd) { + int isCommandPWM(std::string cmd) { std::string pwmCmd = "pwm"; return cmd.compare(0, pwmCmd.length(), pwmCmd); } - static int isCommandInfo(std::string cmd) { + int isCommandInfo(std::string cmd) { std::string infoCmd = "info"; return cmd.compare(0, infoCmd.length(), infoCmd); } - static int isCommandReset(std::string cmd) { + int isCommandReset(std::string cmd) { std::string resetCmd = "reset"; return cmd.compare(0, resetCmd.length(), resetCmd); } - static void receiveArduinoOutput() { + void receiveArduinoOutput() { while(1) { - std::string data = device::io.recv_line(1000); + std::string data = io.recv_line(1000); std::cout << data << std::endl; if(data == std::string("*")) { From bcce013ccd4ca86607d952f0c6733832c26c0785 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Tue, 4 Aug 2015 11:35:37 +0200 Subject: [PATCH 05/16] LPM: LED PIN & Wavelength std::map from YAML File --- lib/data.cc | 28 ++++++++++++++++++++++++++++ lib/data.h | 6 ++++-- tools/lpm.cc | 4 ++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/data.cc b/lib/data.cc index 83a1ce5..a509b57 100644 --- a/lib/data.cc +++ b/lib/data.cc @@ -276,6 +276,34 @@ display store::make_display(const monitor &monitor, return dsp; } +std::map store::lpm_leds() const { + + std::map lpm_led_map; + + fs::file valuesFile = base.child("lpm/leds"); + std::string data = valuesFile.read_all(); + YAML::Node root = YAML::Load(data); + + YAML::Node led_node = root["leds"]; + + for(YAML::const_iterator it = led_node.begin(); it != led_node.end(); it++) { + std::string pin_no = it->first.as(); + std::string led_wavelength = it->second.as(); + + uint8_t pin_int = std::stoi(pin_no); + uint16_t pwm_val_int = std::stoi(led_wavelength); + + lpm_led_map.insert( std::pair(pin_int, pwm_val_int) ); + } + + std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; + + for(auto elem : lpm_led_map) { + std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "\n"; + } + + return lpm_led_map; +} // yaml stuff diff --git a/lib/data.h b/lib/data.h index 7696d0c..15c6d27 100644 --- a/lib/data.h +++ b/lib/data.h @@ -8,7 +8,7 @@ #include #include #include - +#include namespace iris { namespace data { @@ -123,7 +123,6 @@ struct isoslant : entity { std::string rgb2lms; }; - /// /* store dir layout: @@ -165,6 +164,9 @@ class store { // cone fundamentals for calibration fs::file cone_fundamentals(size_t spacing = 4) const; + // the led mapping for the led pseudo monochroma//tor + std::map lpm_leds() const; + // yaml config IO static monitor yaml2monitor(const std::string &data); diff --git a/tools/lpm.cc b/tools/lpm.cc index b78815e..064514c 100644 --- a/tools/lpm.cc +++ b/tools/lpm.cc @@ -2,6 +2,7 @@ #include #include +#include #include "lpm.h" @@ -32,6 +33,9 @@ int main(int argc, char **argv) { } else if (vm.count("device")) { +// iris::data::store store = iris::data::store::default_store(); +// store.lpm_leds(); + std::cout << "Opening device: " << vm["device"].as() << std::endl; device::lpm lpm = device::lpm::open(device); From 84a246f7f9d97ca17d544615925de1a26a03a948 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Wed, 5 Aug 2015 17:46:35 +0200 Subject: [PATCH 06/16] Added iris-LEDPhotoSpectrum. Automates led,picture and spectrum capture --- CMakeLists.txt | 6 ++- tools/LEDPhotoSpectrum.cc | 78 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tools/LEDPhotoSpectrum.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index cfb0685..9daeb78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ file(GLOB_RECURSE lib_INCLUDES lib/*.h lib/*.hpp) add_definitions(-DHAVE_IRIS) add_library(iris SHARED ${lib_INCLUDES} ${lib_SOURCES}) -target_link_libraries(iris PUBLIC ${LINK_LIBS}) +target_link_libraries(iris PUBLIC ${LINK_LIBS} -lboost_system -lboost_thread) ####################################### # tools @@ -104,6 +104,10 @@ set(lpm_SOURCES tools/lpm.cc) add_executable(lpm ${lpm_SOURCES}) target_link_libraries(lpm iris) +set(LEDPhotoSpectrum_SOURCES tools/LEDPhotoSpectrum.cc) +add_executable(iris-LEDPhotoSpectrum ${LEDPhotoSpectrum_SOURCES}) +target_link_libraries(iris-LEDPhotoSpectrum iris) + set(pr655_SOURCES tools/pr655.cc) add_executable(pr655 ${pr655_SOURCES}) target_link_libraries(pr655 iris) diff --git a/tools/LEDPhotoSpectrum.cc b/tools/LEDPhotoSpectrum.cc new file mode 100644 index 0000000..f6f6b22 --- /dev/null +++ b/tools/LEDPhotoSpectrum.cc @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +int commandHelper(std::string const& cmd) { + return system(cmd.c_str()); +} + +int main(int argc, char **argv) { + + namespace po = boost::program_options; + + std::string arduinoDevFile; + std::string pr655DevFile; + std::string input; + + po::options_description opts("IRIS LED Photo Spectrum Tool"); + opts.add_options() + ("help", "Some help stuff") + ("arduino", po::value(&arduinoDevFile), "Device file for Aurdrino") + ("pr655", po::value(&pr655DevFile), "Device file for pr655 Spectrometer") + ("input", po::value(&input), "send ,"); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); + po::notify(vm); + + if(vm.count("help")) { + std::cout << opts << std::endl; + return 0; + + } else if(vm.count("arduino") && vm.count("pr655") && vm.count("input")) { + + std::cout << "Hello IRIS: " << std::endl; + std::cout << "main waiting for threads" << std::endl; + + /* + * Turn on LED + */ + std::string cmd = ""; + cmd = "./lpm --device " + arduinoDevFile + " --input \"pwm " + input + "\"" ; + boost::thread lpmThread(commandHelper, cmd); + sleep(1); + lpmThread.join(); + + /* + * Take the picture (change command after implementing iris camera) + */ + cmd = "./lpm --device " + arduinoDevFile + " --input \"pwm " + "5,4096" + "\"" ; + boost::thread photographThread(commandHelper, cmd); + sleep(1); + photographThread.join(); + + /* + * Take the Spectrum (change command for pr655) + */ + cmd = "./lpm --device " + arduinoDevFile + " --input \"pwm " + "1,4096" + "\"" ; + boost::thread pr655Thread(commandHelper, cmd); + sleep(1); + pr655Thread.join(); + + /* + * Reset the LED + */ + cmd = "./lpm --device " + arduinoDevFile + " --input \"reset" + "\"" ; + boost::thread lpmResetThread(commandHelper, cmd); + sleep(1); + lpmResetThread.join(); + + std::cout << "All Threads returned -- Main done" << std::endl; + + } else { + std::cout << "Not Enough Arguments. call --help for help" << std::endl; + } + + return 0; +} \ No newline at end of file From a91421310c3de697f51f79d5f2b91b50ae56839c Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Thu, 6 Aug 2015 16:10:55 +0200 Subject: [PATCH 07/16] Removed Boost thread; not required for IRIS-LED+Photo_Spectrum --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9daeb78..9d4bfbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ file(GLOB_RECURSE lib_INCLUDES lib/*.h lib/*.hpp) add_definitions(-DHAVE_IRIS) add_library(iris SHARED ${lib_INCLUDES} ${lib_SOURCES}) -target_link_libraries(iris PUBLIC ${LINK_LIBS} -lboost_system -lboost_thread) +target_link_libraries(iris PUBLIC ${LINK_LIBS}) ####################################### # tools From 4fec23282c04becc9f497a8cdefb7aba6fbf3e69 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Thu, 6 Aug 2015 16:11:31 +0200 Subject: [PATCH 08/16] Moved lpm.h to /lib from /tools --- {tools => lib}/lpm.h | 9 +++++++++ 1 file changed, 9 insertions(+) rename {tools => lib}/lpm.h (84%) diff --git a/tools/lpm.h b/lib/lpm.h similarity index 84% rename from tools/lpm.h rename to lib/lpm.h index 2ad8bdd..fda1711 100644 --- a/tools/lpm.h +++ b/lib/lpm.h @@ -29,6 +29,10 @@ namespace device { io.send_data("reset"); } + void shoot() { + io.send_data("shoot"); + } + int isCommandPWM(std::string cmd) { std::string pwmCmd = "pwm"; return cmd.compare(0, pwmCmd.length(), pwmCmd); @@ -44,6 +48,11 @@ namespace device { return cmd.compare(0, resetCmd.length(), resetCmd); } + int isCommandShoot(std::string cmd) { + std::string shootCmd = "shoot"; + return cmd.compare(0, shootCmd.length(), shootCmd); + } + void receiveArduinoOutput() { while(1) { From 60bcf8a6e2bef830e483cd17e9952bae66cd8009 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Thu, 6 Aug 2015 16:11:58 +0200 Subject: [PATCH 09/16] Fixed lpm.h resolving --- tools/lpm.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/lpm.cc b/tools/lpm.cc index 064514c..f1f8199 100644 --- a/tools/lpm.cc +++ b/tools/lpm.cc @@ -4,7 +4,7 @@ #include #include -#include "lpm.h" +#include // info // reset @@ -33,9 +33,6 @@ int main(int argc, char **argv) { } else if (vm.count("device")) { -// iris::data::store store = iris::data::store::default_store(); -// store.lpm_leds(); - std::cout << "Opening device: " << vm["device"].as() << std::endl; device::lpm lpm = device::lpm::open(device); @@ -55,6 +52,10 @@ int main(int argc, char **argv) { //handle reset lpm.reset(); + } else if(lpm.isCommandShoot(input) == 0) { + //handle shoot img + lpm.shoot(); + } else { std::cout <<"Error: Incorrect command! " << std::endl; return -1; From 3c7b7388a460203415f3e478698ef00989471ca8 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Thu, 6 Aug 2015 16:21:42 +0200 Subject: [PATCH 10/16] LED_Photo_Spectrum: For all available LEDs - Automated turn on LED, Take picture, Measure Spectrum, Reset;Removed boost threads; No more System call --- lib/data.cc | 3 +- tools/LEDPhotoSpectrum.cc | 106 ++++++++++++++++++++++++-------------- 2 files changed, 70 insertions(+), 39 deletions(-) diff --git a/lib/data.cc b/lib/data.cc index a509b57..719fa53 100644 --- a/lib/data.cc +++ b/lib/data.cc @@ -296,12 +296,13 @@ std::map store::lpm_leds() const { lpm_led_map.insert( std::pair(pin_int, pwm_val_int) ); } + /* std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; for(auto elem : lpm_led_map) { std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "\n"; } - + */ return lpm_led_map; } diff --git a/tools/LEDPhotoSpectrum.cc b/tools/LEDPhotoSpectrum.cc index f6f6b22..d4cb5b9 100644 --- a/tools/LEDPhotoSpectrum.cc +++ b/tools/LEDPhotoSpectrum.cc @@ -1,11 +1,10 @@ #include #include -#include #include +#include -int commandHelper(std::string const& cmd) { - return system(cmd.c_str()); -} +#include +#include int main(int argc, char **argv) { @@ -30,45 +29,76 @@ int main(int argc, char **argv) { std::cout << opts << std::endl; return 0; - } else if(vm.count("arduino") && vm.count("pr655") && vm.count("input")) { + } else if(vm.count("arduino") && vm.count("pr655")) { - std::cout << "Hello IRIS: " << std::endl; - std::cout << "main waiting for threads" << std::endl; + std::cout << "Opening Arduino Device File" << std::endl; + device::lpm lpm = device::lpm::open(arduinoDevFile); //connect to arduino - /* - * Turn on LED - */ - std::string cmd = ""; - cmd = "./lpm --device " + arduinoDevFile + " --input \"pwm " + input + "\"" ; - boost::thread lpmThread(commandHelper, cmd); - sleep(1); - lpmThread.join(); - - /* - * Take the picture (change command after implementing iris camera) - */ - cmd = "./lpm --device " + arduinoDevFile + " --input \"pwm " + "5,4096" + "\"" ; - boost::thread photographThread(commandHelper, cmd); - sleep(1); - photographThread.join(); + std::cout << "Opening pr655 Device File" << std::endl; + //device::pr655 meter = device::pr655::open(pr655DevFile); //connect to pr655 /* - * Take the Spectrum (change command for pr655) + * build the map from YAML Config file */ - cmd = "./lpm --device " + arduinoDevFile + " --input \"pwm " + "1,4096" + "\"" ; - boost::thread pr655Thread(commandHelper, cmd); - sleep(1); - pr655Thread.join(); - - /* - * Reset the LED - */ - cmd = "./lpm --device " + arduinoDevFile + " --input \"reset" + "\"" ; - boost::thread lpmResetThread(commandHelper, cmd); - sleep(1); - lpmResetThread.join(); - - std::cout << "All Threads returned -- Main done" << std::endl; + iris::data::store store = iris::data::store::default_store(); + const std::map ledMap = store.lpm_leds(); + + std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; + for(auto elem : ledMap) { + std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "nm \n"; + } + + std::cout << std::endl << "Starting Process for all available LEDs..." << std::endl << std::endl; + + for(auto elem : ledMap) { + + std::cout << "$: Turning on " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << std::endl; + std::string pwmCmd = "pwm " + std::to_string(unsigned(elem.first)) + ",4096"; + + /* + * Turn on LED + */ + lpm.setPWM(pwmCmd); + std::cout << "---------------------------------------" << std::endl; + std::cout << "From arduino after turning LED on: " << std::endl; + lpm.receiveArduinoOutput(); //print stream from arduino + std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + /* + * Time delay of 1 sec + */ + usleep(1000000); + + /* + * Take the picture + */ + std::cout << "$: Capturing Photograph from Camera" << std::endl; + lpm.shoot(); + std::cout << "---------------------------------------" << std::endl; + std::cout << "From arduino after taking picture " << std::endl; + lpm.receiveArduinoOutput(); //print stream from arduino + std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + + /* + * Measure the Spectrum + */ + std::cout << "$: Measuring the spectrum" << std::endl; + // pr655.measure + + /* + * Reset the LED + */ + std::cout << "$: Resetting the LED" << std::endl; + lpm.reset(); + std::cout << "---------------------------------------" << std::endl; + std::cout << "From arduino after resetting" << std::endl; + lpm.receiveArduinoOutput(); //print stream from arduino + std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + + /* + * Time delay of 1 sec + */ + usleep(1000000); + } } else { std::cout << "Not Enough Arguments. call --help for help" << std::endl; From 8aacd3096374862fef945942f77d1eb7b53d1c03 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Mon, 10 Aug 2015 18:10:45 +0200 Subject: [PATCH 11/16] [LED-PhotoSpectrum] Dump file for measured Spectrums --- tools/LEDPhotoSpectrum.cc | 55 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/tools/LEDPhotoSpectrum.cc b/tools/LEDPhotoSpectrum.cc index d4cb5b9..83557e5 100644 --- a/tools/LEDPhotoSpectrum.cc +++ b/tools/LEDPhotoSpectrum.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -35,7 +36,7 @@ int main(int argc, char **argv) { device::lpm lpm = device::lpm::open(arduinoDevFile); //connect to arduino std::cout << "Opening pr655 Device File" << std::endl; - //device::pr655 meter = device::pr655::open(pr655DevFile); //connect to pr655 + device::pr655 meter = device::pr655::open(pr655DevFile); //connect to pr655 /* * build the map from YAML Config file @@ -50,6 +51,8 @@ int main(int argc, char **argv) { std::cout << std::endl << "Starting Process for all available LEDs..." << std::endl << std::endl; + std::map spectrumData; + for(auto elem : ledMap) { std::cout << "$: Turning on " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << std::endl; @@ -82,7 +85,27 @@ int main(int argc, char **argv) { * Measure the Spectrum */ std::cout << "$: Measuring the spectrum" << std::endl; - // pr655.measure + + std::string prefix = "# "; + try { + bool could_start = meter.start(); + if (! could_start) { + std::cerr << "Could not start remote mode" << std::endl; + meter.stop(); + return -1; + } + + meter.units(true); + meter.measure(); + device::pr655::cfg config = meter.config(); + spectral_data data = meter.spectral(); + spectrumData.insert( std::pair(elem.second, data) ); + + } catch (const std::exception &e) { + std::cerr << e.what() << std::endl; + } + + meter.stop(); /* * Reset the LED @@ -100,6 +123,34 @@ int main(int argc, char **argv) { usleep(1000000); } + + std::ofstream fout("spectral.txt"); + + fout << "xx,"; + + for(auto elem : spectrumData) { + spectral_data temp = elem.second; + + for (size_t i = 0; i < temp.data.size(); i++) { + fout << temp.wl_start + i * temp.wl_step << ","; + } + break; + } + + fout << std::endl; + + for(auto elem : spectrumData) { + fout << unsigned(elem.first) << ","; + spectral_data temp = elem.second; + + for (size_t i = 0; i < temp.data.size(); i++) { + fout << temp.data[i] << ","; + } + + fout << std::endl; + + } + } else { std::cout << "Not Enough Arguments. call --help for help" << std::endl; } From 500652a52a131e43e9a68f61c0f996f7568b1fe3 Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Tue, 11 Aug 2015 19:05:09 +0200 Subject: [PATCH 12/16] [LPM] New LED PWM Thresholder and lpm_pwm() function --- CMakeLists.txt | 4 + lib/data.cc | 32 +++++- lib/data.h | 3 + tools/LEDPhotoSpectrum.cc | 8 +- tools/thresholder.cc | 209 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 252 insertions(+), 4 deletions(-) create mode 100644 tools/thresholder.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d4bfbe..8213765 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,10 @@ set(LEDPhotoSpectrum_SOURCES tools/LEDPhotoSpectrum.cc) add_executable(iris-LEDPhotoSpectrum ${LEDPhotoSpectrum_SOURCES}) target_link_libraries(iris-LEDPhotoSpectrum iris) +set(lpmThresholder_SOURCES tools/thresholder.cc) +add_executable(iris-lpmThresholder ${lpmThresholder_SOURCES}) +target_link_libraries(iris-lpmThresholder iris) + set(pr655_SOURCES tools/pr655.cc) add_executable(pr655 ${pr655_SOURCES}) target_link_libraries(pr655 iris) diff --git a/lib/data.cc b/lib/data.cc index 719fa53..ae9eae2 100644 --- a/lib/data.cc +++ b/lib/data.cc @@ -280,7 +280,7 @@ std::map store::lpm_leds() const { std::map lpm_led_map; - fs::file valuesFile = base.child("lpm/leds"); + fs::file valuesFile = base.child("lpm/pwmLed"); std::string data = valuesFile.read_all(); YAML::Node root = YAML::Load(data); @@ -306,6 +306,36 @@ std::map store::lpm_leds() const { return lpm_led_map; } + std::map store::lpm_pwm() const { + + std::maplpm_led_map; + + fs::file valuesFile = base.child("lpm/pwm"); + std::string data = valuesFile.read_all(); + YAML::Node root = YAML::Load(data); + + YAML::Node led_node = root["pwm"]; + + for(YAML::const_iterator it = led_node.begin(); it != led_node.end(); it++) { + std::string wavelength = it->first.as(); + std::string led_pwm = it->second.as(); + + uint16_t wavelength_int = std::stoi(wavelength); + uint16_t led_pwm_int = std::stoi(led_pwm); + + lpm_led_map.insert( std::pair(wavelength_int, led_pwm_int) ); + } + + /* + std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; + + for(auto elem : lpm_led_map) { + std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "\n"; + } + */ + return lpm_led_map; + } + // yaml stuff diff --git a/lib/data.h b/lib/data.h index 15c6d27..f2ee31d 100644 --- a/lib/data.h +++ b/lib/data.h @@ -167,6 +167,9 @@ class store { // the led mapping for the led pseudo monochroma//tor std::map lpm_leds() const; + // the pwm mapping for the led pseudo monochroma//tor + std::map lpm_pwm() const; + // yaml config IO static monitor yaml2monitor(const std::string &data); diff --git a/tools/LEDPhotoSpectrum.cc b/tools/LEDPhotoSpectrum.cc index 83557e5..ab04557 100644 --- a/tools/LEDPhotoSpectrum.cc +++ b/tools/LEDPhotoSpectrum.cc @@ -44,6 +44,8 @@ int main(int argc, char **argv) { iris::data::store store = iris::data::store::default_store(); const std::map ledMap = store.lpm_leds(); + const std::map ledPwmMap = store.lpm_pwm(); + std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; for(auto elem : ledMap) { std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "nm \n"; @@ -55,8 +57,8 @@ int main(int argc, char **argv) { for(auto elem : ledMap) { - std::cout << "$: Turning on " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << std::endl; - std::string pwmCmd = "pwm " + std::to_string(unsigned(elem.first)) + ",4096"; + std::cout << "$: Turning on " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) < +#include +#include +#include +#include +#include + +#include +#include + +int main(int argc, char **argv) { + + namespace po = boost::program_options; + + std::string arduinoDevFile; + std::string pr655DevFile; + std::string input; + + po::options_description opts("IRIS LED Photo Spectrum Tool"); + opts.add_options() + ("help", "Some help stuff") + ("arduino", po::value(&arduinoDevFile), "Device file for Aurdrino") + ("pr655", po::value(&pr655DevFile), "Device file for pr655 Spectrometer") + ("input", po::value(&input), "send ,"); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); + po::notify(vm); + + if(vm.count("help")) { + std::cout << opts << std::endl; + return 0; + + } else if(vm.count("arduino") && vm.count("pr655")) { + + std::cout << "Opening Arduino Device File" << std::endl; + device::lpm lpm = device::lpm::open(arduinoDevFile); //connect to arduino + + std::cout << "Opening pr655 Device File" << std::endl; + device::pr655 meter = device::pr655::open(pr655DevFile); //connect to pr655 + + /* + * build the map from YAML Config file + */ + iris::data::store store = iris::data::store::default_store(); + const std::map ledMap = store.lpm_leds(); + + std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; + for(auto elem : ledMap) { + std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "nm \n"; + } + + std::cout << std::endl << "Starting Process for all available LEDs..." << std::endl << std::endl; + + std::map spectrumData; + + std::map led_pin_pwm; + + float threshold = 0.000025; + bool thresholdFlag = false; + + int pwmDecrementStepSize = 500; + uint16_t previousPWMVal = 4096; //initially 4096 + + while(!thresholdFlag) { + + for(auto elem : ledMap) { + + std::cout << "$: Turning on " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << std::endl; + + bool currentLedThresholdFlag = false; + + while(!currentLedThresholdFlag) { + + std::string pwmCmd = "pwm " + std::to_string(unsigned(elem.first)) + "," + std::to_string(previousPWMVal) + ""; + + std::cout << "executing: " << pwmCmd << std::endl; + + /* + * Turn on LED + */ + lpm.setPWM(pwmCmd); + std::cout << "---------------------------------------" << std::endl; + std::cout << "From arduino after turning LED on: " << std::endl; + lpm.receiveArduinoOutput(); //print stream from arduino + std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + + /* + * Time delay of 1 sec + */ + usleep(1000000); + + /* + * Measure the Spectrum + */ + std::cout << "$: Measuring the spectrum" << std::endl; + + std::string prefix = "# "; + try { + bool could_start = meter.start(); + if (! could_start) { + std::cerr << "Could not start remote mode" << std::endl; + meter.stop(); + return -1; + } + + meter.units(true); + meter.measure(); + device::pr655::cfg config = meter.config(); + spectral_data data = meter.spectral(); + + std::cout << "1" << std::endl; + + std::vector spectraValues; + + std::cout << "2" << std::endl; + + for (size_t i = 0; i < data.data.size(); i++) { + std::vector::iterator it = spectraValues.begin(); + spectraValues.insert(it, data.data[i]); + } + + std::cout << "3" << std::endl; + + float maxima = *std::max_element(spectraValues.begin(), spectraValues.end()); + std::cout << "Peak at: " << maxima << std::endl; + float diff = fabs(maxima - threshold); + std::cout << "Difference in Threshold and Peak: " << diff << std::endl; + + if( diff < 0.000005 || previousPWMVal < 1000) { // it's ok now + currentLedThresholdFlag = true; + led_pin_pwm.insert(std::pair(elem.second, previousPWMVal)); + spectrumData.insert( std::pair(elem.second, data) ); + previousPWMVal = 4096; + } else { + previousPWMVal = previousPWMVal - pwmDecrementStepSize; + } + spectrumData.insert( std::pair(elem.second, data) ); + + } catch (const std::exception &e) { + std::cerr << e.what() << std::endl; + } + + meter.stop(); + } + + /* + * Reset the LED + */ + std::cout << "$: Resetting the LED" << std::endl; + lpm.reset(); + std::cout << "---------------------------------------" << std::endl; + std::cout << "From arduino after resetting" << std::endl; + lpm.receiveArduinoOutput(); //print stream from arduino + std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + + /* + * Time delay of 1 sec + */ + usleep(1000000); + + } + + thresholdFlag = true; //all pwm values are good now + } + + + std::ofstream pwmout("data/pwm.txt"); + + pwmout << "pwm:" << std::endl; + + for(auto elem : led_pin_pwm) { + pwmout << " " << unsigned(elem.first) << " : " << unsigned(elem.second) << std::endl; + } + pwmout.close(); + + std::ofstream fout("spectral.txt"); + + fout << "xx,"; + + for(auto elem : spectrumData) { + spectral_data temp = elem.second; + + for (size_t i = 0; i < temp.data.size(); i++) { + fout << temp.wl_start + i * temp.wl_step << ","; + } + break; + } + + fout << std::endl; + + for(auto elem : spectrumData) { + fout << unsigned(elem.first) << ","; + spectral_data temp = elem.second; + + for (size_t i = 0; i < temp.data.size(); i++) { + fout << temp.data[i] << ","; + } + + fout << std::endl; + + } + + } else { + std::cout << "Not Enough Arguments. call --help for help" << std::endl; + } + + return 0; +} \ No newline at end of file From 74145956514854fd399f4d2334c65651f1149fbe Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Wed, 12 Aug 2015 17:57:17 +0200 Subject: [PATCH 13/16] [LEDPhotoSpectrum] Bug fix - check if spectrum measured or not; comma remove after last entry in file --- tools/LEDPhotoSpectrum.cc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tools/LEDPhotoSpectrum.cc b/tools/LEDPhotoSpectrum.cc index ab04557..8c1855d 100644 --- a/tools/LEDPhotoSpectrum.cc +++ b/tools/LEDPhotoSpectrum.cc @@ -3,7 +3,6 @@ #include #include #include - #include #include @@ -55,6 +54,8 @@ int main(int argc, char **argv) { std::map spectrumData; + std::ofstream errorOut("data/error.txt"); + for(auto elem : ledMap) { std::cout << "$: Turning on " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) <(elem.second, data) ); + if(could_measure) { + spectrumData.insert( std::pair(elem.second, data) ); + } else { + std::cout << ">>: Unable to measure spectrum of " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) <>: Unable to measure spectrum of " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) < Date: Thu, 13 Aug 2015 15:25:15 +0200 Subject: [PATCH 14/16] [LEDPhotoSpectrum] --c and --s flags added to skip camera capture or spectrum measurement --- tools/LEDPhotoSpectrum.cc | 175 ++++++++++++++++++++++++-------------- tools/lpm.cc | 2 +- 2 files changed, 110 insertions(+), 67 deletions(-) diff --git a/tools/LEDPhotoSpectrum.cc b/tools/LEDPhotoSpectrum.cc index 8c1855d..d6048dc 100644 --- a/tools/LEDPhotoSpectrum.cc +++ b/tools/LEDPhotoSpectrum.cc @@ -12,30 +12,51 @@ int main(int argc, char **argv) { std::string arduinoDevFile; std::string pr655DevFile; - std::string input; + + bool pictureFlag = true; + bool spectrumFlag = true; + + device::pr655 meter; po::options_description opts("IRIS LED Photo Spectrum Tool"); opts.add_options() - ("help", "Some help stuff") + ("help", "Supported Arguments/Flags") ("arduino", po::value(&arduinoDevFile), "Device file for Aurdrino") ("pr655", po::value(&pr655DevFile), "Device file for pr655 Spectrometer") - ("input", po::value(&input), "send ,"); + ("c", "Specify this flag to skip capturing of photographs from camera") + ("s", "Specify this flag to skip measurement of spectrometer"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); po::notify(vm); + if(vm.count("c")) { + pictureFlag = false; + } + + if(vm.count("s")) { + spectrumFlag = false; + } + if(vm.count("help")) { std::cout << opts << std::endl; return 0; - } else if(vm.count("arduino") && vm.count("pr655")) { + } else if(vm.count("arduino")) { std::cout << "Opening Arduino Device File" << std::endl; device::lpm lpm = device::lpm::open(arduinoDevFile); //connect to arduino - std::cout << "Opening pr655 Device File" << std::endl; - device::pr655 meter = device::pr655::open(pr655DevFile); //connect to pr655 + if(spectrumFlag) { + + if(vm.count("pr655")) { + std::cout << "Opening pr655 Device File" << std::endl; + meter = device::pr655::open(pr655DevFile); //connect to pr655 + } else { + std::cout << "Error: Specify pr655 device file" << std::endl; + return -1; + } + } /* * build the map from YAML Config file @@ -43,6 +64,9 @@ int main(int argc, char **argv) { iris::data::store store = iris::data::store::default_store(); const std::map ledMap = store.lpm_leds(); + /* + * build the map from YAML Config file + */ const std::map ledPwmMap = store.lpm_pwm(); std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; @@ -53,7 +77,6 @@ int main(int argc, char **argv) { std::cout << std::endl << "Starting Process for all available LEDs..." << std::endl << std::endl; std::map spectrumData; - std::ofstream errorOut("data/error.txt"); for(auto elem : ledMap) { @@ -69,51 +92,69 @@ int main(int argc, char **argv) { std::cout << "From arduino after turning LED on: " << std::endl; lpm.receiveArduinoOutput(); //print stream from arduino std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + /* * Time delay of 1 sec */ usleep(1000000); - /* - * Take the picture - */ - std::cout << "$: Capturing Photograph from Camera" << std::endl; - lpm.shoot(); - std::cout << "---------------------------------------" << std::endl; - std::cout << "From arduino after taking picture " << std::endl; - lpm.receiveArduinoOutput(); //print stream from arduino - std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + if(pictureFlag) { + + /* + * Take the picture + */ + std::cout << "$: Capturing Photograph from Camera" << std::endl; + lpm.shoot(); + std::cout << "---------------------------------------" << std::endl; + std::cout << "From arduino after taking picture " << std::endl; + lpm.receiveArduinoOutput(); //print stream from arduino + std::cout << "---------------------------------------" << std::endl << std::endl << std::endl ; + + /* + * Time delay of 1 sec + */ + usleep(1000000); + } - /* - * Measure the Spectrum - */ - std::cout << "$: Measuring the spectrum" << std::endl; - - std::string prefix = "# "; - try { - bool could_start = meter.start(); - if (! could_start) { - std::cerr << "Could not start remote mode" << std::endl; - meter.stop(); - return -1; - } - meter.units(true); - bool could_measure = meter.measure(); - device::pr655::cfg config = meter.config(); - spectral_data data = meter.spectral(); - if(could_measure) { - spectrumData.insert( std::pair(elem.second, data) ); - } else { - std::cout << ">>: Unable to measure spectrum of " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) <>: Unable to measure spectrum of " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) <(elem.second, data) ); + } else { + std::cout << ">>: Unable to measure spectrum of " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) <>: Unable to measure spectrum of " << unsigned(elem.second) << "nm LED on pin " << unsigned(elem.first) << " with PWM: " << ledPwmMap.at(elem.second) <(&device), "device file for aurdrino") - ("input", po::value(&input), "send r/g/b"); + ("input", po::value(&input), "Specify arduino command (info, pwm, reset, shoot)"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); From 81857b34907fe270d7fdfdc62ebd987c9286e72f Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Fri, 14 Aug 2015 16:15:02 +0200 Subject: [PATCH 15/16] [LPM][ LEDPhotoSpectrum] [Thresholder] Cleanup, addition of comments, rafactoring, better --help detail --- lib/data.cc | 14 ------------ lib/data.h | 4 ++-- tools/LEDPhotoSpectrum.cc | 10 +++++++-- tools/lpm.cc | 30 ++++++++++++++++++-------- tools/thresholder.cc | 45 +++++++++++++++++++++------------------ 5 files changed, 55 insertions(+), 48 deletions(-) diff --git a/lib/data.cc b/lib/data.cc index ae9eae2..c5281a1 100644 --- a/lib/data.cc +++ b/lib/data.cc @@ -296,13 +296,6 @@ std::map store::lpm_leds() const { lpm_led_map.insert( std::pair(pin_int, pwm_val_int) ); } - /* - std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; - - for(auto elem : lpm_led_map) { - std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "\n"; - } - */ return lpm_led_map; } @@ -326,13 +319,6 @@ std::map store::lpm_leds() const { lpm_led_map.insert( std::pair(wavelength_int, led_pwm_int) ); } - /* - std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; - - for(auto elem : lpm_led_map) { - std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "\n"; - } - */ return lpm_led_map; } diff --git a/lib/data.h b/lib/data.h index f2ee31d..dd0af00 100644 --- a/lib/data.h +++ b/lib/data.h @@ -164,10 +164,10 @@ class store { // cone fundamentals for calibration fs::file cone_fundamentals(size_t spacing = 4) const; - // the led mapping for the led pseudo monochroma//tor + // the led mapping for the led pseudo monochromator std::map lpm_leds() const; - // the pwm mapping for the led pseudo monochroma//tor + // the pwm mapping for the led pseudo monochromator std::map lpm_pwm() const; // yaml config IO diff --git a/tools/LEDPhotoSpectrum.cc b/tools/LEDPhotoSpectrum.cc index d6048dc..7e8aba2 100644 --- a/tools/LEDPhotoSpectrum.cc +++ b/tools/LEDPhotoSpectrum.cc @@ -1,3 +1,9 @@ +/* + * Tool for automating the process of turning on all available LEDs one by one and + * measuring the spectrum of each LED and taking the picture of each using the camera. + * -c & -s flags are added to skip spectrum measurement or capturing of photograph + */ + #include #include #include @@ -69,7 +75,7 @@ int main(int argc, char **argv) { */ const std::map ledPwmMap = store.lpm_pwm(); - std::cout << "Traversing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; + std::cout << "Traversing and printing the map; generated from LED PIN & Wavelength YAML Config File: " << std::endl; for(auto elem : ledMap) { std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "nm \n"; } @@ -188,7 +194,7 @@ int main(int argc, char **argv) { fout << ","; } } - break; + break; // just to print top header line in dump file } fout << std::endl; diff --git a/tools/lpm.cc b/tools/lpm.cc index d29b9e4..15dd5ee 100644 --- a/tools/lpm.cc +++ b/tools/lpm.cc @@ -1,15 +1,19 @@ +/* + * LED Pseudo Monochromator tool for communicating with Arduino that itself + * has firmware for controlling the attached LEDs; supports different commands + */ + #include #include - #include #include - #include -// info -// reset -// pwm 10,2000 -// shoot +// Supported commands: +// info (for getting information of all LED pins from arduino +// reset (for resetting and turning off all LEDs that are on) +// pwm 10,2000 (Turning on one LED on particular pin with pwm) +// shoot (For triggering IR LED to take picture from camera) int main(int argc, char **argv) { namespace po = boost::program_options; @@ -19,9 +23,9 @@ int main(int argc, char **argv) { po::options_description opts("LED Pseudo Monochromatic Command Line tool"); opts.add_options() - ("help", "Some help stuff") + ("help", "Flag for Help") ("device", po::value(&device), "device file for aurdrino") - ("input", po::value(&input), "Specify arduino command (info, pwm, reset, shoot)"); + ("input", po::value(&input), "Specify command (info, pwm, reset, shoot)"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); @@ -30,6 +34,14 @@ int main(int argc, char **argv) { if(vm.count("help")) { //show program options std::cout << opts << std::endl; + std::cout << "Supported Commands:" << std::endl << std::endl; + + std::cout << "info (for getting information of all LED pins from arduino" << std::endl; + std::cout << "reset (for resetting and turning off all LEDs that are on)" << std::endl; + std::cout << "pwm 10,2000 (Turning on one LED on particular pin with pwm)" << std::endl; + std::cout << "shoot (For triggering IR LED to take picture from camera)" << std::endl; + + std::cout << std::endl; } else if (vm.count("device")) { @@ -38,7 +50,7 @@ int main(int argc, char **argv) { device::lpm lpm = device::lpm::open(device); std::cout << "val of fd: " << lpm.io.printfd() << std::endl; - std::cout << "input: " << input << std::endl; + std::cout << "user input: " << input << std::endl; if(lpm.isCommandPWM(input) == 0) { // handle PWM diff --git a/tools/thresholder.cc b/tools/thresholder.cc index 74211a3..dfc08fc 100644 --- a/tools/thresholder.cc +++ b/tools/thresholder.cc @@ -1,10 +1,13 @@ +/* + * Thresholding tool for setting PWM values for all available LEDs such that + * their brightness is almost equal (Peaks are almost at same height) + */ #include #include #include #include #include #include - #include #include @@ -14,21 +17,19 @@ int main(int argc, char **argv) { std::string arduinoDevFile; std::string pr655DevFile; - std::string input; - po::options_description opts("IRIS LED Photo Spectrum Tool"); + po::options_description opts("IRIS LED PWM Thresholder"); opts.add_options() - ("help", "Some help stuff") + ("help", "Call --help for help") ("arduino", po::value(&arduinoDevFile), "Device file for Aurdrino") - ("pr655", po::value(&pr655DevFile), "Device file for pr655 Spectrometer") - ("input", po::value(&input), "send ,"); + ("pr655", po::value(&pr655DevFile), "Device file for pr655 Spectrometer"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); po::notify(vm); if(vm.count("help")) { - std::cout << opts << std::endl; + std::cout << opts << std::endl << std::endl; return 0; } else if(vm.count("arduino") && vm.count("pr655")) { @@ -50,7 +51,7 @@ int main(int argc, char **argv) { std::cout << "pin: " << unsigned(elem.first) << " -- Wavelength: " << unsigned(elem.second) << "nm \n"; } - std::cout << std::endl << "Starting Process for all available LEDs..." << std::endl << std::endl; + std::cout << std::endl << "Starting Thresholding Process for all available LEDs..." << std::endl << std::endl; std::map spectrumData; @@ -109,25 +110,19 @@ int main(int argc, char **argv) { device::pr655::cfg config = meter.config(); spectral_data data = meter.spectral(); - std::cout << "1" << std::endl; - std::vector spectraValues; - std::cout << "2" << std::endl; - for (size_t i = 0; i < data.data.size(); i++) { std::vector::iterator it = spectraValues.begin(); spectraValues.insert(it, data.data[i]); } - std::cout << "3" << std::endl; - float maxima = *std::max_element(spectraValues.begin(), spectraValues.end()); std::cout << "Peak at: " << maxima << std::endl; float diff = fabs(maxima - threshold); std::cout << "Difference in Threshold and Peak: " << diff << std::endl; - if( diff < 0.000005 || previousPWMVal < 1000) { // it's ok now + if( diff < 0.000005 || previousPWMVal < 1000) { // it's ok now if diff is less than specified value or PWM gets lower than 1000 currentLedThresholdFlag = true; led_pin_pwm.insert(std::pair(elem.second, previousPWMVal)); spectrumData.insert( std::pair(elem.second, data) ); @@ -176,15 +171,19 @@ int main(int argc, char **argv) { std::ofstream fout("spectral.txt"); - fout << "xx,"; + fout << "LED,"; for(auto elem : spectrumData) { spectral_data temp = elem.second; for (size_t i = 0; i < temp.data.size(); i++) { - fout << temp.wl_start + i * temp.wl_step << ","; + fout << temp.wl_start + i * temp.wl_step ; + + if(i != (temp.data.size() -1) ) { + fout << ","; + } } - break; + break; // just to print top header line in dump file } fout << std::endl; @@ -194,13 +193,17 @@ int main(int argc, char **argv) { spectral_data temp = elem.second; for (size_t i = 0; i < temp.data.size(); i++) { - fout << temp.data[i] << ","; - } + fout << temp.data[i] ; + if(i != (temp.data.size() -1) ) { + fout << ","; + } + } fout << std::endl; - } + fout.close(); + } else { std::cout << "Not Enough Arguments. call --help for help" << std::endl; } From d6d06abc018f8fa8cef8b6e5c7f29e1f69591aeb Mon Sep 17 00:00:00 2001 From: Shumail92 Date: Fri, 14 Aug 2015 16:21:25 +0200 Subject: [PATCH 16/16] Renaming of LPMThresholder to ledPWMthresholder --- CMakeLists.txt | 6 +++--- tools/{thresholder.cc => ledPWMthresholder.cc} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename tools/{thresholder.cc => ledPWMthresholder.cc} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8213765..d6741f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,9 +108,9 @@ set(LEDPhotoSpectrum_SOURCES tools/LEDPhotoSpectrum.cc) add_executable(iris-LEDPhotoSpectrum ${LEDPhotoSpectrum_SOURCES}) target_link_libraries(iris-LEDPhotoSpectrum iris) -set(lpmThresholder_SOURCES tools/thresholder.cc) -add_executable(iris-lpmThresholder ${lpmThresholder_SOURCES}) -target_link_libraries(iris-lpmThresholder iris) +set(ledPWMthresholder_SOURCES tools/ledPWMthresholder.cc) +add_executable(iris-ledPWMthresholder ${ledPWMthresholder_SOURCES}) +target_link_libraries(iris-ledPWMthresholder iris) set(pr655_SOURCES tools/pr655.cc) add_executable(pr655 ${pr655_SOURCES}) diff --git a/tools/thresholder.cc b/tools/ledPWMthresholder.cc similarity index 100% rename from tools/thresholder.cc rename to tools/ledPWMthresholder.cc