benpeart / digital-daguerreotype

An application that will capture an image, convert it to TSP art and send gcode to render it on a CNC device
MIT License
4 stars 1 forks source link

Unable to run app at the final step - Imgui error #1

Open akay0402 opened 2 years ago

akay0402 commented 2 years ago

Hi Ben,

First of all, great project, I'm trying to replicate your setup. and have successfully installed all components/dependancies by following your instructions

I have tried to start the application by going to the build directory and entering "./digital-daguerreotype", the application launches momentarily and a windows opens, but then closes immediately

Then I'm presented with the below error

[WARN:0@1.498] global /home/USER/opencv/modules/imgcodecs/src/loadsave.cpp (239) findDecoder imread_('digital-daguerreotype.png'): can't open/read file: check file path/integrity digital-daguerreotype: /home/USER/Work/imgui/imgui.cpp:8458: bool ImGui::ItemAdd(const ImRect&, ImGuiID, const ImRect*, ImGuiItemFlags): Assertion id !=window->ID && "Cannot have an empty ID at the root of a window. If you need an empty label, use "##" and read the FAQ about how the ID Stack works!"' failed. Aborted.

Running OS and env:

Raspbian bullseye (64-bit) Raspberry pi 4 8GB model

Any help would be greatly appreciated

Many thanks, Ace.

akay0402 commented 2 years ago

Hi Ben,

After some troubleshooting, I was able to resolve the issue and load the application successfully by modifying the "main.cpp" file

In particular, line 577

I had modified it from ImGui::VSliderFloat("", slider_size, &clipping_dist, 0.0f, 6.0f, "", ImGuiSliderFlags_None); to ImGui::VSliderFloat("##slider_size", slider_size, &clipping_dist, 0.0f, 6.0f, "", ImGuiSliderFlags_None);

And then I had to rebuild the make file

"cmake .." in the build directory

But now when I try to test, I'm presented with the below error

[WARN:0@14.431] global /home/USER/opencv/modules/imgcodecs/src/loadsave.cpp (239) find Decoder imread_('digital-daguerreotype.png'): can't open/read file: check file path/integrity sh: 1: linkern: not found error spawning linkern

Again thanks in advance for your time and assistance on this

Regards, Ace.

benpeart commented 2 years ago

Thanks for the catch/fix for the ImGui error. They must have changed the requirements for ID's since I last built this. I'll incorporate your fix and update the repo.

You are very close to getting this running! You have a couple of unrelated issues here:

First, the warning "[WARN:0@14.431] global /home/USER/opencv/modules/imgcodecs/src/loadsave.cpp" is benign. That is just checking for the existence of an image with the filename 'digital-daguerreotype.png' and if it exists, it will load it and jump directly into processing it (instead of using the camera to capture an image). It was a handy way to get output for any image I wanted instead of just images I could capture with the camera.

The second error is the 'linkern: not found' error. The fix for this is listed in the readme.md file as "5. Concorde (Traveling Salesman toolset) specifically the linkern command line tool." You will need to download this tool from http://www.math.uwaterloo.ca/tsp/concorde/ and put it in your source directory so the build can find it.

akay0402 commented 2 years ago

Hi Ben,

No joy. As I get the same issue

However when I look at the concorde folder, I can see a folder called LINKERN, when I navigate to that folder there is "linkern" app

I tried deleting the "concorde" and "digital-daguerreotype" Unzipping c0031219.tar Moved the concorde folder to /home/USER/Work Copied the linkern file to "/home/USER/Work/concorde" cd ~/Work/concorde ./configure make It did create the LINKERN folder and the linkern app (green icon) cd ~/Work git clone https://github.com/benpeart/digital-daguerreotype mkdir build && cd build cmake ../ make -j4

My folder structure is as follows:

/home/USER/Work /home/USER/Work/concorde /home/USER/Work/digital-daguerreotype /home/USER/Work/imgui /home/USER/Work/librealsense /home/USER/Work/protobuf

Apologies if these are basic things I should know as I'm fairly new to linux and am navigating with the little skills I know

Thanks for your assistance

Regards, Ace.

benpeart commented 2 years ago

Does the linkern app run when you attempt to run it manually or do you get an error? I had to get the Concorde source and build it for Raspberry Pi. It took some tweaking to get it to build (mostly dealing with platform dependencies). Once you get it building and running, place the resultant linkern binary in the same directory as the digital-daguerreotype binary so it can find it.

