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

开发环境: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. ASP.NET MVC 定义JsonpResult实现跨域请求

    1:原理 在js中,XMLHttpRequest是不能请求不同域的数据,但是script标签却可以,所以可以用script标签实现跨域请求.具体是定义一个函数,例如jsonp1234,请求不同域的ur ...

  2. [BZOJ 1033] [ZJOI2008] 杀蚂蚁antbuster 【模拟!】

    题目链接: BZOJ - 1033 题目分析 模拟!纯粹按照题目描述模拟! 这是一道喜闻乐见的经典模拟题! 我一共写了2遍,Debug 历时2天的所有晚自习 ... 时间超过 8h ... 我真是太弱 ...

  3. Pair of Numbers

    Codeforces Round #209 (Div. 2) D:http://codeforces.com/contest/359/problem/D 题意:给以一个n个数的序列,然后问你最大的区间 ...

  4. Network Saboteur

    poj2531:http://poj.org/problem?id=2531 题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大.题解:一开始比知道怎么办,想用 ...

  5. 把CSV文件导入到SQL Server表中

    保存数据库数据直接查询select * from tableName 在数据表格的左上角右击——将结果另存为选择路劲保存好的就是.csv格式的数据 有时候我们可能会把CSV中的数据导入到某个数据库的表 ...

  6. 【HDOJ】1601 Galactic Import

    Dijkstra. /* 1601 */ #include <cstdio> #include <cstring> #include <cstdlib> #defi ...

  7. Javascript 面向对象编程(一):封装 by 阮一峰

    <Javascript高级程序设计(第二版)>(Professional JavaScript for Web Developers, 2nd Edition) 它们都是非常优秀的Java ...

  8. 网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life

    John is a Chief Executive Officer at a privately owned medium size company. The owner of the company ...

  9. 译文链接:http://www.codeceo.com/article/10-truth-programmer-must-know.html

    大多数时候,写代码都是挺有意义的一件事,不光能增加经验值,解决难题的时候还特别爽.耐心.毅力.执着,再加上正确的工具——只要有它们的亲密协作,优雅.漂亮的代码就是手到擒来的事儿. 但是,紧接着拙劣的资 ...

  10. 《University Calculus》-chaper13-多重积分-三重积分的引入

    承接之前对一重积分和二重积分的介绍,这里我们自然的引出三重积分. 在二重积分的引入中,我们曾经埋下过一个小伏笔,二重积分的几何意义是求解一个体积,但是我们仅仅限定在了曲顶柱体的几何体,那么对于完全由曲 ...