Posted in Uncategorized

A Web Server-Controlled Mobile Robot

This post is about getting into robotics.  I discovered building robots uses some of the same skills for building CNC machines.  Basically you are coupling motors to move to an object to move that object. I increased my knowledge in web development.  Software is a significant part of the robot, because it controls everything. A friend and I built robots which are controlled from a web server and wifi. No wires are connected to the robots. My friend did most of the heavy lifting on the software.

Mobile Robot and Test Fixture

About the robots

Currently our robots are prototypes.  At this point, in the project, we are only proving a concept.  Of course, with any project, the budget is limited. The objective is to keep the cost down by using Off-the-shelf parts that are available most places such as Lowes, Home Depot or online.  I am amazed with the availability and low cost of the technology.

Robot parts purchased Locally

This section of the blog is about the parts that were purchased locally.  The frame, wheels, and the battery were purchased from Lowes Hardware.

The webcam was purchased from Best Buy.

The ½” thick plastic was purchased from Tap Plastics in Bellevue Washington which was repurposed from another project.

The most expensive part of the robot is the battery and charger.  The battery is a Dewalt 12 volt 3 Amp Hour Lithium Ion battery used in their power drills.  This works pretty well for pro-typing. You will need a larger battery for production.



Robot parts purchased online

This section of the blog covers the parts that were purchased online.  These parts can be purchased from Amazon or Ebay. If you buy the parts from Ebay you might be able to save more money.  Don’t forget that the Amazon prices are pretty good, when you factor in Prime’s free shipping.

The Raspberry Pi, Arduino, Stepper Motors and Drivers, Battery Emulation Circuit were purchased off Amazon.

Web server and Clients

The software is composed of a web server and a 2 or more clients.  

  • Client 1 is running on the Raspberry Pi.
  • Client 2 is running on the desktop/laptop and sending messages between a game engine.

The game engine is connected to an XBox controller which sends messages to the server commanding it to move the robot.   The server passes the message to the Raspberry Pi. Then the Pi executes the commands sent over.

I will cover this is more detail in the next post if there is a demand.

Live Streaming Video V4L2RTSPServer

Currently, I am working on the live stream video.  I am running v4l2rtspserver on the Raspberry Pi to stream live video from the webcam.  

The software needed on your host pc;

  • Install Visual Studio Code.
  • Install Vlc- use this tool to view the streaming video.  No programming is required.
  • Install Python
  • Install Opencv-python- Pip install opencv-python

You need to install v4l2rtspserver on your Raspberry Pi;

All the information needed is at https://github.com/mpromonet/v4l2rtspserver

After you install the software on the Raspberry Pi, run the following command from the terminal.

V4l2rtspserver -c -v -H480 -W640 /dev/video0

After running the command.  The program outputs the url it is streaming from to the termainal.  You will see a url.

rtsp://<url>:8554/unicast.

View Live Streaming Video from VLC

Run the VLC and “Open Network Stream” from the Media menu.  Enter the rtsp://<url>:8554/unicast. You should see the video from the webcam.

Open the Network Stream and PLAY
Live Video in VLC

View Live Streaming Video from Opencv-python

The VLC is a good way to verify your video is working, but you cannot use it for many applications.  It would take a lot of work to integrate it into an application like unity or any other application. You can use Opencv-python.

I am not going to show you how to install it, because there are many tutorials out there.   But, here is one that I used;

Open Visual Studio Code and copy/past the following snippet

“”” Quick script to test an RTSP server. “””

import cv2 as cv

vcap = cv.VideoCapture(“rtsp://XX.0.0.XX:8554/unicast”)

while(1):

     ret, frame = vcap.read()

     cv.imshow(‘VIDEO’, frame)

     cv.waitKey(1)

Before you run the code enter your url.

You should see video as shown in the photo below.

Live Video from the Webcam

Summary

We can move the robots. But more work needs to be done;

We plan to implement the following

Stream the video in Unity or GoDot.

Control the robot from a browser

Develop an easier way to get the url from robot without using Putty

Make it autonomous.

Posted in Computer Vision

Calibrating the Video Camera (Augmented Reality JoyStick Part 4)

This section is very important for the Detecting/tracking the markers.  It also affects the accuracy of the camera orientation.  This article assumes you have experience with Visual Studio 2015.

Watch OpenCV Basics on Camera Calibration

This the minimum training needed to calibrate the camera.  George Lecakes provides the tutorial.  There are 4 parts to calibration.

  • OpenCV Basics 14 on Camera Calibration Part 1
  • OpenCV Basics 16 on Camera Calibration Part 2
  • OpenCV Basics 17 on Camera Calibration Part 3
  • OpenCV Basics 18 on Camera Calibration Part 4

Create a Detection Board for Calibration.

Select the project to create a pattern used for calibration.

Here are the debug setting in VS2015

Cut and paste the settings into VS2015 and run the program

“C:\\ArucoData\\Calibration\\grid_board_4x4_50_1.png” -w=7 -h=5 -l=400 -s=100 -d=0

Running the program will produce the following image.  You will need to print the image a tape it to a thin (¼”) plywood board.


Calibrate the Camera.

Refer to OpenCV Basics 17 on Camera Calibration Part 3.  This video shows you how to calibrate the camera.

 

Select the project as shown.

Calibration debug settings

Cut and Paste into vs2015 and run the program.

-w=5 -h=4 -l=0.04 -s=0.01 -d=0 -a=1 -dp=”C:\ArucoData\Markers\detector_params.yml” “C:\ArucoData\Calibration\out_camera_data1_hd1080.yml”

 

To calibrate the camera, place the board in the field of view of the camera.  Change the orientation of the camera.   The youtube video OpenCV Basics 17 on Camera Calibration Part 3 shows how to calibrate the camera.  It is not hard.

 

Good luck.

 

Posted in CNC Router, Computer Vision

Updating your old CNC machine (Augmented Reality JoyStick Part 5)

Introduction

The purpose of this article is to explain how to update your old CNC machine.  Also a another reason for this article is to record what I did so I can reference it later.  I guarantee, 6 months from now I won’t remember.  This article was written assuming you have some experience with the KFLOP motion controller or any other motion controller.  Also, good wiring skills are needed to connect encoder/motor to the motion controller.

About the old machine

The machine was old, but it was in good condition.  The table moved as expected. You can turn the lead screws on each axis and move the axis.  This task was to make sure that the lead screws were not locked.

DC Servo Motor

This is my 3rd machine that I have worked on.  Refurbishing the machine went faster than expected, because most of the parts were still working.  The machine used old DC Servo motors with analog tachometers.  After all the machine is over 20 years old.  What do you expect from an old machine? 

 

Modifying DC Servo Motor and Analog Tachometer

To update the motors, I removed the tachometers and replace them with encoders.  It was a very small investment in time and money.

The image below shows the original motor with tachometer.

Motor and Analog Tachometer

Replacing the Tachometer with Encoder.

The image below shows the motor with the encoder.  Replacing the tachometers with encoders simplified the motor.  I used the AMT102 encoders from CUI, Inc.

 

Incorporating KFLOP and Snap Amp

I used the Dynomotion KFLOP Motion Controller again for this project.  What is different with this new machine from the previous CNC machines?  I used the Dynomotion Snap Amp to drive the servo motors instead of the Gecko drives.  This turned out to be a good decision;

  • The minor downside of the Snap Amp; it costs more than the Geckos. The Snap Amp costs $400, but controls 4 axes.  If you only need 3 axis, 3 Geckos will cost you $114.95/each for a total for $344.85.
  • The Snap Amp was easier to wire than the Geckos.
  • Dynomotion provides all software to tune the PID parameters for the Snap Amp. Tuning the Amplifier was done without any manual adjustments to the hardware. The Gecko drives required manually tuning by adjusting a potentiometer on the drive.


XBox Joystick

We are using the XBox Game Controller to move the machine.  It works well for what I want it to do.  The good thing about the controller, you can customize the joystick to do more than just move the machine.  In this demonstration, functionality was added to the X, Y, B button to zero out the axes.

Just a tip.  If you don’t want to spend a lot of money on XBox Joystick, you can buy one at Goodwill for $6 or $7.  I bought my second joystick there.  It works as good as the newer one.

 

Getting the Motion Control System to work

This took me about a few hours to get the first motor to move because I was a little sloppy with the wiring.  Make sure your wiring is good especially between the encoders and the KFLOP.  Bad wiring will cause the machine to move unexpectedly.  After working on the machine, I am a firm believer in using the e-Stop.  If you machine goes out of control; just hit the e-stop.  Whatever you do, take your time with the wiring and invest in good crimping tools

Also, It took me a while to figure how to write the C program to move the stage.

 

int main()

{

    WriteSnapAmp(SNAP0+SNAP_PEAK_CUR_LIMIT0,9);
    WriteSnapAmp(SNAP0+SNAP_PEAK_CUR_LIMIT1,9);

 // clamp supply to 90V
    WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP0,SNAP_CONVERT_VOLTS_TO_ADC(70.0));
    WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP1,SNAP_CONVERT_VOLTS_TO_ADC(70.0));

 // enable supply clamping
    WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP_ENA0 ,1);
    WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP_ENA1 ,1);
}

 

This code will allow you move the motors from the KMotion Step Response dialog.  I would test each axis.

 

How to Create the C Program for the KFLOP and Snap Amp.

Creating the C program to control the SnapAmp was a little tricky.  I am assuming your machine has 3 axis.  Basically, I converted InitKStep3Axis.c program to control the Snap Amp.

Here are the steps.

 

  1. Copy InitKStep3Axis.c in C:\KMotion433\C Programs\KStep to C:\KMotion433\C Programs\SnapAmp.
  2. Go to the C:\KMotion433\C Programs\SnapAmp.
  3. Rename InitKStep3Axis.c to InitSnapAmp3Axis.c.
  4. Open InitSnapAmp3Axis.c.
  5. Paste the following code below the Main ()

 

WriteSnapAmp(SNAP0+SNAP_PEAK_CUR_LIMIT0,9);

WriteSnapAmp(SNAP0+SNAP_PEAK_CUR_LIMIT1,9);

// clamp supply to 90V

WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP0,SNAP_CONVERT_VOLTS_TO_ADC(70.0);

WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP1,SNAP_CONVERT_VOLTS_TO_ADC(70.0);

// enable supply clamping

WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP_ENA0 ,1);

WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP_ENA1 ,1);

 

  1. Remove the command KStepPresent=TRUE.

 

The top of the program should look like.

Tuning the DC Servos.

Once you have the program you can start tuning the servos.  Dynomotion provides all of the software to tune the system.  Of course you need to wire the encoders to the KFLOP.

Before you apply power to the motors, run the KMotion.exe and hit the “Axis” menu.  This page displays the status of the each axis via encoders.   When you turn the motors manually, you will see the counts change for each axis.

Next wire the power up to the motors and the Snap Amp.

Here are the steps.

  1. Turn on the Power.  Run Kmotion.exe.
  2. Open, Compile and Run the initSnapAmp3Axis.c.

3. Open the Config Dialog.

4.  Open the Step Response Dialog.

5.  On the Step Response Dialog under the “servo” box.

