GTS-800二次开发基本流程总结

转载连接: http://www.cnblogs.com/LandyTan/p/6973920.html


1、打开控制器         GT_Open
2、启动伺服使能          GT_ClrSts
3、轴规划位置清零       GT_SetPrfPos
4、轴运动模式         GT_PrfTrap
5、轴目标位置         GT_SetPos
6、轴转动速度         GT_SetVel
7、启动轴           GT_Update
8、关闭使能          GT_AxisOff
9、关闭控制器         GT_Close
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
C#:<br> using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;
using  gts;
 
 
namespace  GTS
{
     class  Program
     {
         static  void  command( string  sz,  short  nR)
         {
             Console.WriteLine(sz +  " = "  + nR);
         }
 
         static  void  Main( string [] args)
         {
             short  mAxis = 2;
             short  nR = mc.GT_Open(0, 1);
             if  (nR != 0)
             {
                 command( "GT_Open" , nR);
                 Console.WriteLine( "Open error" );
                 return ;
             }
             command( "GT_Open" , nR);
             // 清除各轴的报警和限位
             command( "GT_ClrSts" , mc.GT_ClrSts(mAxis, 1));
             // 伺服使能
             command( "GT_AxisOn" , mc.GT_AxisOn(mAxis));
             // 位置清零
             command( "GT_ZeroPos" , mc.GT_ZeroPos(mAxis, 1));
             // 轴规划位置清零
             command( "GT_SetPrfPos" , mc.GT_SetPrfPos(mAxis, 0));
             // 设置指定轴为点位运动模式。
             command( "GT_PrfTrap" , mc.GT_PrfTrap(mAxis));
             // 设置点位运动参数
             mc.TTrapPrm trap =  new  mc.TTrapPrm();
             trap.acc = 0.25;
             trap.dec = 0.125;
             trap.smoothTime = 25;
             command( "GT_SetTrapPrm" , mc.GT_SetTrapPrm(mAxis,  ref  trap));
             // 设置轴的目标位置
             command( "GT_SetPos" , mc.GT_SetPos(mAxis, 50000));
             // 设置轴的目标速度
             command( "GT_SetVel" , mc.GT_SetVel(mAxis, 25));
             // 启动轴运动
             command( "GT_Update" , mc.GT_Update(1 << mAxis - 1));
 
             mc.GT_Close();
             Console.ReadKey();
         }
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
C++源码:
#include "stdafx.h"
#include "windows.h"
#include "conio.h"
#include "gts.h"
 
#define AXIS        1
 
// 该函数检测某条GT指令的执行结果,command为指令名称,error为指令执行返回值
void  commandhandler( char  *command,  short  error)
{
     // 如果指令执行返回值为非0,说明指令执行错误,向屏幕输出错误结果
     if (error)
     {
         printf( "%s = %d\n" , command, error);
     }
}
int  main( int  argc,  char * argv[])
{
     short  sRtn;
     TTrapPrm trap;
     long  sts;
     double  prfPos;
 
     // 打开运动控制器
     sRtn = GT_Open();
     // 指令返回值检测,请查阅例2-1
     commandhandler( "GT_Open" , sRtn);
     // 配置运动控制器
     // 注意:配置文件取消了各轴的报警和限位
     sRtn = GT_LoadConfig( "test.cfg" );
     commandhandler( "GT_LoadConfig " , sRtn);
     // 清除各轴的报警和限位
     sRtn = GT_ClrSts(1, 8);
     commandhandler( "GT_ClrSts" , sRtn);
     // 伺服使能
     sRtn = GT_AxisOn(AXIS);
     commandhandler( "GT_AxisOn" , sRtn);
 
     // 位置清零
     sRtn = GT_ZeroPos(AXIS);
     commandhandler( "GT_ZeroPos" , sRtn);
     // AXIS轴规划位置清零
     sRtn = GT_SetPrfPos(AXIS, 0);
     commandhandler( "GT_SetPrfPos" , sRtn);
     // 将AXIS轴设为点位模式
     sRtn = GT_PrfTrap(AXIS);
     commandhandler( "GT_PrfTrap" , sRtn);
     // 读取点位运动参数
     sRtn = GT_GetTrapPrm(AXIS, &trap);
     commandhandler( "GT_GetTrapPrm" , sRtn);
     trap.acc = 0.25;
     trap.dec = 0.125;
     trap.smoothTime = 25;
     // 设置点位运动参数
     sRtn = GT_SetTrapPrm(AXIS, &trap);
     commandhandler( "GT_SetTrapPrm" , sRtn);
     // 设置AXIS轴的目标位置
     sRtn = GT_SetPos(AXIS, 50000L);
     commandhandler( "GT_SetPos" , sRtn);
     // 设置AXIS轴的目标速度
     sRtn = GT_SetVel(AXIS, 50);
     commandhandler( "GT_SetVel" , sRtn);
     // 启动AXIS轴的运动
     sRtn = GT_Update(1<<(AXIS-1));
     commandhandler( "GT_Update" , sRtn);
 
     do
     {
         // 读取AXIS轴的状态
         sRtn = GT_GetSts(AXIS, &sts);
         // 读取AXIS轴的规划位置
         sRtn = GT_GetPrfPos(AXIS, &prfPos);
         printf( "sts=0x%-10lxprfPos=%-10.1lf\r" , sts, prfPos);
     } while (sts&0x400);   // 等待AXIS轴规划停止
 
     // 伺服关闭
     sRtn = GT_AxisOff(AXIS);
     printf( "\nGT_AxisOff()=%d\n" , sRtn);
     getch();
     return  0;
 
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值