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动画事件>,今天又要唠叨一下这个东西了, ...
随机推荐
- 在linux下实现UBOOT的TFTP下载功能
一.环境 1.条件 软件:虚拟机下linux(本文涉及到的是Ubuntu12.0.4). linux下的串口助手(例如minicom)或windows下的串口助手(例如超级终端.SecureCRT) ...
- const 笔记
.指向const的指针例如:double a=1.01;const double * b=&a;*b=2.1; //这显然是错误的a=2.1; //这是正确的,a和*b的值都会变成2.01,有 ...
- Ubuntu下安装和配置Apache2
http://www.blogjava.net/duanzhimin528/archive/2010/03/05/314564.html 在Ubuntu中安装apache 安装指令:sudo apt- ...
- C#程序设计基础——运算符与表达式
运算符就是完成操作的一系列符号,它主要包括算术运算符.赋值运算符.关系运算符.逻辑运算符.条件运算.位操作运算符和字符串运算符. 表达式就是运算符和操作数的组合,如a*b+1-c.表达式主要包括算术表 ...
- Qt tip 网络请求 QNetworkRequest QJason 处理 JSON
http://blog.csdn.net/linbounconstraint/article/details/52399415 http://download.csdn.net/detail/linb ...
- Git skills in reseting files
How to uncommit files that were committed long time a ago?Note: Since all changes in the current wor ...
- COJ 0046 20701除法
20701除法 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 输入正整数n,按从小到大的顺序输出所有满足表达式abcd ...
- 【字符串】【最小表示法】Vijos P1683 有根树的同构问题
题目链接: https://vijos.org/p/1683 题目大意: 给M棵树,每棵N个点,N-1条边,树边有向,问哪些树同构. 题目思路: [字符串][最小表示法] 用()表示一个节点,那么三个 ...
- 【宽搜】Vijos P1206 CoVH之再破难关
题目链接: https://vijos.org/p/1206 题目大意: 给你开始和结束两张4x4的01图,每次操作只能够交换相邻的两个格子(有公共边),问最少的操作步数. 题目思路: [搜索] 这题 ...
- 暴力求解——POJ 3134Power Calculus
Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multipli ...