Homing

Moderators: TomKerekes, dynomotion

Post Reply
garytom
Posts: 5
Joined: Sat Jan 05, 2019 10:46 am

Homing

Post by garytom » Thu Mar 07, 2019 2:27 pm

Hello

Could anyone assist me in implementing homing sequence for a 2 axis machine,
Version of Kflop 1.2 ,Kmotion434, PC VB example Dynomotion dotNet
I have written code for reading corresponding bits of each axis and if high proximity sensor is activated.

Regards
Gary

Moray
Posts: 83
Joined: Thu Apr 26, 2018 10:16 pm

Re: Homing

Post by Moray » Thu Mar 07, 2019 5:50 pm

Can you post what code you've already written?

garytom
Posts: 5
Joined: Sat Jan 05, 2019 10:46 am

Re: Homing

Post by garytom » Thu Mar 07, 2019 8:05 pm

Hello Moray
Thanks for reply
I have only got to stage of reading state of bits


VB.net Form Code:

Public Sub HomeMotors()

If updating = False Then ' Move X and Y motors to proximity sensors
SendCommand = (String.Format("MoveXYZABC" & " " & "-50.0 -50.0 0.0 0.0 0.0 0.0"))
device.ProcessCommandXY(SendCommand)
SendCommand = ""
End If

End Sub

Private Sub btnHome_Click(sender As Object, e As EventArgs) Handles btnHome.Click

btnRight.Enabled = False
btnUp.Enabled = False
btnDown.Enabled = False
btnLeftDownNudge.Enabled = False
btnRightUpNudge.Enabled = False
btnLeft.Enabled = False
btnLeftUpNudge.Enabled = False
btnDownRightNudge.Enabled = False
btnZDown.Enabled = False
btnZUp.Enabled = False

HomeMotors()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

updating = True
device.UpdateValues()
XPosition.Text = Format(Val(device.XPosition), "0.00")
YPosition.Text = Format(Val(device.YPosition), "0.00")
' ZPosition.Text = Format(Val(device.ZPosition), "0.00")

If device.XPosition = 0 AndAlso device.YPosition = 0 Then
btnRight.Enabled = True
btnUp.Enabled = True
btnDown.Enabled = True
btnLeftDownNudge.Enabled = True
btnRightUpNudge.Enabled = True
btnLeft.Enabled = True
btnLeftUpNudge.Enabled = True
btnDownRightNudge.Enabled = True
btnZDown.Enabled = True
btnZUp.Enabled = True
End If

txtXPulses.Text = device.XPosition * 12.78
txtYPulses.Text = device.YPosition * 12.78

chkEnableX.Checked = device.XEnabled
chkEnableY.Checked = device.YEnabled
' chkEnableZ.Checked = device.ZEnabled

If MovingXAxis Then
responseX = device.ResponseX
End If
If MovingYAxis Then
responseY = device.ResponseY
End If

If device.ReadBit4 = True Then ' X axis bit4 state
ChkLimitX.CheckState = CheckState.Checked
Else
ChkLimitX.CheckState = CheckState.Unchecked
End If

If device.ReadBit5 = True Then ' Y axis bit5 state
ChkLimitY.CheckState = CheckState.Checked
Else
ChkLimitY.CheckState = CheckState.Unchecked
End If

updating = False

' draw rectangle shape
If rubberBanding Then
Panel1.Invalidate()
End If

End Sub
-----------------------------------------------------------------------------------------------------------


Public Class DynoMotionVBnetProvider code:

Public Sub UpdateValues()

' check if the board is available
If (_Controller.WaitToken(100) = KMotion_dotNet.KMOTION_TOKEN.KMOTION_LOCKED) Then
_Controller.ReleaseToken()

Try
_XPosition = Convert.ToDouble(_Controller.WriteLineReadLine("Dest0") / _Controller.CoordMotion.MotionParams.CountsPerInchX) * 25.4
_YPosition = Convert.ToDouble(_Controller.WriteLineReadLine("Dest1") / _Controller.CoordMotion.MotionParams.CountsPerInchY) * 25.4
'_ZPosition = Convert.ToDouble(_Controller.WriteLineReadLine("Dest2") / _Controller.CoordMotion.MotionParams.CountsPerInchZ)* 25.4


