OpenCV project

Please share your projects...
Bertus Kruger
Site Admin
Posts: 1594
Joined: Wed Feb 03, 2016 10:26 pm
Location: Wellington , New Zealand
Contact:

Re: OpenCV project

Post by Bertus Kruger » Sun Mar 08, 2020 6:36 pm

HTieleman wrote:
Tue Mar 03, 2020 3:47 pm
Bertus Kruger wrote:
Wed Feb 26, 2020 6:37 pm
HTieleman wrote:
Wed Feb 26, 2020 2:28 pm
Besides the above I try to figure out how to make sent commands to GRBL in python. Do you have a script in python which sents lineair motions to GRBL which is can use as example?
Here are some Python code I use to test if the serial port is working...
https://github.com/Protoneer/RPI-CNC-Co ... alPorts.py
I am still looking into the the translation between opencv in python and sending commands to GRBL. I am thinking of using an PID controller in python to determine which movement the gantry has to make (X, Y) and send jogging commands ($J) to GRBL.

I found the simple_stream.py script for sending G-code from python, but these script is set up to sent G-code positioned in a lose file. Can you point me in the right direction of how to sent $ commands directly out of python to GRBL?
The link above has an example in the TestSerial function.

It sends "?" to GRBL but you can replace that with your GRBL commands. Just have to consider that GRBL needs \r or \n characters to accept commands. (Can't remember if its \r or \n)

Bertus Kruger
Site Admin
Posts: 1594
Joined: Wed Feb 03, 2016 10:26 pm
Location: Wellington , New Zealand
Contact:

Re: OpenCV project

Post by Bertus Kruger » Sun Mar 08, 2020 6:52 pm


HTieleman
Posts: 6
Joined: Fri Feb 21, 2020 12:52 pm

Re: OpenCV project

Post by HTieleman » Mon Mar 16, 2020 12:28 pm

I got things up and running!

temporary removed the steppers from the linear drive to prevent catastrophic damages :)
I was able to reach the board via Minicom and I am able to jog the motors around with bCNC.

here some pictures of the test setup.

White tube has the camera mounted inside which should (at some point) be located above another circle by means of OpenCV.
I also wired a emergengy stop to cut off power towards the stepper motors for when I mount the motors in the system.

next step is to try get the motors moving by means of Python..
Attachments
IMG_6255.jpg
IMG_6255.jpg (192.78 KiB) Viewed 40 times
IMG_6254.jpg
IMG_6254.jpg (180.58 KiB) Viewed 40 times
IMG_6253.jpg
IMG_6253.jpg (175.71 KiB) Viewed 40 times

HTieleman
Posts: 6
Joined: Fri Feb 21, 2020 12:52 pm

Re: OpenCV project

Post by HTieleman » Mon Mar 16, 2020 1:09 pm

stumbled upon a small problem with my Python script.
I took the code below based on simple_stream.py from the Grbl GitHub.

Code: Select all

import serial
import time

#open grbl serial port
s = serial.Serial('/dev/ttyAMA0', 115200)

#wake up grbl
s.write('\r\n\r\n')
time.sleep(2)
s.flushInput()

#stream G-code to grbl
s.write('#J=X10.0 Y-1.5 F100\n')
grbl_out = s.readline()

s.close()
With the code above I wanted to sent a simple jogging G-code (#J=X10.0 Y-1.5 F100) to the board.
However I received the following error:
Attachments
IMG_6257.jpg
IMG_6257.jpg (159.2 KiB) Viewed 40 times

Bertus Kruger
Site Admin
Posts: 1594
Joined: Wed Feb 03, 2016 10:26 pm
Location: Wellington , New Zealand
Contact:

Re: OpenCV project

Post by Bertus Kruger » Fri Mar 27, 2020 11:28 pm

HTieleman wrote:
Mon Mar 16, 2020 1:09 pm
stumbled upon a small problem with my Python script.
I took the code below based on simple_stream.py from the Grbl GitHub.

Code: Select all

import serial
import time

#open grbl serial port
s = serial.Serial('/dev/ttyAMA0', 115200)

#wake up grbl
s.write('\r\n\r\n')
time.sleep(2)
s.flushInput()

#stream G-code to grbl
s.write('#J=X10.0 Y-1.5 F100\n')
grbl_out = s.readline()

s.close()
With the code above I wanted to sent a simple jogging G-code (#J=X10.0 Y-1.5 F100) to the board.
However I received the following error:
Have a look at this : https://stackoverflow.com/questions/356 ... -encode-to

Bertus Kruger
Site Admin
Posts: 1594
Joined: Wed Feb 03, 2016 10:26 pm
Location: Wellington , New Zealand
Contact:

Re: OpenCV project

Post by Bertus Kruger » Fri Mar 27, 2020 11:34 pm

I found it funny that I am now embarking on the same path.

My latest project is also using OpenCV with the RPI CNC hat...

I will be using Docker as well cause we need to roll the solution out to 4 machines.

Very surprised how quick the RPi4 is. :)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests