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.