Hit the “disable” button to disable the servo amp.

Hit the “Zero” button.

Hit the “Enable” button to re-enable the servo amp.

6.  To Tune hit the Step button.  You should see the output as shown above.

7.   Change the P, D, I values in the order specified until you get the output as shown below

8.  Repeat the steps for the other axes.  For more information refer to the KFLOP manual.

 

Posted in Gaming Technology

Augmented Reality Project with Unity and Vuforia

Introduction

This article will explain how to use Unity and Vuforia to make an Augmented Reality app for your Android device.  As a beginner, this is where I had some problems.  To create the Android app was as simple as recompiling the Unity project for the Android platform.  The app failed to build on Android Studio.  The next problem, the app would not switch to the video after detecting the targets.

Basically, the application uses photos of the Seattle Seahawks’ logo and Russell Wilson as target images.  When the app detects the target, the app switches to the videos of the Hawks famous plays.

The application worked with Unity 2017.4.1.f1 and Vuforia SDK v7.1.34.  This article does not cover running the Unity and Vuforia on the Windows 10 desktop, because “Playful Technology” already has an awesome video on youtube.

 

Unity and Vuforia Tutorial on Windows 10

There is no way I could explain it better.  The author from “Playful Technology” does an excellent job.  The video was published February 2018.  As of April 2018, this was one of the latest tutorials.

https://www.youtube.com/watch?v=MtiUx_szKbI&t=748s

Unity and Vuforia are changing their software a lot.  I started out trying the make the app based on a tutorial from September 2017, but it was out of date.

Devices used

Windows 10 PC, Galaxy Tablet A.  Android version 7.1.1.

The Unity and Vuforia Project

The project is real simple.  I am using photos of Seahawks’ logo and of Russell Wilson as my targets. These 2 photos were added to “Target Manager” database from the Vuforia website.,  After you create the database, import it into Unity.  When you run Unity, the AR camera detects the targets, and the app shows the Seahawks monumental plays.  GO HAWKS!!

 

Unity and Vuforia Tutorial on Android

The 2 problems I encounter were;

  • The project would not build for Android
  • Videos attached to the markers would not play.

SOLUTION

For any problems with the app check Unity website first.  A lot of information is under the Unity “Community” link.  Both of the solutions were found under “Forums” and “Answers” which is under the link.

The Build Problem

The Unity/Vuforia project failed to build with jdk-9.0.1.  The Unity Forum explained how to fix the problem in Android Studio, by changing the jdk-1.8.0_131.  Yo do this by loading the Unity *.apk project into Android Studio.  Then go to File > Project Structure and change the SDK setting as shown and change the jdk-1.8.0_131.


The Video Transcoding Problem

The next problem was the app was not switching to the video after it detected the targets.  The video had to be transcoded and compressed.  Without transcoding the video, the Android device was not able play the video.  The video had to be compressed so it can run on the Android device.  The original size of the Android executable was 126 MB.  Transcoding and compressing the video cut the size down to 66 MB.

Video Of the App running in Unity And Vuforia on Windows and Android

Posted in CNC Router

How to connect the Omron EE-SX671 Limit Switch to the KFLOP

Augmented Reality JoyStick Part 2

Limit switches are very important for machine safety and longevity.  The switches prevent the machine from moving past its mechanical limits.  When the machine reaches the limit, the switch sends a message to the motion control system to disable the motor.  This is especially critical when the stage is moving at high speeds.  Without the switches, parts can fly off the machine and potentially injuring the operator.  This project uses the Omron ee-sx671 which is an optical switch.

The Basic Circuit

The switch is just like any switch.  The switch is connected to digital input on the Dynomotion Snap Amp with a pull up resistor.  Here is a simplified version of switch.

The EE-SX671 is an optical limit switch

The ee-sx671 is an optical switch.  The sensor operates by sending a beam of light between the slot.  One side is the emitter the other is the receiver.  When the light is blocked between the emitter and receiver the switch changes state.  The advantage of an optical it is immune to electrical noise.  The disadvantage is it is affected by external light.

Know the configuration of your switch PNP or NPN

Since the part number is EE-SX671 and there is no P or R after the number.  The part is NPN.  Its very important to know the difference.  If the part is hooked up wrong it could damage the part.

Here is the PNP configure.  We are not going to use it.  We will keep this for future reference.

Some of the specifications of the switch

The important information to know is the voltage and the maximum current it can handle.  The switch will operate from 5 to 24 VDC, and can handle 35 ma max.

Connecting the switch to the Snap Amp

The following circuit is the DIO signal to the Snap Amp.  We connect the 5 volts of the switch to OPTO_PLUS signal.  The 470 ohm resistor the switch will draw 10 ma.  The current is well under the 35 ma limit.

Next we connect the OPTO_NEG signal to the OUT signal of the switch.

Each axis requires 2 switches; one for the min and one for max position.  We only need one 5 Volt power supply for all of the limit switches.

The limit switches are connected to;

Axis

Signal on Switch

Signal on Snap Amp

