All posts by phobic

YX_PAD DEV – OBJECT RECOGNITION WITH PYTHON AND OPENCV

I need to find a good way to locate objects in the game, later I will find the coordinates of the object and send it to the Arduino controlling the stepper motors.

Step one is to install OpenCV on my Macbook. The best tutorial you will find on PyImageSearch.

First thing I tried was OpenCV with template matching. This is a method for searching and finding the location of a template image in a larger image. It simply slides the template image over the input image and compares the template and patch of input image under the template image. The method worked fairly OK, but it seemed like the method world be best on actual screengrabs, not motion video which can have a skew angle and differ in level of zoom. The template and object you want to find should be the same size.

This is when I discovered Haar Feature-based Cascade Classifier for Object Detection. This seems like the best algorithm to use for my case.

I have cloned a  good tutorial for learn how to train your own OpenCV Haar classifier, which I used in combination with this tutorial. All of the classifiers I have trained, will be uploaded here.

Pyton code for realtime testing of multiple classifiers:

EDIT: I discovered a fault that sent me on an hour detour around Google. At the step:

I only get the error:

I tried different things, like changing location of positive, negative and samples folder, adding the whole file location for  /usr/local/Cellar/opencv/2.4.12/bin/opencv_createsamples and messing around with the opencv_createsamples parameters. Nothing helped.

At some comment field I found the solution. I had only used one positive file when using the command:

This resulted in a positives.txt file having only one line of text. The createtrainsamples.pl ignores the last entry and throws an exception.

Just adding an empty line fixed the problem, and the script finally works!

 

YX_PAD DEV – COORDINATES CODE V.1

This code will move the stepper motor in +/- X-direction or +/- Y-direction depending on which “stepperX.move” line is uncommented. The movement will go on until an end stop is triggered.

Full code:

 

YX_PAD DEV – ENDSTOP TEST CODE V.2

Changed the endstop code to be separate functions.

 

YX_PAD DEV – ENDSTOP TEST CODE V.1

Endstops are mounted for min/max movement in X- and Y-direction.

This code will test if the connections are correct.

Screen Shot 02-18-17 at 03.14 PM

Upgraded to v.2 of the code

YX_PAD DEV CODE – STEPPER MOTOR CONTROL V.1

I have tried all kinds of boards in combination with motor controllers, and haven’t really gotten any of them to work.

This is the only code and board combination I have used that actually moves the stepper motors. I am using a Rumba board with stepper drivers A4988  and two Nema 17 Stepper Motor (4217HS4401).

This code does nothing more that move the center in a square. Just a proof a concept for actual stepper control.

 

Usefull Gcode commands for calibration of 3D-printer

G92E0 – Reset the extruder
G1E100F90 – Extrude 100 mm filament at the speed of 90 mm per minute. For 1.75mm filament.

Calibration: Old steps/mm * 100 mm / Length printer extruded = New steps / mm

List of my calibrated filaments for the Micromake D1:

RS-Online PLA Clear – 163 steps/mm – Flow: 90%
RS-Online PLA Black – 150 steps/mm – Flow: 90% – Hotend: 200
RS-Online ABS Clear Red – 170 steps/mm – Flow: 100% – Hotend: 220 – Bed: 100
RS-Online ABS Clear – 175 steps/mm – Flow: 100% – Hotend: 225 – Bed: 100

CONTROLLING UARM WITH SERIAL COMMAND THROUGH PYTHON WITH STDIN OVER BLUETOOTH FTDI DEVICE

I bough my uFactory uArm with an additional Bluetooth module.

I have had some problem making it work, so I will note down the procedure here.

The drivers for FTDI are found at FTDI Chip. I am using the x64 (64-bit) for Mac OS X 10.9 and above.

After installing the driver, the Bluetooth port did not come up in Arduino. I only get this error message:

Checking my System Information, I find the following information. (Description in Norwegian)

The available port can also be located with pySerial.

When using Python, I change the serial port to:

And then I follow the same procedure I did with the FTDI through USB cable. This works fine.

 

 

 

 

 

Controlling UArm with serial command through Python with stdin through FTDI USB

The code below works when iPad mini is centered and in line with the uArm feet.

 

Control Uarm with Python from Raspberry Pi over USB/serial line

SSH with X11 to Raspberry Pi.

First of all we need PyFirmata. Install it with:

or

Go to the folder where pyFirmata got installed. In my case it was:

Copy UarmForPython to this same folder.

Start Python and import UArmForPython to check if it is installed properly. If no errors – good to go.

Disconnect and reconnect USB

 

Install UArm on Raspberry Pi

From FTDIchip – download in Terminal:

 

sudo cp ~/UArmForPython/ .