运动平台:日脉的二维运动平台(一个旋转平台和一个滑动平台)

开发环境:VS2010 + .NET Framework + VB.NET

使用文件:pci_8158.vb

motion_8158_2D.vb

2D平台运动类

Public Class motion_8158_2D

    Public CardId As Integer
'move parameter here
'AxisNo is 0 or 1
Public AxisNo As Short
'Dist : mm
Public Dist As Double
'StrVel : mm/s
Public StrVel As Double
'MaxVel : mm/s
Public MaxVel As Double
'Tacc : s
Public Tacc As Double
'Tdec : s
Public Tdec As Double Public Sub New(ByVal cardId1 As Integer)
CardId = cardId1
End Sub Public Sub New(ByVal axisNo1 As Short, ByVal dist1 As Double, ByVal strVel1 As Double, ByVal maxVel1 As Double, ByVal tacc1 As Double, ByVal tdec1 As Double)
AxisNo = axisNo1
Dist = dist1
StrVel = strVel1
MaxVel = maxVel1
Tacc = tacc1
Tdec = tdec1
End Sub Public Sub CardRegedit_8158_2d() Dim code As Integer
code = B_8158_initial(CardId, )
'set axis num 0
B_8158_set_move_ratio(, )
B_8158_set_pls_outmode(, )
B_8158_set_servo(, ) 'set axis num 1
B_8158_set_alm(, , )
B_8158_set_inp(, , )
B_8158_set_move_ratio(, )
B_8158_set_pls_outmode(, )
B_8158_set_move_ratio(, ) 'code = B_8158_config_from_file()
'the axis num of x axis linear motion is 0
'the axis num of Ry axis ratary motion is 1 'Is has 8158 card 's drive
If (code <> ) Then
MsgBox("No 8158 Card exit!")
B_8158_close()
End If 'configure the input mode of external feedback pulse
B_8158_set_pls_iptmode(, , )
'set counter input source
B_8158_set_feedback_src(, )
End Sub Public Sub LinearMotion()
Dim pulse_dist As Double = Dist *
Dim pulse_strVel As Double = StrVel *
Dim pulse_maxVel As Double = MaxVel *
B_8158_start_tr_move(AxisNo, pulse_dist, pulse_strVel, pulse_maxVel, Tacc, Tdec)
End Sub Public Sub RotateMotion()
'rotation stage dec radio 1/5
Dim pulse_dist As Double = Dist * /
Dim pulse_strVel As Double = StrVel * /
Dim pulse_maxVel As Double = MaxVel * /
B_8158_start_tr_move(AxisNo, pulse_dist, pulse_strVel, pulse_maxVel, Tacc, Tdec)
End Sub Public Function GetLinearSpeed() As Double
Dim s As Double
B_8158_get_current_speed(, s)
GetLinearSpeed = s /
End Function Public Function GetRotSpeed() As Double
Dim s As Double
B_8158_get_current_speed(, s)
GetRotSpeed = s * /
End Function
End Class

新开辟一个线程,用While循环控制连续运动主窗体程序:

用事件委托的方法,向TextBox中写入数据