_ResponseX = _Controller.WriteLineReadLine("CheckDone0")
_ResponseY = _Controller.WriteLineReadLine("CheckDone1")
_ResponseXY = _Controller.WriteLineReadLine("CheckDoneXYZABC")

_XEnabled = Convert.ToDouble(_Controller.WriteLineReadLine("Enabled0"))
_YEnabled = Convert.ToDouble(_Controller.WriteLineReadLine("Enabled1"))
' _ZEnabled = Convert.ToDouble(_Controller.WriteLineReadLine("Enabled2"))

_ReadBit0 = Convert.ToDouble(_Controller.WriteLineReadLine("ReadBit0")) ' laser
_ReadBit1 = Convert.ToDouble(_Controller.WriteLineReadLine("ReadBit1")) 'sandblaster
_ReadBit2 = Convert.ToDouble(_Controller.WriteLineReadLine("ReadBit2")) ' vacuum
_ReadBit4 = Convert.ToDouble(_Controller.WriteLineReadLine("ReadBit4")) ' X Axis homing
_ReadBit5 = Convert.ToDouble(_Controller.WriteLineReadLine("ReadBit5")) ' Y Axis homing

Catch ex As KMotion_dotNet.DMException
MessageBox.Show(ex.InnerException.Message(), "Dynomotion")
End Try

End If

End Sub

Public Sub ProcessCommandXY(ByVal sCommand As String)
WriteLineException(sCommand)
End Sub

Moray
Posts: 83
Joined: Thu Apr 26, 2018 10:16 pm

Re: Homing

Post by Moray » Thu Mar 07, 2019 9:21 pm

I've just realised you posted in the User PC Apps forum.

You'll need to do the actual homing routine using a C program, as the lag between PC and KFlop is to slow to detect bit changes quickly (IIRC it's around 10Hz), unless you run homing at a very slow speed.

Easiest option is to create a couple basic C programs that you download and run depending on axis being homed, and have them set a couple virtual bits once homing is complete, and have your PC app monitor the virtual bits so it knows when homing is complete.

User avatar
TomKerekes
Posts: 320
Joined: Mon Dec 04, 2017 1:49 am

Re: Homing

Post by TomKerekes » Thu Mar 07, 2019 9:36 pm

Hi Gary,

You might also see the SimpleHomeIndexFunctionTest.c example.
Regards,

Tom Kerekes
Dynomotion, Inc.

garytom
Posts: 5
Joined: Sat Jan 05, 2019 10:46 am

Re: Homing

Post by garytom » Thu Mar 07, 2019 10:29 pm

Hello Moray

Thanks for your help

Regards
Gary

garytom
Posts: 5
Joined: Sat Jan 05, 2019 10:46 am

Re: Homing

Post by garytom » Fri Mar 08, 2019 12:17 am

Hello Tom

Thank you for reply, i have taken a look at file.
I only have basic knowledge of vb.net.
as file is c code how do i use file within vb.net program or do i need to convert c file to vb.net?
please excuse my lack of understanding

Regards
Gary

User avatar
TomKerekes
Posts: 320
Joined: Mon Dec 04, 2017 1:49 am

Re: Homing

Post by TomKerekes » Fri Mar 08, 2019 2:37 am

Hi Gary,

Any homing program needs to be written in C and executed in KFLOP.

You can debug the program using KMotion.exe C Program Screen. Then after it is working you can Compile/Load/Run the program in KFLOP with a single function call from your VB.net program to our .NET Library. See this .NET function.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

garytom
Posts: 5
Joined: Sat Jan 05, 2019 10:46 am

Re: Homing

Post by garytom » Fri Mar 08, 2019 1:07 pm

Hello Tom

Thanks for your help.

Regards
Gary

Post Reply