GALIL编程程序计算结果出错 点击:504 | 回复:2



AMAL

    
  • 精华:0帖
  • 求助:0帖
  • 帖子:2帖 | 3回
  • 年度积分:0
  • 历史总积分:67
  • 注册:2018年3月08日
发表于:2018-05-07 23:48:58
楼主

刘工您好:

初用GL的卡,编程时遇到点问题,发现一条语句加减乘除算太多,程序就算的结果不对了。

具体见图:


实在是不理解为什么,这个语法问题在说明书的哪里会提到吗?




刘岩利

  • [版主]
  • 精华:2帖
  • 求助:0帖
  • 帖子:17帖 | 8240回
  • 年度积分:397
  • 历史总积分:28760
  • 注册:2005年3月09日
发表于:2018-05-08 09:50:20
1楼

这个与加减乘除有多少没有关系,是您的计算表达式写入错误。对于您期待的结果,正确的galil表达式应该是

 

pTSCTMP2=(pTSCSX-((pTSCNS-1-pTSCCL)*pTSCTSP))*pRESX

 

至于说明书的哪里会提到,不同版本的手册可能有一点差异:

 

在指令手册关于括号()的说明:

Remarks

Note  that  the  controller  evaluates  expressions  from  left  to  right,  and  does  not  follow   academic  algebraic  standards (e.g.  multiplication  and  division  first,  followed  by  addition  or  subtraction ) 

It  is  required  to  use  parentheticals  to  ensure  intended  mathematical  precedence

 

在指令手册里关于乘号*、除号/、加号+的说明

Remarks

 

This  is  a  binary  operator ( takes  two  arguments  and  returns  one  value ).  The  result   of  this    operation  is  a  value,  which  is  not  valid  on  its  own.  It  must  be  coupled  with  a  command.    See  examples  below.


Mathmatical  operations  are  calculated  left  to  right  rather  than  multiplication  and  division  calculations  performed  prior  to  addition  and  subraction.


Example:   1+2*3 = 9;' not 7


It  is  recommended  that  parenthesis  be  used  when  more  than  one  mathmatical    operation  is  combined  in  one  command.

 

Example:   var = ((10*30)+(60/30));' evaluates   as   302

 


var  =  10*30+60/30;'   evalutes  as  12

 

在产品手册的 Mathematical  and   Functional  Expressions 算术和函数表达式一节中,也写了

 

Mathematical  operations  are  executed  from  left  to  right.  Calculations  within  parentheses  have  precedence.


Examples:


speed = 7.5*V1/2     The  variable,  speed,  is  equal  to  7.5  multiplied  by   V1   and   divided   by  2
count = count+2     The   variable,  count,  is  equal  to  the  current  value  plus  2.
result =_TPX-(@COS[45]*40)     Puts  the  position  of  X  -  28.28   in  result.  40 * cosine of  45    is 28.28

AMAL

  • 精华:0帖
  • 求助:0帖
  • 帖子:2帖 | 3回
  • 年度积分:0
  • 历史总积分:67
  • 注册:2018年3月08日
发表于:2018-05-12 08:51:58
2楼
非常感谢刘工!GALIL运算不是按照传统加减乘除的优先级来运算的,是我编程想当然了,还是要仔细看手册~~

热门招聘
相关主题

官方公众号

智造工程师