''' <summary>
''' aging motion control test software at 20130819
''' mail:bin___03@163.com
''' </summary>
''' <remarks></remarks>
''' Public Class Form1
'Control motion manually
Delegate Sub UpdateLogCallback(ByVal [text] As String)
Private manualMotion As Boolean = False
Dim MotionThread As System.Threading.Thread
Dim objMotion As motion_8158_2D = New motion_8158_2D()
Dim timeBegin As Date
Dim timeEnd As Date
Dim boolDuration As Boolean = False
Dim log As IO.StreamWriter
Dim logFileName As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MaximumSize = Me.Size
Me.MinimumSize = Me.Size objMotion.CardRegedit_8158_2d() End Sub Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
timeBegin = DateTime.Now
boolDuration = True
'MsgBox(timeBegin.ToString("yyyyMMddHHmmss"))
logFileName = timeBegin.ToString("yyMMddHHmmss") & ".txt"
log = New IO.StreamWriter(logFileName, True) manualMotion = True
btnStop.Enabled = True
btnStart.Enabled = False
tsslMovingStatus.Text = "moving..."
txtLog.Clear() MotionThread = New System.Threading.Thread(AddressOf ContinuuousMotion)
MotionThread.Start() End Sub Private Function isStopMotion() As Boolean
isStopMotion = True
For i = To
Dim temp As Short = B_8158_motion_done(i)
If B_8158_motion_done(i) <> Then
isStopMotion = False
Exit For
End If
Next
Return isStopMotion
End Function Sub ContinuuousMotion()
Dim objRandom As Random = New Random()
Dim tilt_old As Double =
Dim tilt_new As Double
'MsgBox(manualMotion)
While True If manualMotion Then
Exit While
End If End While While manualMotion
Dim rdn As Double = objRandom.NextDouble
If rdn <= 0.5 Then
tilt_new = - * rdn
Else
tilt_new = * rdn
End If Dim strLog As String =
">> " & DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") & "TILT:" & tilt_new.ToString & vbCrLf
UpdateLog(strLog)
log.Write(strLog) Threading.Thread.Sleep()
' rotate
objMotion = New motion_8158_2D(, tilt_new - tilt_old, , , 0.05, 0.05)
objMotion.RotateMotion() 'waiting for the motion stopped
While True
If isStopMotion() Then
Exit While
End If
End While Threading.Thread.Sleep()
'acc = 0.18g for 100mm for linear stage
objMotion = New motion_8158_2D(, , , , 0.05, 0.05)
objMotion.LinearMotion() 'waiting for the motion stopped
While True
If isStopMotion() Then
Exit While
End If
End While Threading.Thread.Sleep()
'acc = -0.18g for 100mm for linear stage
objMotion = New motion_8158_2D(, -, , , 0.05, 0.05)
objMotion.LinearMotion() 'waiting for the motion stopped
While True
If isStopMotion() Then
Exit While
End If
End While tilt_old = tilt_new
End While
End Sub Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
boolDuration = False
manualMotion = False
btnStop.Enabled = False
btnStart.Enabled = True
tsslMovingStatus.Text = "stoped..."
UpdateLog(Application.StartupPath & "\" & logFileName)
log.Dispose()
log.Close()
MotionThread.Abort() B_8158_stop_move_all()
For i = To
B_8158_emg_stop(i)
B_8158_set_motion_int_factor(i, )
Next
B_8158_int_control(, )
End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
txtLinearSpeed.Text = objMotion.GetLinearSpeed.ToString
txtRotSpeed.Text = objMotion.GetRotSpeed.ToString If boolDuration Then
'start button and stop button control boolDuration parameter
timeEnd = DateTime.Now
'timespan format write to duration time text
txtDurationTime.Text = (timeEnd - timeBegin).ToString("hh\:mm\:ss\.ff")
End If End Sub Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Try
B_8158_stop_move_all()
B_8158_close()
MotionThread.Abort()
log.Dispose()
log.Close()
Catch ex As Exception End Try End Sub Private Sub UpdateLog(ByVal [text] As String)
If InvokeRequired Then
Dim d As New UpdateLogCallback(AddressOf UpdateLog)
Me.Invoke(d, New Object() {[text]})
Else If txtLog.Lines.Count > Then
txtLog.Clear()
End If
txtLog.AppendText([text])
End If
End Sub End Class

工程文件下载页:http://download.csdn.net/detail/asan2006/5993907

ADLINK 8158控制程序-连续运动(VB.NET)的更多相关文章

  1. 第三期 第三期 搜索——1.运动规划(motion_planing)

    运动规划的根本问题在于机器人可能存在于一个这样的世界中, 它可能想找到一条到达这个目标的路径,那么就需要指定一个到达那里的计划, 自动驾驶汽车也会遇到这个问题.他可能处于高速公路的附近的街道网络中,他 ...

  2. [ios学习笔记之视图、绘制和手势识别]

    一 视图 二 绘制 三 手势 00:31 UIGestureRecognizer 抽象类 两步 1添加识别器(控制器或者视图来完成) 2手势识别后要做的事情 UIPanGestureRecognize ...

  3. A simple test

        博士生课程报告       视觉信息检索技术                 博 士 生:施 智 平 指导老师:史忠植 研究员       中国科学院计算技术研究所   2005年1月   目 ...

  4. 标准C函数库的使用方法

    本篇介绍若干经常使用的标准C函数的使用方法,主要介绍stdio(标准输入输出).math(数字函数库).time(时间函数库).stdlib(标准函数库)string(标准字符串函数)等. 最后更新  ...

  5. WEB烟花效果——Canvas实现

    摘要        本文主要介绍一种WEB形式的烟花(fireworks)效果(图1所示),该效果基于Canvas实现,巧妙地运用了canvas绘图的特性,并加入了物理力作用的模拟,使整体效果非常绚丽 ...

  6. search

    |—search()—|—添加一个列表变量Expend,存储每个小格扩展时为第几步,可打印出 |                    |—打印运动表 |—A*—|— heuristic() |—Dy ...

  7. 闵可夫斯基和(Mincowsky sum)

    一.概述 官方定义:两个图形A,B的闵可夫斯基和C={a+b|a∈A,b∈B}通俗一点:从原点向图形A内部的每一个点做向量,将图形B沿每个向量移动,所有的最终位置的并便是闵可夫斯基和(具有交换律) 例 ...

  8. 3.定时器的使用(以通俗易懂的语言解释JavaScript)

    1.定时器的作用: 开启定时器:setInterval -->间隔型 setTimeout -->延时型 区别:setInterval会一直执行,应用如微博间隔一段时间不断请求后台数据,看 ...

  9. CSS3帧动画

    在前面的文章中也有介绍过css3动画的内容,可见<关于transition和animation>和<webkitAnimationEnd动画事件>,今天又要唠叨一下这个东西了, ...

随机推荐

  1. 去除VS2010中中文注释下的红色波浪线

    1,中文注释以分号结尾 2,Assist X 菜单栏->Assist X Option->Underline 选择“min”.

  2. .net 实例化对象

    定义TestClass,在调用的地方 TestClass a; 如果下面有引用 a.Property,VS会报错,而如果 TestClass a = null; 再次调用的话则不会报错. TestCl ...

  3. VLAN间通信----实验

        方法1.增加物理线路     需求:PC0连接SW的F0/1,PC1连接SW的F0/2; SW创建VLAN10,VLAN20; PC0划到VLAN10; PC1划到VLAN20; 现要求借用路 ...

  4. 【深入浅出jQuery】源码浅析2--使用技巧

    最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...

  5. GPIO模拟串口注意是事项

    GPIO模拟串口需要注意的事项如下:(程序见我的博客第一篇) 1.由于串口是异步通信,则串口发送必须满足宽度要求. (1)假设串口的波特率是9600bps(1s传输9600个bit),则传输1bit需 ...

  6. Delphi调用WINAPI时到底应该是指针还是结构体(注意是Delphi变量本身就是指针)

    看MSDN,GetWindowRect的说明如下: BOOL WINAPI GetWindowRect( _In_  HWND   hWnd, _Out_ LPRECT lpRect // 注意,没* ...

  7. 追踪CM_CONTROLCHANGE消息的产生和执行过程,可以较好的领会VCL的思想(就是到处通知,但耦合性很弱)

    追踪CM_CONTROLCHANGE消息的流向,可以较好的 测试代码: procedure TForm1.Button1Click(Sender: TObject);var Image2 : TIma ...

  8. List、Set、 数组等转字符串

    public class Test { public static void main(String[] args) { String str = ""; // list转字符串 ...

  9. c++实现委托

    #include "stdafx.h" #include <iostream> #include <string> using namespace std; ...

  10. Vi的几种退出方式

    1.q 退出 2.w 保存,继续操作 3.wq 保存退出 4.q! 不保存,放弃修改 5.x 同wq相似,但又有区别 wq   强制性写入文件并退出.即使文件没有被修改也强制写入,并更新文件的修改时间 ...