PIN Bit (SnapAmp #0)
X min + 5V OPTO_PLUS_0 32 72
OUT OPTO_NEG_0 31
X max + 5V OPTO_PLUS_1 34 73
OUT OPTO_NEG_1 33
Y min + 5V OPTO_PLUS_2 36 74
OUT OPTO_NEG_2 35
Y max + 5V OPTO_PLUS_3 38 75
OUT OPTO_NEG_3 37
Z min + 5V OPTO_PLUS_4 36 76
OUT OPTO_NEG_4 35
Z max + 5V OPTO_PLUS_5 38 77
OUT OPTO_NEG_5

37

 

Defining the Limit Switches in the KFLOP.

How do you use the information in the KFLOP.  You came to the right place.

 

Step 1:  Run KMotion.exe and Load the C Program for your setup.

You should see something like this dialog.

Step 2:  Open the “Config & Flash”

This is where you set the limit switch parameters.

Step 3:

Open the “Digital IO” dialog for the Snap Amp.  Make sure you connect the 5 volts to your limit switches.  You should see the following dialog.

Place a piece of paper between the slot of the limit switch.  You will see the state change in the check box from UNCHECKED to CHECKED.  Initially, I was not sure if the “Unchecked” state was HIGH or LOW.  The “Unchecked” state is low.  You might want to verify this yourself.

The C program I am using seems to work.  The KFLOP definitely stopped motion when I moved into the limits.

Best of Luck setting the limit switches.  Don’t forget to export the settings and save your program.

 

Posted in Computer Vision

How to use (AR) Augmented Reality to Control your CNC Machine

(Augmented Reality JoyStick Part 1)

Prerequisites

To get the most benefit from this blog you should have some background in the following areas; Computer Vision applications with OpenCV and marker tracking, C#/C++ programming.

Introduction

In this article I will demonstrate how to develop an Augmented Reality (AR) application to move your CNC machine.   I call application the AR Joystick.   The AR Joystick interfaces with a camera and displays the video.  It operates by searching for markers on the machine.   When it detects the markers, the app draws a green box around markers and draws the lines for the X and Y Axis.  If the box is not drawn the marker is not detected.  The markers determine where the machine can move.

The initial idea came from the book “Arduino Computer Vision Programming”, Chapter 9 “Building a Click-To-Go Robot”, by Ozen Ozkaya.   The chapter explains how to write an video application that moves a robot from a video window using the mouse.

About this blog subject

This blog could easily generate at least 10 additional blogs.  I will make a series for the additional blogs and make this blog an overview, but I will spend more time talking about the software. Otherwise the blog will be too long for anyone to read.

The Setup for the AR Joystick

Here are the parts used.

  1. PC running Windows 10 x64
  2. OpenCV 3.2.0 – Aruco (Augmented Reality Library from the University of Cordoba)
  3. Visual Studio 2015 Community Edition
  4. An old CNC machine.
  5. Dynomotion KFLOP motion controller.
  6. Dynomotion Snap Amp DC Servo drive.
  7. Logitech WebCam
  8. 2 Laser Markers from Harbor Freight
  9. XBox Joystick.
  10. 3 AMT102 encoders.
  11. Power supply 24 VDC.

Refurbishing an old CNC machine

This is my 3rd machine that I have worked on.  Refurbishing the machine went faster than expected, because most of the parts were still working.  Only the DC Servo motors were outdated, they were using analog tachometers.  The tachometers were replaced with Encoders from CUI, Inc.

I used the Dynomotion KFLOP Motion Controller again for this project.  What is different with this new machine between the previous CNC machine?  I used the Dynomotion Snap Amp to drive the servo motors instead of the Gecko drives.  The Snap Amp was easier to use.

Writing the software for the AR Joystick

The AR joystick uses 2 programs; CNC Machine Client, and CNC Video Server program.  The client is written in C#.  The server is written in C++.  The server program tracks the markers to set up the origin, X and Y axes, and tells the client where to move.

CNC Machine Client program with the Xbox Game Controller.

The CNC Machine client software uses the Xbox Game Controller to move the machine.

The client moves the machine and displays the XYZ location.   When the client is connected to server, the server tells it where to move. When it is not connected to the server, Xbox joystick controls the client.  To connect the client to the server.  Hit the “Connect Pipe” button.

This is what the client looks like.

CNC Machine client

The CNC Video Server Program.

This is where the fun begins.  This is where we apply Augmented Reality and Robot Computer Vision to the project.

The “CNC Video Server” shows 2 images of the same scene.  The image on the right is the perspective view.  The image on the left is the 2D view.  The server acquires the video as shown on the right and transforms the image into 2D using the warpPerspective OpenCv command.

The image on the left is where the user controls the machine movements.  All the user has to do is click the mouse in the video and the machine moves!!

CNC Video Server

Augmented Reality ARUCO markers to move the machine

The main purpose of the server is to track 4 ARUCO Markers to set up a machine coordinate system based on their orientation.  Each marker has a specific purpose;

  • Marker 1 is the origin.
  • Marker 3 specifies the X-axis.
  • Marker 2 specifies the Y-axis.
  • Marker 4 is optional.

The green lines in the video are the X and Y axis.  The red lines you see are projected from the laser markers mounted to the machine.  These markers show the actual machine position in the live video.

Video Server 3D Perspective View

 

Video Server 2D View

 

The server aligns the perspective image into a 2D image.  The distance between the markers is known to the server.  It defines the scaling, pixels/mms, for each axis.

When the user clicks the mouse in the 2D window, the server detects the pixel XY location and converts XY pixels into inches.  Next the program sends XY values to the CNC Client.  When the client receives the XY values, it will move the machine in the specified XY coordinates.

Applying a perspective Transform and warping the Live Video.

The OpenCV Server displays 2 images of the same scene.  One window shows the perspective view the other shows a 2D view.  Here is the OpenCV snippet that transforms the video.

The vector pts_corners are the 4 center points of the AR markers in the perspective view.  The term “vector” refers to the C++ Standard Template Library data structure.

The vector pts_dst are the 4 center points of the AR markers but in the 2D view.  Both of these vectors are used to find the Homography matrix.  This matrix is used to map the 3D image onto a 2D image.

pts_corners.push_back(Point2f(average[0]));
pts_corners.push_back(Point2f(average[1]));
pts_corners.push_back(Point2f(average[2]));
pts_corners.push_back(Point2f(average[3]));

pts_dst.push_back(Point2f(80, 400));
pts_dst.push_back(Point2f(80, 80));
pts_dst.push_back(Point2f(500, 400));
pts_dst.push_back(Point2f(500, 80));

Mat h = findHomography(pts_corners, pts_dst);
warpPerspective(imageCopy, im_out, h, imageCopy.size());
imshow(“XYView”, im_out);

Handling Mouse Events in OpenCV

The OpenCV code snippet for handling mouse events is implemented by using a callback.  A callback is a pointer to a function.  When the user clicks the mouse in the 2D window, the server generates an event to the callback function to process.  The callback function returns the location of the mouse.  The code is very common on other blogs and articles.  The code will look like the following snippet.

setMouseCallback(“XYView”, CallBackFunc, &stagePt);
The callback function will look something like
void CallBackFunc(int event, int x, int y, int flags, void* ptr)
{
if (event == EVENT_LBUTTONDOWN)
{
// Do something
}
}

 

Details that I am leaving out for Now

I am leaving out a lot of details.  The details will be covered in the next blogs if someone want more information.  Otherwise the blog would be too long.

How to Use the Omron EE-SX671 Limit Switches (Part 2)

This article explains how to use these switches.

 

Creating ARUCO Markers for the Coordinate System (Part 3)

You will need to create the 3 or 4 markers for coordinate system.  For more information refer to OpenCV Basics 21-Aruco Marker Tracking on youtube.

 

Camera Calibration (Part 4)

Calibration is very important for software.  Without calibration the machine movements would not be as accurate.  For more information refer to OpenCV Basics 14-Camera Calibration on youtube.

 

Updating an Old CNC Machine:  Servo Tuning for KFLOP and Snap Amp (Part 5)

If anyone is interested in a blog about this subject let me know.

 

Video camera Controller

The camera is simple Logitech 1080p webcam.  It costs about $70.  To write software to control camera refer to the OpenCV Basics 12- Webcam & Video Capture on youtube.

 

Using Pipes to communicate between the programs.

The named pipes were used for the Client and Server to talk to each other.

 

Limitations:

I need to emphasize; THE SOFTWARE IS NOT PRODUCTION CODE.  I would not put the code in mission critical applications.  The software is only a prototype and was only written to prove a simple concept.  Also accuracy of the stage movements is not great.

Credits

AMT102 Encoders from CUI Inc.

George Lecakes – OpenCV Tutorial on YouTube.  I highly recommend these videos.  There are 21 videos each one is about 10 to 15 minutes long.

OpenCV Basics 01- Getting setup in Visual Studio 2015 for Windows Desktop.

OpenCV Basics 11- Building OpenCV Contribute to CMAKE.

OpenCV Basics 12- Webcam & Video Capture.

OpenCV Basics 14-Camera Calibration Part 1, Part 2, Part 3, Part 4

OpenCV Basics 21-Aruco Marker Tracking.

“Click-to-Go” Robot – Arduino Computer Vision Programming Chapter 9.

Software for the Xbox Game Controller.

* An event-driven C# wrapper for XInput devices.

* Author: Jean-Philippe Steinmetz <caskater47@gmail.com>

* Homepage: http://www.caskater4.com/engineering/xgamepad

Drawing maps with Robots, OpenCV and Raspberry Pi.  Chris Anderson

https://medium.com/@cadanderson/drawing-maps-with-robots-opencv-and-raspberry-pi-3389fa05b90f

 

Video of the AR Joystick

Posted in IOT (Internet Of Things)

A PLC (Program Logic Controller) that Talks and Sends Email

The following project occupied my time for a couple of weeks.  It required learning how to use a PLC (Program Logic Controller);  do embedded programming on the Arduino platform; send email using IOT (Internet of Things) 8266-12E Wifi Chip.  The project was fun and rewarding. but most of all would enhance the user experience of the CNC Mill.

After working with the CNC mill, you will discover that engraving patterns on wood takes a long time.   One pattern took about 3 hours to complete.  There is no need for me to watch the machine for 3 hours, but I needed to know when the job was done so I can turn off the machine.   Leaving the machine running by itself with a sharp router bit turning is dangerous and asking for disaster to happen.  So I needed a device that would detect when the CNC job was done and would notify me by email.

The project used an “Open Source” PLC to detect when the mill completed a job.   When a job completed, the PLC would play a loud message telling anyone in the vicinity that the job was done.  Next the PLC would tell the 8266 Wifi Internet chip to send an email notification to me.  If I was in the shop, I would know the jobs was done because I can hear the message.  Also, if I was not in the shop, I would know the job was done, by checking my email.

The PLC and 8266 Wifi Chip.

The PLC was purchased from Digital Loggers via Amazon.

https://www.amazon.com/enabled-Powerful-durable-Ardino-compatible/dp/B01BFV7O1U/ref=sr_1_1?ie=UTF8&qid=1491885779&sr=8-1&keywords=plc

The PLC is based on the Arduino Mega2650 which contains the following devices

  • Speakers
  • A touch screen,
  • LCD display.
  • ESP8266 Wifi chip, but we used another 8266 Dev Kit.
  • Digital and Analog Input/Outputs.
  • Relays.
  • Card reader
  • Serial and USB ports.

The NodeMCU LUA WiFi Internet ESP8266 Dev Kit was added to the project.  The ESP8266 on the PLC was not used, because the Dev Kit was more advanced.  The kit was purchased from HiLetGo via Amazon.

https://www.amazon.com/HiLetgo-Version-NodeMCU-Internet-Development/dp/B010O1G1ES/ref=sr_1_1?ie=UTF8&qid=1491886314&sr=8-1&keywords=hiletgo

Setting up the KFLOP to control GPIO.

The CNC machine communicates to the PLC by hooking up an output of the CNC machine to an input of the PLC.  The CNC machine was configured so that the command M30 would set the IO26 state HIGH when executed.  Also the PLC was programmed to detect the state of the input signal.  The KMotionCNC.exe application allows you the configure the IO as shown below;

Also you must also modify the InitKStep3Axis.c program for the KFLOP to configure IO26 bit.  The program is located under C:\KMotion433\C Programs\KStep directory.  If you are using the PWM to control your servos, you will need to change a different program.

You need to add the 2 lines of code.

SetBitDirection(26,1);  // set Enable Signal as Output
SetStateBit(26, 0);        // the Signal is set LOw

Here is the code program that executes the M30 command.  The program was shortened for demonstration purposes.

When command is executed, the KFLOP will set the output state to HIGH.

Setting up the CNC Mill to the PLC and the 8266 NodeMcu Dev Kit

The setup is made up of the

  • PLC
  • 8266 NodeMcu Dev Wifi Internet Kit
  • Phone to detect the email.
  • A 3.3 V volt regulator was used, because the GPIO pins on the PLC and 8266 can only handle 3.3V signal levels.

In other words if you use a higher voltage, you will damage the part.  Do not use 5v on the 3.3v GPIO.

Theory of Operation

Hopefully this is the simplest explanation.  The PLC is connected to the CNC mill via GPIO (General Purpose Input Output).  To send email, the PLC sends a signal to the 8266 Nodemcu Dev Kit.  The implementation incorporates the following steps.

  1. After the CNC mill has finished a job, the G-Code program executes M30 to send a signal to the PLC.
  2. The PLC detects when the signal goes HIGH, then the PLC sends a signal to the 8266.
  3. The 8266 detects when the signal goes HIGH, then the 8266 logins into the Wifi and sends the email notification.

Connecting the KFLOP to PLC

To connect the KFLOP GPIO to the PLC, simply use a 2 conductor wire.  One side goes to ground of the KFLOP and PLC.  The other side goes from JP6 pin 5 (IO26) to IN-31 of the PLC.  When the signal changes the state from LOW to HIGH, the PLC plays a message “Your CNC job is done.  Please check your email for the notification.  Thanks you”.  The message ends with the Ferris Bueller “Oh Yeah”

Connecting the PLC to 8266 NodeMcu Dev Kit

To connect the PLC to the 8266, simply connect Digital Output 38 of the PLC to the Digital Input 16 which is connected to pin D0.

References for the NodeMCU-DEVKIT-V1.0 (8266-ESP12E based).

There are infinite number of the references on the chip but I will show a few.  The dev kit was less than $10 dollars on the Amazon.  I started using the ESPlorer and then moved on the Arduino.  There are many libraries implemented by the Arduino.

  1. NodeMCU-DEVKIT-V1.0 – https://github.com/nodemcu/nodemcu-devkit.
  2. Tutorial for the 8266 – http://www.kloppenborg.net/blog/microcontrollers/2016/08/02/getting-started-with-the-esp8266.
  3. Tutorial to setup the Arduino IDE to develop software on the 8266-http://www.instructables.com/id/Programming-ESP8266-ESP-12E-NodeMCU-Using-Arduino-/

A Video of a PLC (Program Logic Controller) that Talks and Sends Email

Hope you like the video.

Posted in CNC Router

DIY CNC Engraving with the KFLOP and CAMBAM

Hello, I am back again.  I was side-tracked working on an Open Sourced PLC which I will cover in another post.  This post is about engraving patterns using your DIY CNC Mill with the KFLOP and CAMBAM.  CAMBAM has a feature to engrave patterns easy by simply opening a bitmap into CAMBAM.  It is so easy, a Caveman can even do it.  When you open a bitmap in CAMBAM, CAMBAM converts the edges in the image to a polyline.  I have provided the instructions and video to do the engravings.

How to open an Image in CAMBAM.

In this section I used the Boston Marathon logo as an example.  The logo looked like a fun project to do.  Also, I am a runner.  My wife and I ran the marathon in 2013.  Here are the following steps.

Step 1. Open the image from the “HeightMap Generator” under the CAMBAM “Plugins” menu as shown below;

Step 2.   Open the image into CAMBAM

Step 3.  Set your “HeightMap Generator” options.

Be aware that the XStep and YStep size are important.  The smaller size produces a better engraved image, but it takes the machine longer to carve the pattern.  A 4″ x 4″ piece of wood with a 0.04″ step size and feedrate 6″ inch/min will take about 2 hours.  With a 0.02″ step size, the same part will take over 3 hours.  This blog will show the difference between the engravings.

 

Step 4.  Generate the HeightMap

Step 5.  Generate the Tools paths and G-Code.

Video of CAMBAM generating G-Code from a Bitmap.

The video below will show you how to generate G-Code from the “HeightMap Generator” in CAMBAM.

 

 

Video of the CNC Mill engraving the Image on wood.

This video shows how the machine engraves the Boston Marathon Logo on the a CNC machine.  The CNC machine is using the Dynomotion KFLOP to perform the engraving

.  CAMBAM generated the G-Code from a Bitmap.

Final Products.

Before, I engraved the Boston Marathon Logo, I started with a business card to test the first engraving.  I took a photo of the business card and converted it to a black/white bitmap.  The black/white bitmap seemed work better than the color.

The business card is from Run 26 which is a running store in Mill Creek Washington.  If you want to get in shape for long distance running, this is the store.  They can help you select the right gear for you to start running.  They cater to all runners;  fast and slow, old and young.  The owner is a awesome and knowledgeable coach.

Engraving with different Step sizes.

The step size determine the quality of the engraving.  The image on the left was engraved with the steps sizes set to 0.04″ for both X and Y.  The image on the right was used 0.02″ for both X and Y, but took over 3 hours.  The engraving process was stopped after 3 hours.  It would have taken another hour.

If you have any questions or comments please contact us.

Also best of luck to the runners in the Boston Marathon tomorrow April 17, 2017.

 

Posted in CNC Router

An Affordable DIY Manual Mill CNC conversion with the KFLOP

The purpose of this post is to present an Affordable DIY Manual Mill CNC conversion using the KFLOP Motion Controller.  If you look on the web site, https://www.automationtechnologiesinc.com/, you can get most of the parts for under a thousand dollars.  You will have to buy the KFLOP from another vendor, because Automation Technologies does not sell the KFLOP.

item Description Price Total
1 KFLOP Motion Controller 249 249
3 Gecko Servo Amplifiers 114 342
3 Motors 350 oz-inch 79.95 239.85
3 AMT Encoders 38.95 116.85
947.7

Once you have the parts for the 3 axis machine, you will need to figure out a way to connect the motor to the machine.   This is only an estimate based on the following components.

  1. 2 timing belt pulleys (around $12 each),
  2. 1 timing belt around $15.
  3. 1 idler pulley and tighter around $100.
  4. 6″ x 24″ x 1/2″ aluminum around $40.
  5. 1 clamp to idler.

It will cost about $500 for the 3 axes.

If you have a machine shop or have access to one and you do the work yourself, your CNC Conversion cost is about $1,500.  However, this is excluding the cost of the CAD/CAM software.

Just for review, CNC stands for Computer Numerical Control.   A computer controls the movement of the Mill.  The CNC machine operates by the user doing the following steps;

  • Set the part onto a fixture with respect to work and tool offsets.
  • Load a G-Code program, to make the part, into the CNC control software.
  • Runs G-Code to machine the part.

I will explain more about the G-Code.

G-Code.

The g-code files tells the machine what to do and where to move.  You can find a good overview of G-code at this link

http://www.cnccookbook.com/CCCNCGCodeRef.html

G-code commands can be classified as Motion, Coordinate, Compensation, and Canned commands.  The most common Motion commands are G0, G1, G2, G3;

  • G0 – Tells the machine to move to a position XYZ.  The move is not in a straight line.
  • G1- Tells the machine to move linearly to a position.  During a linear move the mill move in a straight line.  Each axis moves and stops at the same time.  It is also known a coordinated move.
  • G2, G3 Tells the machine to move in a circular motion.

The Coordinate type commands would be G17, G18, G19 which allows you to select XY Plane, YZ Plane, ZX Plane respectively. 

The Compensation type commands such as G52 to G59 are used to set work and tool offsets on the machine.  

Canned commands such as, but not limited, G81 to G89 are used for drilling, boring, tapping.

This paragraph is only scratches the surface about G-code.  Refer to the above link for more details.

The CNC mill conversion 2.0 using the KFLOP

If you have read my post “DIY CNC Demo Using CAMBAM”, you would recognize that the new mill uses a lot of the mechanical parts from the old mill.  The old mill was prototype to verify that the design worked as expected.  It can do quite a bit of tasks, but it can only handle small jobs, because the motors are smaller and low power.  The new mill is larger and suited for industrial applications, and it uses larger motors.  The newer mill incorporates the same mechanical design, but it will also have;

  • New Servo Motors-sized better for the larger Mill/Drill.
  • New Motion Controller Card (Dynomotion KFLOP).
  • 3 Gecko G-320X Servo Amplifiers.
  • 3 additional mounting plates to connect the motor assemblies to the machine.

Originally, I was going to use the Gecko amplifiers with the Kerr Motion Control Cards, but I was not sure if they were compatible.  Besides I wanted to try something new and experience the KFLOP in action.

Old CNC Mill

 

New CNC Mill

 

The Dynomotion KLOP Motion Controller

The KLOP motion controller was recommended to me by a friend (Eric) at work.  Eric’s CNC mill broke down and he was going to fix it using the KFLOP.  He decided to use the KFLOP, because the parts for his old mill were too expensive.  He encouraged me to buy the KFLOP, so I bought the KFLOP.  I discovered that the KFLOP has a lot of nice features;

  • Controls up to 8 Axis Servo or Stepper motor.
  • USB interface.
  • Provides a G-Code Interpreter (Open source).
  • Provides good software examples.  The application KMotionCNC.exe, provided with the samples,  is a complete CNC solution.
  • The software can also be used by the .NET Framework.
  • Provides good documentation.
  • Only costs $250.
  • You can use a Game Console to move the stage.

The new mill requires 1 KFLOP motion Controller, 3 Gecko Servo Amplifiers and 3 Servo motors with encoders.   As shown below, each axis requires 1 servo motor.

Each motor uses an Incremental Encoder.  I recommend purchasing the encoders from US digital or AMT CUI INC.  I favor the encoders from AMT CUI INC because of the cost/performance ratio.  Check the prices for both manufacturers.  If you want a 2048 count encoder from US Digital it will cost about $76.  The similar product from AMT CUI INC would cost around $23.  If you are going to sell the CNC machines professionally you might consider US Digital.

KFLOP and Gecko Servo Amplifiers

 

Attaching the Motors to the machine.

Attaching the motors to the Milling machine took some thought.  This task required drilling 7 holes into the machine itself; 2 holes for the x-axis; 2 holes for the y-axis, and 3 for the z-axis.  It was a dreaded task.  Potentially ruining your machine is not a good feeling to have.

I don’t guarantee this is the best and only way, but it works.  Each axis required an additional mounting plate to connect the motor assembly.  Also, spacers were required between the mounting plate and the machine so the timing belt would be parallel to the motor assembly.  You will see this in the annotated X-Axis image.  The Z-Axis did not require spacers.  You will also see an annotated Z-Axis image.

Additional Machining for the X, Y and Z axis pulleys

Both the X and Y axes use a 2 ¼“ diameter pulley that needed modifications.  The bore diameters needed to be expanded from ¼“ to 7/10”.  To increase the bore diameter, I recommend using a boring head rather than using a drill bit.  Finding a drill bit with the exact diameter takes time.  When you re-drill the bore with a drill bit, the bit will make the hole off centered.  So when the pulley turns it will wobble.  Using the bore head does not have this problem.  The bore head can be adjusted easily for any size diameter.

The pulleys hubs needed to be machined so they would lock onto the axis of the mill.  If you remove the crank handle from the XY Table; this what the pulley needs attach to. 

Location to attach the Axis pulley

 

The modified pulley has a larger bore diameter and the hub was machine to interlock with the axis.  Basically you use a smaller end mill and cut straight across the hub.  The first cut is easy.  The second cut requires you to measure the arc distance on the mill axis.

 

Axis Pulley Interlocking with the Axis

The pulleys and timing belts were purchased from “Stock Drive Products and Sterling Instruments”.

The tools such as the bore head, end mill, drill bits were purchased from MSC Industrial.

 X-Axis Motor Assembly

 

 Y-Axis Motor Assembly

The work on the Y-Axis required the same work as the X-Axis.  The only difference is the mounting plate and the length of the spacers.

Y-Axis

 Z-Axis Motor Assembly

Attaching the Z-Axis motor assembly was about the same effort.  The assembly required; an additional mounting plate, extra shaft extended, and a shaft coupler.  Spacers were not needed.

Parts needed to attach the Z-Axis

 

Adjusting the PID (Proportional–Integral–Derivative) settings for each  Servo Motor Drive.

Setting these values were tricky at first.  It is best to start adjusting 1 motor without it attached to the machine.  Basically, adjust the PID values, on the Gecko amplifier, to the lowest settings.  Follow the instructions provided by Gecko.  Once you have the power and encoder lines hooked up to the amplifier, apply the minimum 18 volts.  It is best to start with the lower voltage, because the motor oscillations tend be worse with larger voltages.  Increase the voltage until the motors start oscillating.  Adjust the PID settings by turning the potentiometer on the side of the amplifier.  The “P”, “I”, and “D” are marked on the side of the amplifier.

  1. Turn the potentiometer for “P” so the oscillation stops and the motor is only humming.
  2. Turn the potentiometer for “D” so the humming decreases.
  3. Turn the potentiometer for “I” so the humming decreases even more.

After you connect the motors to the machine you might need to readjust the PID settings.  I ran into this problem when I was trying to control the machine.  The motor would move the machine in one direction without problems, but it vibrate in the reverse direction.

Creating the Initialization code for the KFLOP.

This section covers setting up the machine configuration, input/output channels, limit switch options.  The objective is to provide an overview of creating the “Initialization code” rather than repeat the manual.   The KFLOP user manual covers the task in detail.  

The main part to remember is to get the “Configuration”, and the “Step Response” Dialogs.  Both of these dialogs need to be open.  Select the menu options as shown in the image below.

Kmotion “Config & Flash” and “Step Response” Menu

On the dialog you will need to set the following.  This assumes your amplifier is setup for “Step” and “Dir” mode.

  • Hit the “Load Channel” button select KStepAxis0.mot for x-axis.
  • Set the Channel number.  For the x-axis it will be 0.
  • Set the Axis Mode as shown below.
  • Set your Input/output Channels.
  • Set the IO numbers for the limit switches.  This can be done later.
  • On the Step Response dialog set your PID, velocity and acceleration.
  • Hit the move button to set the step response.
  • Repeat for each axis.

Configuration Dialog

 

Step Response Dialog

  • Next, on the Kmotion.exe, hit the “C Programs” button.  Load a default program such as C:\KMotion433\C Programs\KStep\InitKStep3Axis.c

C Programs Dialog

  • Save the program as another program such as InitKStep3Axis-12-22-2016.c.
  • From the “Configuration” dialog hit “Export All to Open C Program” to update your setup C program.

Remember the name of the C program that you saved.  You will read this program from the KMotionCNC.exe.

YouTube has a good video for the KFLOP – “KSTEP Introduction – Getting Started with KSTEP Stepper Driver”

KMotionCNC application.

This application is a complete CNC solution.  The application provides a CNC Control Panel, G-Code Interpreter, G-Code Viewer.  The YouTube video, “KSTEP Introduction – Getting Started with KSTEP Stepper Driver”, and KFLOP user manual explains the application in detail.

The “INIT” button calls the C program that you saved in the previous section.  The video show you how to set the button to point to the C code.

KMotionCNC

 

Video of the New CNC Mill in Action.

The new mill uses the old mechanical design from the previous CNC mill.  Just to reiterate the machine uses the following parts;

  • KFLOP Motion Controller from Dynomotion.
  • Gecko g-320X Servo Amplifiers.
  • Servo Motors (300 oz/in XY axis, 240 oz/in for Z axis).
  • Encoders came with the YX motors.  Only the z-axis required a new encoder from AMT CUI.
  • XBox Joystick

The following video will show you how to run the KMotionCNC.exe application.

Xbox JoyStick

Video Of the Retrofitted Mill

If you have any questions or comment please let me know.