akay0402 commented 2 years ago

Hi Ben,

Yes it does seem to run when ran manually

I've placed the linkern file/app under Work folder, the digital-daguerreotype folder and also the build folder

Still the same issue

ace@raspberrypi:~/Work/digital-daguerreotype/build $ ls CMakeCache.txt cmake_install.cmake digital-daguerreotype linkern CMakeFiles compile_commands.json digital-daguerreotype.tsp Makefile ace@raspberrypi:~/Work/digital-daguerreotype/build $ ./linkern -s 99 -k 100 Host: raspberrypi Current process id: 12994 ./linkern -s 99 -k 100 Chained Lin-Kernighan with seed 99 Random 100 point set XTime to build kdtree: 0.00 445 edges Time to find quad 2-nearest: 0.00 Grow a Quick-Boruvka tour Length of Quick-Boruvka Tour: 892.00 Time to grow tour: 0.00 linkern ... Starting Cycle: 892 0 Steps Best: 787 0.00 seconds 1 Steps Best: 785 0.00 seconds 2 Steps Best: 784 0.01 seconds 10 Steps Best: 782 0.02 seconds 18 Steps Best: 781 0.03 seconds 19 Steps Best: 780 0.03 seconds 100 Total Steps. Best cycle length: 780 Lin-Kernighan Running Time: 0.10 Final Cycle: 780 Total Running Time: 0.11 ace@raspberrypi:~/Work/digital-daguerreotype/build $ ls CMakeCache.txt cmake_install.cmake digital-daguerreotype linkern CMakeFiles compile_commands.json digital-daguerreotype.tsp Makefile ace@raspberrypi:~/Work/digital-daguerreotype/build $ cd .. ace@raspberrypi:~/Work/digital-daguerreotype $ ls 3Dmodels dithering.cpp main.cpp build gcode.cpp README.md CMakeLists.txt gcode.h rgb2tsp.cpp digital-daguerreotype.sln images rgb2tsp.h digital-daguerreotype.vcxproj LICENSE texture.h digital-daguerreotype.vcxproj.filters linkern ace@raspberrypi:~/Work/digital-daguerreotype $ cd .. ace@raspberrypi:~/Work $ ls concorde imgui linkern protobuf digital-daguerreotype librealsense OpenCV-4-6-0.sh

Is there another place I should be placing the file on?

Do you perhaps have an environmental variable that points to linkern?

Regards, Ace.

benpeart commented 2 years ago

This error:

sh: 1: linkern: not found error spawning linkern

indicates that the call to spawn the linkern still can't find the binary. The code that spawns linkern is in rgb2tsp.cpp (line #135):

// now spawn Concorde to create a tour
error = system("linkern -Q -t 5 -o digital-daguerreotype.tour digital-daguerreotype.tsp");
if (error)
    throw std::runtime_error("error spawning linkern");

The 'system' call will search the path to locate the command to execute. You can add the directory that contains linkern to your path by updating '.bashrc' Here is an article on the web that goes through this in a lot of detail.

akay0402 commented 2 years ago

Hi Ben,

I can confirm that has worked. I'm now able to see the TSP output

I made changes to my ".bashrc" file and added the line

export PATH="$HOME/.local/bin:$HOME/bin:$PATH:/home/USER/Work/concorde/LINKERN"

Many thanks for your help

I am however not able to get cnc machine (Bachinmaker ST-2039) to now work, when I click draw it simply resumes back to the initial step

I presume I need to get the device driver installed

Thanks Ace.

benpeart commented 2 years ago

Sound like you are getting an error when it tries to output the gcode to the cnc. You can check with a debugger (GDB works well) to see what is failing. This all happens in main.cpp:print_gcode().

There is no driver necessary, the cnc should just show up as a USB device. On line #683 in main.cpp I open the serial port "/dev/ttyUSB0" and then write out all the gcode to draw the image. It's possible your device shows up as a different USB device (especially if you have some other usb devices plugged in). You can check with lsusb - make sure 1) the cnc is showing up as a USB device and 2) what the device name is. Google can help here if you don't know how to do this.

akay0402 commented 2 years ago

Hi Ben,

Can confirm the cnc shows up as a device.

