ADLINK 8158控制程序-连续运动(VB.NET)
运动平台:日脉的二维运动平台(一个旋转平台和一个滑动平台)
开发环境: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.运动规划(motion_planing)
运动规划的根本问题在于机器人可能存在于一个这样的世界中, 它可能想找到一条到达这个目标的路径,那么就需要指定一个到达那里的计划, 自动驾驶汽车也会遇到这个问题.他可能处于高速公路的附近的街道网络中,他 ...
- [ios学习笔记之视图、绘制和手势识别]
一 视图 二 绘制 三 手势 00:31 UIGestureRecognizer 抽象类 两步 1添加识别器(控制器或者视图来完成) 2手势识别后要做的事情 UIPanGestureRecognize ...
- A simple test
博士生课程报告 视觉信息检索技术 博 士 生:施 智 平 指导老师:史忠植 研究员 中国科学院计算技术研究所 2005年1月 目 ...
- 标准C函数库的使用方法
本篇介绍若干经常使用的标准C函数的使用方法,主要介绍stdio(标准输入输出).math(数字函数库).time(时间函数库).stdlib(标准函数库)string(标准字符串函数)等. 最后更新 ...
- WEB烟花效果——Canvas实现
摘要 本文主要介绍一种WEB形式的烟花(fireworks)效果(图1所示),该效果基于Canvas实现,巧妙地运用了canvas绘图的特性,并加入了物理力作用的模拟,使整体效果非常绚丽 ...
- search
|—search()—|—添加一个列表变量Expend,存储每个小格扩展时为第几步,可打印出 | |—打印运动表 |—A*—|— heuristic() |—Dy ...
- 闵可夫斯基和(Mincowsky sum)
一.概述 官方定义:两个图形A,B的闵可夫斯基和C={a+b|a∈A,b∈B}通俗一点:从原点向图形A内部的每一个点做向量,将图形B沿每个向量移动,所有的最终位置的并便是闵可夫斯基和(具有交换律) 例 ...
- 3.定时器的使用(以通俗易懂的语言解释JavaScript)
1.定时器的作用: 开启定时器:setInterval -->间隔型 setTimeout -->延时型 区别:setInterval会一直执行,应用如微博间隔一段时间不断请求后台数据,看 ...
- CSS3帧动画
在前面的文章中也有介绍过css3动画的内容,可见<关于transition和animation>和<webkitAnimationEnd动画事件>,今天又要唠叨一下这个东西了, ...
随机推荐
- unix 环境高级编程-读书笔记与习题解答-第二篇
第四节 输入与输出 上次的笔记中写到的 open, read, write, lseek 以及close ,都是不带缓存的IO函数,这些函数都使用文件描述符进行工作. 上一篇笔记用到的 read(ST ...
- 十月例题F题 - City Game
F - City Game Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Bob is a st ...
- protocol(协议) 和 delegate(委托)也叫(代理)---辨析
protocol和delegate完全不是一回事. 协议(protocol),(名词)要求.就是使用了这个协议后就要按照这个协议来办事,协议要求实现的方法就一定要实现. 委托(delegate),(动 ...
- 性能相差极大的SQL语句
等价的SQL,性能差异极大,数据库里设计了一个字段存储日期时间,但不是datetime类型,用了时间戳(int 11), 下面有2个SQL语句用于查询数据库,一个是把时间戳转成date进行查询,一个是 ...
- 关于javascript
Client-Language-----------------------JavaScript/Object-C/Java/C# HTML5 DOM/Template/Data/Ajax/Regul ...
- java学习面向对象之继承
在我们编写程序的过程当中,会遇到这种情况: 比如现在有一个狗,他的功能有跑,有跳,有吃,有叫,属性有雌雄,大小,颜色等等,同时现在我们也有一个猫,上述功能她也有.这个时候我们写代码的时候,就得分别把上 ...
- LVM 命令集总结
PV 命令 下面的命令是在与物理卷相关的操作中最常用的命令: lsdev 列出ODM中的设备. chdev 修改设备的特征. mkdev 增加一个设备到系统中. chpv 修改物理卷的状态. lspv ...
- POJ 3468 A Simple Problem with Integers(详细题解) 线段树
这是个线段树题目,做之前必须要有些线段树基础才行不然你是很难理解的. 此题的难点就是在于你加的数要怎么加,加入你一直加到叶子节点的话,复杂度势必会很高的 具体思路 在增加时,如果要加的区间正好覆盖一个 ...
- 主席树:POJ2104 K-th Number (主席树模板题)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 44952 Accepted: 14951 Ca ...
- page-object使用(1)
创建你的page 你必须做的第一件事情是创建你的page,这是一些包含了PageObject模块的简单的ruby类,请不要创建你自己的initialize方法,因为已经有一个存在而且不能被覆盖.如果你 ...