1. 在Trio控制器中,目前只有MC224具有时钟功能,通过DATE和TIME指令可以获得或更改当前控制器的日期。如果你只是希望做定时功能的话,每一款Trio控制器为每个任务内都分配了一个系统参数ticks,这个参数的意义为每隔一个伺服周期(默认为1ms),系统内核软件自动将其减1,而且这个ticks可以随时由用户程序赋值,例如以下程序的意思为每隔1秒钟在终端0处打印“1 second timer!”: ticks=0 While true if ticks<=-1000 then print "1 second timer!" ticks=0 endif wend
2. MSPEED 就是你所希望得到的当前轴的速度参数。通过查询该参数可以获得任意时刻轴的当前速度。注意:MSPEED参数为每个伺服周期都进行一次更新的参数,它的意思为每个伺服周期内轴的反馈位置增加值,其单位与SPEED单位相同,如果电机轴转的不是足够快时,你有时访问该值会发现它会为0(因为1个伺服周期内(1ms),系统没有采集到该轴位置的变化),为避免程序误判,建议根据你的实际需要,对mspeed参数进行平均数处理,以下给出两个例程,希望对你有所帮助: 例一: ‘ Rolling average function to smooth out the fluctuations in MSPEED ‘ Each msec, this function adds the latest MSPEED value to the total ‘ of n-1 values. The smoothed value is then (total / n) ‘ n = 500 VR(20) = MSPEED * n ‘ insert starting value VR(21) = VR(20) / n ‘ starting value for average WHILE TRUE VR(20) = VR(20) – VR(21) ‘ reduce total to n-1 values VR(20) = VR(20) + MSPEED ‘ add latest measured speed VR(21) = VR(20) / 500 ‘ calculate the latest average WA(1) ‘ one millisecond wait WEND ‘ VR(21) contains the average mspeed value to be used for display
例二: ‘ measured speed calculated from 2 readings of position over a ‘ specified time period ‘ p = 500 VR(21) = 0 ‘ initialise the speed to zero WHILE TRUE TICKS = p VR(20) = MPOS WAIT UNTIL TICKS<=0 VR(21) = (MPOS – VR(20)) * 1000 / p ‘ calculate change per second WEND