ace@raspberrypi:~ $ lsusb Bus 002 Device 002: ID 8086:0ad3 Intel Corp. Intel(R) RealSense(TM) Depth Camera 415 Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 005: ID 03f0:2f4a HP, Inc HP Business Slim Keyboard Bus 001 Device 004: ID 046d:c07d Logitech, Inc. G502 Mouse Bus 001 Device 003: ID 1a86:7523 QinHeng Electronics CH340 serial converter Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub ace@raspberrypi:~ $ ls /dev/*USB* /dev/ttyUSB0

When I remove the USB cable that's plugged into the CNC machine, and run the "ls /dev/USB", it recognises there's no other USB device

I also had checked the syslog and could see that it's getting attached

Jul 17 00:31:27 raspberrypi mtp-probe: bus: 1, device: 5 was not an MTP device Jul 17 00:31:27 raspberrypi kernel: [ 1919.214954] usbcore: registered new interface driver usbserial_generic Jul 17 00:31:27 raspberrypi kernel: [ 1919.215007] usbserial: USB Serial support registered for generic Jul 17 00:31:27 raspberrypi kernel: [ 1919.219625] usbcore: registered new interface driver ch341 Jul 17 00:31:27 raspberrypi kernel: [ 1919.219687] usbserial: USB Serial support registered for ch341-uart Jul 17 00:31:27 raspberrypi kernel: [ 1919.219789] ch341 1-1.1:1.0: ch341-uart converter detected Jul 17 00:31:27 raspberrypi kernel: [ 1919.233987] usb 1-1.1: ch341-uart converter now attached to ttyUSB0

Regards, Ace.

akay0402 commented 2 years ago

Hi Ben,

I tried to troubleshoot further, but could not isolate the issue. And so I tried starting fresh and installed everything on a freshly formatted OS

But now I'm getting a different error message:

OpenCV(4.6.0) /home/USER/opencv/modules/core/src/matrix.cpp:808: error: (-215:Assertion failed) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'Mat'

Does this look familiar to you

Regards, Ace.

benpeart commented 2 years ago

Sorry for the radio silence. Both my parents got covid and my father is currently dying from it. I'm going to be busy and unavailable for a while.

I don't recognize that problem with OpenCV but I'd look into the code that converts a real sense frame into a matrix for processing by OpenCV. I would guess the real sense frame isn't getting generated correctly.

akay0402 commented 2 years ago

Hi Ben,

My greatest sympathies, appreciate you taking the time to msg me. Hope everything gets better real soon!

I'd continue to troubleshoot this on my end

You have my thoughts and prayers, stay strong

Regards, Ace.

akay0402 commented 5 months ago

Hi Ben,

Just thought I'd reach out, I sort of lost interest. But then only recently started to get it to try and work again.

I managed to finally move the xy plotter by installing minicom and enabling local echo

Will keep you posted. Hope everything is okay on your end

Regards, Ace.

akay0402 commented 5 months ago

Hi Ben,

I think I managed to isolate the issue. The issue was the first check to see if it's arm.

#ifdef __arm__
#define RASPBERRYPI
#endif

as I'm using raspberry pi os 64 bit not sure if this is defined. So I modified the code to

//#ifdef __arm__
#define RASPBERRYPI
//#endif

I also commented the code to not check for the existing file "digital-daguerreotype.png". I did this by commenting the below code block

        // Mat disk_image = imread("digital-daguerreotype.png");
        // if (!disk_image.empty()) {
            // display_image = disk_image;
            // process_image = true;
            // program_mode = program_modes::computing;
            // rename("digital-daguerreotype.png", "digital-daguerreotype.png.bak");
        // }

When I now run try to recompile the code I'm getting an error

/usr/bin/ld: CMakeFiles/digital-daguerreotype.dir/main.cpp.o: in function `print_gcode(void*)':
main.cpp:(.text+0x319c): undefined reference to `gcode_open(char const*)'

Will keep you posted

Thanks, Ace.

benpeart commented 5 months ago

Glad to hear you are making progress.

Removing the #ifdef around the #define RASPBERRYPI is fine – I was using that to enable me to build it for Windows as well as Raspberry PI as debugging on Windows is a lot easier for me (tools I’m familiar with).

The code checking for digital-daguerreotype.png is to let me load an image from disk instead of from the camera. For example, I had it load (and then draw) a picture of the Eifel Tower). If you don’t want to be able to do that, leave it commented out. If that files doesn’t exist, the code is benign and just won’t execute. If you want to use it, just copy a file named digital-daguerreotype.png to the same directory the application is in and it will get loaded and printed.

`gcode_open(char const*)' is in the file digital-daguerreotype/gcode.h at main · benpeart/digital-daguerreotype (github.com)https://github.com/benpeart/digital-daguerreotype/blob/main/gcode.h which should be in your clone of the repo. Gcode.h is include at the top of main.cpp:

. .

include "texture.h"

include "gcode.h"

include

. .

Ben

From: akay0402 @.> Sent: Wednesday, May 29, 2024 7:24 PM To: benpeart/digital-daguerreotype @.> Cc: Ben Peart @.>; Comment @.> Subject: Re: [benpeart/digital-daguerreotype] Unable to run app at the final step - Imgui error (Issue #1)

Hi Ben,

I think I managed to isolate the issue. The issue was the first check to see if it's arm.

ifdef arm

define RASPBERRYPI

endif

as I'm using raspberry pi os 64 bit not sure if this is defined. So I modified the code to

//#ifdef arm

define RASPBERRYPI

//#endif

I also commented the code to not check for the existing file "digital-daguerreotype.png". I did this by commenting the below code block

           // Mat disk_image = imread("digital-daguerreotype.png");

           // if (!disk_image.empty()) {

                   // display_image = disk_image;

                   // process_image = true;

                   // program_mode = program_modes::computing;

                   // rename("digital-daguerreotype.png", "digital-daguerreotype.png.bak");

           // }

When I now run try to recompile the code I'm getting an error

/usr/bin/ld: CMakeFiles/digital-daguerreotype.dir/main.cpp.o: in function `print_gcode(void*)':

main.cpp:(.text+0x319c): undefined reference to `gcode_open(char const*)'

Will keep you posted

Thanks, Ace.

— Reply to this email directly, view it on GitHubhttps://github.com/benpeart/digital-daguerreotype/issues/1#issuecomment-2138409653, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADULUPMANFOHLIVQFXZ4L43ZEZPSFAVCNFSM53EMRQP2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJTHA2DAOJWGUZQ. You are receiving this because you commented.Message ID: @.**@.>>

akay0402 commented 5 months ago

Ah man, I really thought I had fixed it. So after fixing the code in the main.cpp and gcode.cpp, it now compiles okay and successfully builds the application. However I'm now getting "Segmentation fault" as the error. When I try to launch the program. If I leave the ifdef arm and compile, I'm able to launch the application and continue. But no such luck with them (#ifdef) commented/deleted

benpeart commented 5 months ago

Check all the code inside the various “#ifdef RASPBERRYPI” sections. If I had to guess, you don’t have Open GL setup on the Raspberry Pi.

From: akay0402 @.> Sent: Thursday, May 30, 2024 6:03 AM To: benpeart/digital-daguerreotype @.> Cc: Ben Peart @.>; Comment @.> Subject: Re: [benpeart/digital-daguerreotype] Unable to run app at the final step - Imgui error (Issue #1)

Ah man, I really thought I had fixed it. So after fixing the code in the main.cpp and gcode.cpp, it now compiles okay and successfully builds the application. However I'm now getting "Segmentation fault" as the error. When I try to launch the program. If I leave the ifdef arm and compile, I'm able to launch the application and continue. But no such luck with them (#ifdef) commented/deleted

— Reply to this email directly, view it on GitHubhttps://github.com/benpeart/digital-daguerreotype/issues/1#issuecomment-2139208676, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADULUPIG36PZWCK5U6RRNLDZE32MNAVCNFSM53EMRQP2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJTHEZDAOBWG43A. You are receiving this because you commented.Message ID: @.**@.>>

akay0402 commented 4 months ago

It works. I had to comment the below line of codes and did nothing else. Very happy that it worked


#ifdef RASPBERRYPI
    // create the window full screen
    GLFWmonitor* monitor = glfwGetPrimaryMonitor();
    const GLFWvidmode* mode = glfwGetVideoMode(monitor);

    glfwWindowHint(GLFW_RED_BITS, mode->redBits);
    glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
    glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
    glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
    GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, window_name, monitor, NULL);
#else
    // create the window the size it will be on the Raspberry Pi
    GLFWwindow* window = glfwCreateWindow(screenWidth, screenHeight, window_name, NULL, NULL);
#endif

I think it has to do with Hardware acceleration, yes I think you were right I didn't have the option to enable OpenGL driver in sudo-raspi config (Step 3) in https://www.instructables.com/Digital-Daguerreotype-TSP-Art/.

But it didn't affect the capture and printing side of things

Regards, Ace.