OpenCV project

Please share your projects...
HTieleman
Posts: 6
Joined: Fri Feb 21, 2020 12:52 pm

OpenCV project

Post by HTieleman » Fri Feb 21, 2020 2:10 pm

Hi everyone,

I recently bought a Protoneer Raspberry HAT for my project.

I want to achieve the following:
I have a X / Y gantry (both 400mm stroke) positioned above a table. The gantry is equipped with an USB camera.
On the table a piece of pipe is placed which can be moved around by hand.

By means op Opencv I manage to detect the circumference and center point of the pipe and calculate the pixel distance (x / y) from circle center to camera center.

Now I want to actively position the camera in the center of the pipe by means of Protoneer HAT.

I am looking for the most suitable way to do this within Python. Do you advice using bCNC? or sent direct serial commands from python? Do you have any example of sending direct messages from python?

Furthermore which software do I have to install on my Rpi if I want to keep my existing image? Installing opencv was quite some work and would like to prevent repeating the process.


Component list:
Raspberry pi 4
Protoneer CNC Hat
DRV8825 stepper drivers
12v 20A power supply
lineair actuators with 17HS3401-S stepper motors

Currently I am assembling the hardware, will post some pictures soon!

Thanks!

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

Re: OpenCV project

Post by Bertus Kruger » Tue Feb 25, 2020 6:49 pm

HTieleman wrote:
Fri Feb 21, 2020 2:10 pm

I am looking for the most suitable way to do this within Python. Do you advice using bCNC? or sent direct serial commands from python? Do you have any example of sending direct messages from python?

Furthermore which software do I have to install on my Rpi if I want to keep my existing image? Installing opencv was quite some work and would like to prevent repeating the process.

Very interesting project!!!

I would suggest talking to the Hat via serial in Python. I actually use Python scripts to test GRBL on the hats before I send them out.

You don't need to use the pre made SD card images. You just need to make sure the serial pins are work with your openCV environment...

In the past I have played with with Docker containers on the RPi to setup environments for these kind of things. Especially with openCV being a pain to install this might be a good option.

These were the main shell commands needed to make the serail work on 'n RPi 4. (I take it that is what you will use)

sudo sed -i 's/ console=serial0,115200//g' /boot/cmdline.txt

+

https://github.com/Protoneer/RPI-CNC-Co ... -Config.sh

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

Re: OpenCV project

Post by HTieleman » Wed Feb 26, 2020 2:28 pm

Thank you very much for your reply.

If I understand correctly I have to enable the serial GPIO pins of the RPi4 to communicate with the Hat.

sudo sed -i 's/ console=serial0,115200//g' /boot/cmdline.txt This will set the baud rate to 115200 by editing the cmdline.txt file correct?

And then the _RPi34-Serial-Config.sh script should be run. Correct?

Maybe a very beginner question..
How can I run a .sh file from github via my command line??

Furthermore do I have to install Arduino IDE? If I understand correctly GRBL is preinstalled on the HAT?

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?

Btw, great product!

Still in the hardware phase, will post some pictures soon

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

Re: OpenCV project

Post by Bertus Kruger » Wed Feb 26, 2020 6:31 pm

HTieleman wrote:
Wed Feb 26, 2020 2:28 pm
sudo sed -i 's/ console=serial0,115200//g' /boot/cmdline.txt This will set the baud rate to 115200 by editing the cmdline.txt file correct?
No, this is just to remove the default console port when the RPi loads

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

Re: OpenCV project

Post by Bertus Kruger » Wed Feb 26, 2020 6:33 pm

HTieleman wrote:
Wed Feb 26, 2020 2:28 pm
And then the _RPi34-Serial-Config.sh script should be run. Correct?
Yes, that will enable the /dev/ttyAMA0 port for coms.

GRBL runs at baud rate 115200

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

Re: OpenCV project

Post by Bertus Kruger » Wed Feb 26, 2020 6:35 pm

HTieleman wrote:
Wed Feb 26, 2020 2:28 pm
Maybe a very beginner question..
How can I run a .sh file from github via my command line??
https://www.cyberciti.biz/faq/run-execu ... ll-script/

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

Re: OpenCV project

Post by Bertus Kruger » Wed Feb 26, 2020 6:36 pm

HTieleman wrote:
Wed Feb 26, 2020 2:28 pm
Furthermore do I have to install Arduino IDE? If I understand correctly GRBL is preinstalled on the HAT?
GRBL is pre installed so you don't need Arduino to upload it.

If you have to I have used this script to install Arduino...
https://github.com/Protoneer/RPI-CNC-Co ... Arduino.sh

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

Re: OpenCV project

Post by Bertus Kruger » 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

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

Re: OpenCV project

Post by Bertus Kruger » Wed Feb 26, 2020 6:38 pm

HTieleman wrote:
Wed Feb 26, 2020 2:28 pm
Btw, great product!

Still in the hardware phase, will post some pictures soon
Thanks.. :)

Would love to see more on your project...

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

Re: OpenCV project

Post by HTieleman » 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?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests