Kollmorgen AkD BASlC Basic User Manual

AKD BASIC™
User Guide
Edition March 30, 2012, Revision A
Valid for Hardware Revision C
Patents Pending
Part Number 903-2000014-00
Keep all manualsas a product component during the life span ofthe product.
Passallmanuals to future users/owners of the product.
Record of Document Revisions:
Revision Remarks
06/2011, Rev A Launch Version for M_01-06-00-000
Windows is a registered trademark of Microsoft Corporation AKD is a registered trademark of Kollmorgen Corporation
Current patents:
US Patent 5,646,496 (used in control card R/D and 1 Vp-p feedback interface)
US Patent 5,162,798 (used in control card R/D)
US Patent 6,118,241 (used in control card simple dynamic braking)
Technical changes which improve the performance of the device may be made without prior notice.
Printed in the United States of America This document is the intellectual property of Kollmorgen™. All rights reserved. No part of this work may be reproduced in any form (by photocopying, microfilm or any other method) or stored, processed, copied or distributed by electronic means without the written permission of Kollmorgen™.
Kollmorgen™ | March 30, 2012 2
This page intentionally left blank.
3 Kollmorgen™ | March 30, 2012
Table of Contents
1 About this User Guide 16 2 Program View 17
2.1 Toolbar Options 17
2.1.1 New ... 17
2.1.2 Save / Save As 17
2.1.3 Open 18
2.1.4 Edit Parameters Section 18
2.1.5 Compile / Download / Run 18
2.1.6 Continue / Pause / Stop 18
2.1.7 Debug 18
2.1.8 View 19
2.1.9 Format Document 19
2.1.10 Insert Code Snippet 19
2.1.11 Upload? 19
2.1.12 Lock 19
3 AKDBASICLanguage 20
3.1 AKD BASIC Program Structure 20
3.1.1 Local Variables 20
3.1.2 Global Variables 20
3.2 Program Sections 21
3.2.1 Program Template 21
3.2.2 Setup Parameter Definitions 21
3.2.3 Global Variables, Constants, and Aliases 22
3.2.4 Variable Definitions 22
3.2.5 Constant Definitions 22
3.2.6 Alias Definitions 23
3.3 Main Program, Subroutines, Functions & Interrupt Handlers 23
3.3.1 Main Definitions 23
3.3.2 Subroutine Definition 24
3.3.3 Function Definition 25
3.3.4 Interrupt Handler Definition 25
3.4 Language Definition 26
3.4.1 Lexical Conventions 26
3.4.2 Identifiers 26
3.4.3 Data Types 26
3.4.4 Literal Constants 27
3.4.5 Decimal Integer Constants 27
3.4.6 Hexadecimal Constants 27
3.4.7 Floating-Point Constants 27
3.5 Statements 28
3.5.1 Alias 28
3.5.2 Call 28
Kollmorgen™ | March 30, 2012 4
3.5.3 Cls 28
3.5.4 Const 28
3.5.5 Dim 29
3.5.6 Exit 29
3.5.7 For…Next 29
3.5.8 Function 30
3.5.9 GoTo 30
3.5.10 If…Then…Else 30
3.5.11 $Include 31
3.5.12 Input 31
3.5.13 Interrupt … End Interrupt 31
3.5.14 MOVE.ABORT 31
3.5.15 MOVE.GOABS 31
3.5.16 MOVE.GOHOME 31
3.5.17 MOVE.GOREL 32
3.5.18 MOVE.GOUPDATE 32
3.5.19 MOVE.GOVEL 32
3.5.20 On Error GoTo 32
3.5.21 Pause( ) 33
3.5.22 Print 33
3.5.23 Example 33
3.5.24 VM.RESTART 33
3.5.25 Select Case 33
3.5.26 Static 34
3.5.27 Stop 34
3.5.28 Sub…End Sub 34
3.5.29 Swap 35
3.5.30 When 35
3.5.31 While…Wend 35
3.6 Built-in Functions 35
3.6.1 Parameters and Commands 36
3.7 Expressions 37
3.7.1 Arithmetic Expressions 37
3.7.2 Numeric Operators 37
3.7.3 Logical Operators 37
3.7.4 String Operators 38
3.7.5 Example 38
3.8 Function Invocation 38
3.8.1 $INCLUDE 38
3.9 Arrays and Function Parameter Lists 39
3.9.1 Optimizations 39
3.10 ModBus TCP/IP 41
3.10.1 ModBus Parameter Table 41
3.10.2 ModBus Register and Data Types 41
3.10.3 User Created Variables with Assigned Modbus Address Numbers 41
5 Kollmorgen™ | March 30, 2012
3.10.4 Drive Fault Table 42
3.10.5 Drive Parameter Scaling Over Modbus 42
3.10.6 Special Modbus AKD Parameters 42
3.10.7 ModBus Dynamic Mapping 43
3.11 Cam Profiling 43
3.11.1 Procedure 43
3.11.2 Related Variables 43
3.11.3 Cam Wizard 44
3.11.4 Example 45
3.11.5 Program 45
3.11.6 Virtual encoder (virtual master) 46
3.11.7 Move Parameters 47
3.11.8 Move Statements 47
3.11.9 Other Variables 47
4 Quick Reference: Parameters, Functions, Operators 48
4.1 AKD Parameters and Commands 48
4.2 AKDBASICParameters and Commands 55
5 AKD BASIC Functions 63
5.1 ABS() 64
5.2 ASC() 65
5.3 ATAN() 66
5.4 CHR$() 67
5.5 CINT() 68
5.6 COS() 69
5.7 EXP() 70
5.8 FIX() 71
5.9 HEX$() 72
5.10 INKEY$() 73
5.11 INSTR() 74
5.12 INT() 75
5.13 LCASE$() 76
5.14 LEFT$() 77
5.15 LEN() 78
5.16 LOG() 79
5.17 LOG10() 80
5.18 LTRIM$() 81
5.19 MID$ 82
5.20 OCT$() 83
5.21 RIGHT$() 84
5.22 RTRIM$() 85
5.23 SGN() 86
5.24 SIN() 87
5.25 SPACE$() 88
5.26 SQR() 89
5.27 STR$() 90
Kollmorgen™ | March 30, 2012 6
5.28 STRING$() 91
5.29 TAN() 92
5.30 TRIM$() 93
5.31 UCASE$() 94
5.32 VAL() 95
6 AKD BASIC Parameters, Operators, Statements 96
6.1 Additional Statements 97
6.1.1 $Include 98
6.1.2 Alias 99
6.1.3 Call 100
6.1.4 Cls 101
6.1.5 Const 102
6.1.6 Dim 103
6.1.7 Exit 104
6.1.8 For...Next 105
6.1.9 Function 106
6.1.10 GoTo 107
6.1.11 If...Then...Else 108
6.1.12 Input 109
6.1.13 On Error GoTo 110
6.1.14 Pause() 112
6.1.15 Print 113
6.1.16 Restart 114
6.1.17 Select Case 115
6.1.18 Static 116
6.1.19 Stop 117
6.1.20 Sub...End Sub 118
6.1.21 Swap 119
6.1.22 While...Wend 120
6.2 Operators 121
6.2.1 MOD 122
6.3 AIN Parameters 123
6.3.1 AIN.CUTOFF 124
6.3.2 AIN.DEADBAND 125
6.3.3 AIN.DEADBANDMODE 127
6.3.4 AIN.ISCALE 129
6.3.5 AIN.MODE 130
6.3.6 AIN.OFFSET 131
6.3.7 AIN.PSCALE 132
6.3.8 AIN.VALUE 134
6.3.9 AIN.VSCALE 135
6.3.10 AIN.ZERO 137
6.4 AOUT Parameters 139
6.4.1 AOUT.CUTOFF 140
6.4.2 AOUT.DEBUGADDR 141
7 Kollmorgen™ | March 30, 2012
6.4.3 AOUT.DEBUGDATATYPE 142
6.4.4 AOUT.DEBUGSCALE 143
6.4.5 AOUT.ISCALE 144
6.4.6 AOUT.MODE 145
6.4.7 AOUT.OFFSET 146
6.4.8 AOUT.PSCALE 147
6.4.9 AOUT.VALUE 149
6.4.10 AOUT.VALUEU 150
6.4.11 AOUT.VSCALE 151
6.5 CAM Parameters 152
6.5.1 CAM.ACTIVATE 153
6.5.2 CAM.ADDPOINT 155
6.5.3 CAM.CORRECTDIR 157
6.5.4 CAM.CREATE 158
6.5.5 CAM.MASTER 160
6.5.6 CAM.MASTERPOS 161
6.5.7 CAM.SLAVEOFFSET 162
6.5.8 CAMVM.DIR 163
6.5.9 CAMVM.FREQ 164
6.5.10 CAMVM.GOREL 165
6.5.11 CAMVM.GOUPDATE 166
6.5.12 CAMVM.GOVEL 167
6.5.13 CAMVM.MOVING 168
6.5.14 CAMVM.POSITION 169
6.5.15 CAMVM.RELATIVEDIST 170
6.5.16 CAMVM.STOP 171
6.6 CAP Parameters 172
6.6.1 CAP0.EDGE, CAP1.EDGE 173
6.6.2 CAP0.EN, CAP1.EN 174
6.6.3 CAP0.EVENT, CAP1.EVENT 175
6.6.4 CAP0.FILTER, CAP1.FILTER 178
6.6.5 CAP0.MODE, CAP1.MODE 179
6.6.6 CAP0.PLFB, CAP1.PLFB 180
6.6.7 CAP0.PREEDGE, CAP1.PREEDGE 181
6.6.8 CAP0.PREFILTER, CAP1.PREFILTER 182
6.6.9 CAP0.PRESELECT, CAP1.PRESELECT 183
6.6.10 CAP0.STATE, CAP1.STATE 184
6.6.11 CAP0.T, CAP1.T 185
6.6.12 CAP0.TRIGGER, CAP1.TRIGGER 186
6.7 CS Parameters 188
6.7.1 CS.DEC 189
6.7.2 CS.STATE 190
6.7.3 CS.TO 191
6.7.4 CS.VTHRESH 192
6.8 DIN Parameters 193
Kollmorgen™ | March 30, 2012 8
6.8.1 DIN.ROTARY 194
6.8.2 DIN.STATES 195
6.8.3 DIN1.FILTER TO DIN7.FILTER 196
6.8.4 DIN1.INV to DIN7.INV 197
6.8.5 DIN1.MODE to DIN19.MODE 198
6.8.6 DIN1.STATE TO DIN7.STATE 200
6.8.7 DIN9.STATE to DIN11.STATE 201
6.9 DIO Parameters 202
6.9.1 DIO9.INV to DIO11.INV 203
6.9.2 DIO9.DIR to DIO11.DIR 204
6.10 DOUT Parameters 205
6.10.1 DOUT.RELAYMODE 206
6.10.2 DOUT.STATES 207
6.10.3 DOUT8.MODE to DOUT11.MODE 208
6.10.4 DOUT1.PARAM AND DOUT2.PARAM 209
6.10.5 DOUT1.STATE AND DOUT2.STATE 210
6.10.6 DOUT1.STATEU AND DOUT2.STATEU 211
6.10.7 DOUT9.STATE to DOUT11.STATE 212
6.10.8 DOUT9.STATEU to DOUT11.STATEU 213
6.11 DRV Parameters 214
6.11.1 DRV.ACC 215
6.11.2 DRV.ACTIVE 217
6.11.3 DRV.BLINKDISPLAY 218
6.11.4 DRV.CLRFAULTHIST 219
6.11.5 DRV.CLRFAULTS 220
6.11.6 DRV.CMDSOURCE 221
6.11.7 DRV.DBILIMIT 222
6.11.8 DRV.DEC 223
6.11.9 DRV.DIR 224
6.11.10 DRV.DIS 226
6.11.11 DRV.DISSOURCES 227
6.11.12 DRV.DISTO 228
6.11.13 DRV.EMUEDIR 229
6.11.14 DRV.EMUEMODE 230
6.11.15 DRV.EMUEMTURN 232
6.11.16 DRV.EMUERES 233
6.11.17 DRV.EMUEZOFFSET 234
6.11.18 DRV.EN 235
6.11.19 DRV.FAULT1 to DRV.FAULT10 236
6.11.20 DRV.HANDWHEEL 237
6.11.21 DRV.HANDWHEELSRC 238
6.11.22 DRV.HWENABLE 239
6.11.23 DRV.ICONT 240
6.11.24 DRV.IPEAK 241
6.11.25 DRV.NAME 242
9 Kollmorgen™ | March 30, 2012
6.11.26 DRV.NVLOAD 243
6.11.27 DRV.NVSAVE 244
6.11.28 DRV.OPMODE 245
6.11.29 DRV.RSTVAR 246
6.11.30 DRV.SETUPREQBITS 247
6.11.31 DRV.STOP 248
6.11.32 DRV.SWENABLE 249
6.11.33 DRV.TIME 250
6.11.34 DRV.WARNING1 to DRV.WARNING10 251
6.12 EGEAR Parameters 252
6.12.1 EGEAR.ACCLIMIT 253
6.12.2 EGEAR.DECLIMIT 254
6.12.3 EGEAR.ERROR 255
6.12.4 EGEAR.LOCK 256
6.12.5 EGEAR.ON 257
6.12.6 EGEAR.PULSESIN 258
6.12.7 EGEAR.PULSEOUT 259
6.12.8 EGEAR.RATIO 260
6.12.9 EGEAR.TYPE 261
6.13 EXTENCODER Parameters 262
6.13.1 EXTENCODER.FREQ 263
6.13.2 EXTENCODER.POSITION 264
6.13.3 EXTENCODER.POSMODULO 265
6.14 FAULT Parameters 266
6.14.1 FAULTx.ACTION 267
6.15 FB1 Parameters 268
6.15.1 FB1.BISSBITS 269
6.15.2 FB1.ENCRES 270
6.15.3 FB1.HALLSTATE 271
6.15.4 FB1.HALLSTATEU 272
6.15.5 FB1.HALLSTATEV 273
6.15.6 FB1.HALLSTATEW 274
6.15.7 FB1.IDENTIFIED 275
6.15.8 FB1.INITSIGNED 276
6.15.9 FB1.MECHPOS 277
6.15.10 FB1.MEMDUMP 278
6.15.11 FB1.MEMVER 279
6.15.12 FB1.ORIGIN 280
6.15.13 FB1.P 282
6.15.14 FB1.PDIR 283
6.15.15 FB1.POFFSET 284
6.15.16 FB1.POLES 285
6.15.17 FB1.PSCALE 286
6.15.18 FB1.PUNIT 287
6.15.19 FB1.SELECT 288
Kollmorgen™ | March 30, 2012 10
6.16 FB2 Parameters 290
6.16.1 FB2.ENCRES 291
6.16.2 FB2.MODE 292
6.16.3 FB2.P 293
6.16.4 FB2P.DIR 294
6.16.5 FB2.POFFSET 294
6.16.6 FB2.PUNIT 295
6.16.7 FB2.SOURCE 296
6.17 FB3 Parameters 297
6.17.1 FB3.MODE 298
6.17.2 FB3.POFFSET 299
6.17.3 FB3.PUNIT 300
6.18 HWLS Parameters 301
6.18.1 HWLS.NEGSTATE 302
6.18.2 HWLS.POSSTATE 303
6.19 IL Parameters 304
6.19.1 IL.BUSFF 305
6.19.2 IL.CMD 306
6.19.3 IL.CMDU 307
6.19.4 IL.DFOLDT 308
6.19.5 IL.DIFOLD 309
6.19.6 IL.FB 310
6.19.7 IL.FF 311
6.19.8 IL.FOLDFTHRESH 312
6.19.9 IL.FOLDWTHRESH 313
6.19.10 IL.IFOLD 314
6.19.11 IL.IUFB 315
6.19.12 IL.IVFB 316
6.19.13 IL.KP 317
6.19.14 IL.KPDRATIO 318
6.19.15 IL.LIMITN 319
6.19.16 IL.LIMITP 320
6.19.17 IL.MFOLDD 321
6.19.18 IL.MFOLDR 322
6.19.19 IL.MFOLDT 323
6.19.20 IL.MIFOLD 324
6.19.21 IL.VCMD 325
6.19.22 IL.VUFB 326
6.19.23 IL.VVFB 327
6.20 INTR Parameters 328
6.20.1 Interrupt {Source} 329
6.20.2 Interrupt...End Interrupt 332
6.21 LOAD Parameters 333
6.21.1 LOAD.INERTIA 334
6.22 MODBUS Paramters 335
11 Kollmorgen™ | March 30, 2012
6.22.1 MODBUS.READFLOAT 336
6.22.2 MODBUS.WRITEFLOAT 337
6.23 MOTOR Parameters 338
6.23.1 MOTOR.BRAKE 339
6.23.2 MOTOR.BRAKEIMM 340
6.23.3 MOTOR.BRAKERLS 341
6.23.4 MOTOR.ICONT 342
6.23.5 MOTOR.INERTIA 343
6.23.6 MOTOR.IPEAK 344
6.23.7 MOTOR.KE 345
6.23.8 MOTOR.KT 346
6.23.9 MOTOR.LQLL 347
6.23.10 MOTOR.NAME 348
6.23.11 MOTOR.PHASE 349
6.23.12 MOTOR.PITCH 350
6.23.13 MOTOR.POLES 351
6.23.14 MOTOR.R 352
6.23.15 MOTOR.TBRAKEAPP 353
6.23.16 MOTOR.TBRAKERLS 354
6.23.17 MOTOR.TEMP 355
6.23.18 MOTOR.TEMPFAULT 356
6.23.19 MOTOR.TEMPWARN 357
6.23.20 MOTOR.TYPE 358
6.23.21 MOTOR.VOLTMAX 359
6.24 MOVE Parameters 360
6.24.1 MOVE.ABORT 361
6.24.2 MOVE.ACC 362
6.24.3 MOVE.DEC 364
6.24.4 MOVE.DIR 366
6.24.5 MOVE.DWELLTIME 367
6.24.6 MOVE.GOABS 368
6.24.7 MOVE.GOHOME 369
6.24.8 MOVE.GOREL 370
6.24.9 MOVE.GOUPDATE 371
6.24.10 MOVE.GOVEL 372
6.24.11 MOVE.INPOSITION 373
6.24.12 MOVE.INPOSLIMIT 374
6.24.13 MOVE.MOVING 375
6.24.14 MOVE.POSCOMMAND 376
6.24.15 MOVE.RELATIVEDIST 377
6.24.16 MOVE.RUNSPEED 378
6.24.17 MOVE.SCURVETIME 379
6.24.18 MOVE.TARGETPOS 380
6.25 PL Parameters 381
6.25.1 PL.CMD 382
Kollmorgen™ | March 30, 2012 12
6.25.2 PL.ERR 383
6.25.3 PL.ERRFTHRESH 384
6.25.4 PL.ERRMODE 386
6.25.5 PL.ERRWTHRESH 388
6.25.6 PL.FB 390
6.25.7 PL.FBSOURCE 391
6.25.8 PL.INTINMAX 392
6.25.9 PL.INTOUTMAX 394
6.25.10 PL.KI 396
6.25.11 PL.KP 397
6.25.12 PL.MODP1 398
6.25.13 PL.MODP2 399
6.25.14 PL.MODPDIR 400
6.25.15 PL.MODPEN 401
6.26 PLS Parameters 402
6.26.1 PLS.EN 403
6.26.2 PLS.MODE 404
6.26.3 PLS.P1 TO PLS.P8 405
6.26.4 PLS.RESET 406
6.26.5 PLS.STATE 407
6.26.6 PLS.T1 TO PLS.T8 408
6.26.7 PLS.UNITS 409
6.26.8 PLS.WIDTH1 TO PLS.WIDTH8 411
6.27 REC Parameters 413
6.27.1 REC.ACTIVE 413
6.27.2 REC.DONE 414
6.27.3 REC.OFF 415
6.27.4 REC.TRIG 416
6.28 REGEN Parameters 417
6.28.1 REGEN.POWER 418
6.28.2 REGEN.REXT 419
6.28.3 REGEN.TEXT 420
6.28.4 REGEN.TYPE 421
6.28.5 REGEN.WATTEXT 422
6.29 STO Parameters 423
6.29.1 STO.STATE 424
6.30 SWLS Parameters 425
6.30.1 SWLS.EN 426
6.30.2 SWLS.LIMIT0 427
6.30.3 SWLS.LIMIT1 428
6.30.4 SWLS.STATE 429
6.31 UNIT Parameters 430
6.31.1 UNIT.ACCLINEAR 431
6.31.2 UNIT.ACCROTARY 432
6.31.3 UNIT.LABEL 433
13 Kollmorgen™ | March 30, 2012
6.31.4 UNIT.PIN 434
6.31.5 UNIT.PLINEAR 435
6.31.6 UNIT.POUT 436
6.31.7 UNIT.PROTARY 437
6.31.8 UNIT.VLINEAR 438
6.31.9 UNIT.VROTARY 439
6.32 VBUS Parameters 440
6.32.1 VBUS.OVFTHRESH 441
6.32.2 VBUS.OVWTHRESH 442
6.32.3 VBUS.RMSLIMIT 443
6.32.4 VBUS.UVFTHRESH 444
6.32.5 VBUS.UVMODE 445
6.32.6 VBUS.UVWTHRESH 446
6.32.7 VBUS.VALUE 447
6.33 VL Parameters 448
6.33.1 VL.ARPF1 TO VL.ARPF4 449
6.33.2 VL.ARPQ1 TO VL.ARPQ4 451
6.33.3 VL.ARTYPE1 TO VL.ARTYPE4 453
6.33.4 VL.ARZF1 TO VL.ARZF4 454
6.33.5 VL.ARZQ1 TO VL.ARZQ4 456
6.33.6 VL.BUSFF 458
6.33.7 VL.CMD 459
6.33.8 VL.CMDU 460
6.33.9 VL.ERR 461
6.33.10 VL.FB 462
6.33.11 VL.FBFILTER 463
6.33.12 VL.FBSOURCE 464
6.33.13 VL.FBUNFILTERED 465
6.33.14 VL.FF 466
6.33.15 VL.GENMODE 467
6.33.16 VL.KBUSFF 468
6.33.17 VL.KI 469
6.33.18 VL.KP 470
6.33.19 VL.KVFF 471
6.33.20 VL.LIMITN 472
6.33.21 VL.LIMITP 473
6.33.22 VL.LMJR 474
6.33.23 VL.THRESH 475
6.34 VM Parameters 477
6.34.1 VM.AUTOSTART 478
6.34.2 VM.ERR 479
6.34.3 VM.INTRTIMER 481
6.34.4 VM.RESTART 482
6.35 WHEN Parameters 483
6.35.1 When 484
Kollmorgen™ | March 30, 2012 14
6.35.2 WHEN.DRVHANDWHEEL 486
6.35.3 WHEN.DRVTIME 487
6.35.4 WHEN.FB1MECHPOS 488
6.35.5 WHEN.PLCMD 489
6.35.6 WHEN.PLFB 490
6.36 WS Parameters 491
6.36.1 WS.ARM 492
6.36.2 WS.DISARM 493
6.36.3 WS.DISTMAX 494
6.36.4 WS.DISTMIN 495
6.36.5 WS.IMAX 496
6.36.6 WS.MODE 497
6.36.7 WS.NUMLOOPS 498
6.36.8 WS.STATE 499
6.36.9 WS.T 500
6.36.10 WS.TDELAY1 501
6.36.11 WS.TDELAY2 502
6.36.12 WS.TDELAY3 503
6.36.13 WS.VTHRESH 504
15 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 1 About this User Guide

1 About this User Guide

This guide describes the operation and use of the AKD drive. Each section details a specific topic related to the use of the product in simple terms which will help you get the most from the product. Each section includes examples to help guide you in setting up and using the various features available in the drive.
This guide is for users who have installed and tested the drive according to the AKD Installation Manual. The AKD Installation Manual is included on the product CD and contains critical safety information.
Kollmorgen™ | March 30, 2012 16
AKD BASIC User Guide | 2 Program View

2 Program View

The program view in AKD WorkBench is specific to AKD BASIC drives and can only be accessed using an AKD BASIC drive type in either online or offline mode. Programs can be compiled in offline mode, but an AKD BASIC drive must be connected to download and run a program.

2.1 Toolbar Options

The toolbar at the top of the program view contains a number of tools to assist you in programming.

2.1.1 New ...

The Program view loads as an empty window. Create a new program by clicking the new icon in the upper-left corner and selecting either BASIC or BASICUsing Current Drive Params. The BASIC selection will load an empty template. The BASICUsing Current Drive Params selection will populate the template with all current drive values. Then select the location and name of your new project file, and click save.
This will load the BASICtemplate from which you can begin programming.

2.1.2 Save / Save As

Once you have written your program, save it using the "Save" or "Save As" function on the toolbar .
17 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 2 Program View

2.1.3 Open

To open a previous project file click the "Open" function and locate your file in the explorer.

2.1.4 Edit Parameters Section

Clicking on the Edit Params Section tool will prompt you to populate the Params section of your code with all the current drive settings. Clicking yes will overwrite all current param defintions with the current drive values.

2.1.5 Compile / Download / Run

The Compile button will compile your source code to binary so that you may download the program to the drive.
The Download button will download your compiled code and source code to the drive by default. If you do not wish to download the source code to the drive, go to the options menu, choose download and de­select download source with binary.
The run button will issue a VM.START to start the BASIC program in the drive. If the active BASIC pro­gram in the editor is different than the program in the drive, the run button will compile and download the program before running.

2.1.6 Continue / Pause / Stop

The Continue, Pause, and Stop options allow you to control your program while it is running.

2.1.7 Debug

The Debugger allows you to set break points and step through your program.
Kollmorgen™ | March 30, 2012 18
AKD BASIC User Guide | 2 Program View

2.1.8 View

Use Find and Replace to find keywords in your program and replace them with a new keyword
Use the Go To Line to go to a specific line of code
Watch will open the expression evaluator tab. The expression evaluator is only valid while using the debugger. You can evaluate any drive parameter or user defined variable when the program is paused by the debugger.
Call Stack will open the call stack tab

2.1.9 Format Document

The format document tool implements correct line indentation across all code.

2.1.10 Insert Code Snippet

The Insert Code Snippet tool presents a list of existing code snippets, which can be selected and inserted into the program at the point where the cursor is currently placed.

2.1.11 Upload?

The upload tool uploads the source code from the drive. If the source code has not been downloaded, this option is not available. The tools menu allows you to select if the source code is to be downloaded with the binary.

2.1.12 Lock

The lock tool password protects the source code in the drive. If a new program is downloaded to a drive, the original source code and password protection is erased.
19 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
3 AKDBASICLanguage
This chapter describes the overall structure of an AKD BASIC program and the elements of the AKD BASIC language. Topics covered are:
l scope l program structure
l setup parameters l global variables, constants and aliases l ‘main’ program, subroutines, functions and interrupt handlers
l language description
l lexical conventions l identifiers l data types l constants l statements l built-in functions l parameters l expressions l function invocation l $include l arrays and parameter lists l optimizations

3.1 AKD BASIC Program Structure

3.1.1 Local Variables

The notion of ‘scope’ is a key concept in AKD BASIC programs. By ‘scope’, we mean those parts of the program in which a particular name is ‘visible’. There are two levels of scope in AKD BASIC — global and local. Variables (and constant definitions, aliases, etc.) defined inside a ‘main’ definition, or a subroutine, function, or interrupt handler definition, are considered to be ‘local’ in scope (visible only within that function).

3.1.2 Global Variables

All other definitions (those occurring outside functions) are considered ‘global’ in scope (visible inside main, and inside any subroutine, function, or interrupt handler). For example, consider the following simple AKD BASIC program:
'-------------- Define (dim) Global Variables -
-------
dim i as integer
'-------------- Main Program ------------------
-------
Main
dim i as integer for i = 1 to 10 print "the cube of "; i; "is "; cube(i) call increment next i
End Main
Kollmorgen™ | March 30, 2012 20
AKD BASIC User Guide | 3 AKDBASICLanguage
'-------------- Subroutines and Functions -----
-------
function cube(i as integer) as integer
cube = i * i * i
end function sub increment
i = i + 1
end sub
This program prints a table of the cubes of the integers from 1 to 10. The first (global) definition of ‘i’ is visible inside subroutine ‘increment’, but ‘shadowed’ by the ‘i’ in main and function ‘cube’. The definition of ‘i’ inside ‘main’ is local to ‘main’, and is NOT the same variable as the ‘i’ inside the function ‘cube’, or inside the subroutine ‘increment’. These same scope rules apply to constant definitions and aliases, as well.

3.2 Program Sections

The major sections of an AKD BASIC program are:
l setup parameter definitions l global variables, constants, and aliases l ‘main’ program, subroutines, functions, and interrupt handlers
Although these sections may appear in any order, we recommend that you keep them in the order shown, or at least, choose a single layout style and use it consistently.

3.2.1 Program Template

The program below is an example of the template generated automatically by WorkBench:
'-------------- Device Params -----------------
------
Params
End Params
'-------------- Define (dim) Global Variables -
------­'-------------- Main Program ------------------
-------
Main
End Main
'-------------- Subroutines and Functions ----
--------
'-------------- Interrupt Routines -----------
--------
These sections are described in greater detail in the following paragraphs.

3.2.2 Setup Parameter Definitions

This section of the program defines the setup parameters for drive tuning and configuration. It is executed immediately upon power-up (if VM.AUTOSTART = 1), before entering main, and before any interrupts are enabled. The section begins with Param and ends with End Param
21 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
(this is similar to the format used to define a subroutine or function). The only statements per­mitted in this section are assignment statements of the form:
<parameter> = <constant expression>
This section can be automatically generated by WorkBench when a New Program is created. Choose "current drive parameters" to include the connected drive's setup parameters in your program. If you choose to not include the setup parameters in your program, be sure to save the setup parameters to the drive to ensure proper drive setup upon power up.

3.2.3 Global Variables, Constants, and Aliases

This section contains variables, constant definitions, and global alias expressions — they apply everywhere in the program, unless specifically overridden by another declaration at local scope (inside a subroutine, function, or interrupt handler). Global definitions may be placed almost anywhere in the program text — between subroutines, before or after ‘main’, and so on.
Global variables, constants, and aliases do not need to be defined before use — the only requirement is that they be defined at some point in the program text. You may have multiple instances of the global variables section throughout your program. However, as a matter of good programming style, we recommend that you keep all global definitions in one place, pref­erably at or near the beginning of your program.

3.2.4 Variable Definitions

The format of a global variable definition is:
dim a,b as integer, x,y,z as float dim ia(3,4) as integer dim s1, s2 as string*80 dim sa(5,2) as string dim j, k, l as integer NV
Line 1 declares a and b as integers, x,y, and z as floats. Line 2 declares a 3 x 4 array of integers. Line 3 declares s1 and s2 as strings, each of length 80. Line 4 declares sa as a 5 x 2 array of strings, each with the default length of 32 characters. Line 5 defines 3 integers, j, k, and l as NV.
In addition, global variables can be specified as ‘NV’ to indicate their values are retained when power is turned off. All other global variables are automatically initialized when the program begins (strings are set to empty, and floats and integers are set to 0). There are no restrictions on the ordering of volatile vs. non-volatile user-variables. For ease of program maintenance, place all non-volatile variables definitions in a single section at the beginning of the program, and add new variables to the end of that section.

3.2.5 Constant Definitions

The format of a constant declaration is:
const <name> = <constant_expression>
as in
const ARRAY_SIZE = 4 * NUMBER_OF_ENTRIES const PI_SQUARE = 3.1415926535 ^ 2 const GREETING = “Hello” const GREETING = “Hello” const NUMBER_OF_ENTRIES = 5
Kollmorgen™ | March 30, 2012 22
AKD BASIC User Guide | 3 AKDBASICLanguage
Names for constants follow the same rules as variable names. ‘Forward definitions’ are allowed. Circular definitions are detected and reported at compile-time. Although it is not required, it is convenient to adopt a convention of keeping all constants in UPPER_CASE, so you can easily distinguish between constants and variables in the program.
Constant definitions are entirely ‘folded’ at compile-time. Feel free to write maintainable con­stant expressions such as:
const LENGTH = 3 const WIDTH = 10 const AREA = LENGTH * WIDTH
The value of AREA is computed at compile-time, so the program does NOT need to compute this at run-time and the program is easier to maintain if LENGTH changes at some future date.

3.2.6 Alias Definitions

Aliases allow you to define your own names for system resources, such as input / output pins. The intention is to make it possible for you to use names that are meaningful to you in your par­ticular application. The format of an alias expression is:
alias <name> = <expression>
For example, the following alias defines application-specific uses of input # 1:
alias CONVEYOR_IS_RUNNING = (DIN1.STATE = 0) alias CONVEYOR_IS_STOPPED = (DIN1.STATE = 1) if CONVEYOR_IS_RUNNING then
print“running” else
print“stopped”
An alias is much more powerful than a constant. Constant expressions are computable at com­pile-time, while an alias has a value that is only known (in general) at the time it is used. Use ali­ases with care — too much aliasing can make it very difficult for you to understand the program.

3.3 Main Program, Subroutines, Functions & Interrupt Handlers

These sections share the same fundamental structure:
<section>
<declarations>
<statements>
<section end>
An example of each of these sections follows, with an explanation of key points.

3.3.1 Main Definitions

For main, a typical definition is:
Main
dim i as integer
i = 1
print i End Main
23 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
The variable ‘i’ defined above in the ‘dim’ statement is a local variable — it is not accessible to other functions, and inside ‘main’, its definition overrides any other variable named ‘i’ that might exist at global scope.
Unlike global variables, local variables MUST be defined at the beginning of the section — they must appear before any executable statement in main. For example, the following is illegal:
Main
dim i as integer
i = 1
dim j as integer ‘this is an error!
j = i
End Main
You may also define local constant definitions and aliases, provided that like local variables, they appear before any executable statement. Local constant definitions override global def­initions of the same name. For example, given the following global definitions,
const N = 1 Main
const N = “Hello, world!”
print N
call sub1 End Main
'-------------- Subroutines and Functions -----
-------
sub sub1
print N end sub
The program prints to the console:
Hello world! 1
Because the N visible inside main is the constant defined there, while the N visible to sub1 is the global constant N, whose value is 1.
The main program is the section of your program that is executed immediately after the‘params section, regardless of its position in the program text. Other functions, subroutines, and inter­rupt handlers are executed according to the flow of control defined in the program.
main does not accept arguments, and cannot be called from any other subroutine, function, or interrupt handler.

3.3.2 Subroutine Definition

For a subroutine such as print_sum, a typical definition is:
sub print_sum(i,j as integer)
print i+j end sub
The arguments to this subroutine are specified as integer variables, and are passed by value ­any assignments to these variables has no effect on the arguments supplied by the caller. Sub­routines are invoked by ‘call’ instructions, as in call print_sum(3,4).
Kollmorgen™ | March 30, 2012 24
AKD BASIC User Guide | 3 AKDBASICLanguage

3.3.3 Function Definition

For a function such as sum_squares, a typical definition is:
function sum_squares(i,j as integer) as integer
sum_squares = i^2 + j^2
end function
The function above returns a value of type integer. The value of the function is assigned by assigning to the name of the function, as if it were a variable.
It is not legal to use the function name as a variable name on the left-hand-side of an assignment - a function name on the leftt-hand-side is always an INVOCATION of that function.
There must be at least one statement in the function that assigns a value to the function. It is not possible to detect at compile-time if the statement will actually execute. Functions are invoked by name, as in print sum_squares(3,4). This is syntactically identical to an array ref­erence.

3.3.4 Interrupt Handler Definition

The Interrupt statment marks the beginning of an Interrupt Service Routine. The Interrupt Serv­ice Routine is defined by a program structure resembling a subroutine. The interrupt feature per­mits execution of a user-defined subroutine upon receipt of a hardware interrupt signal or a pre­defined interrupt event.
Interrupts are triggered by pre-defined events or external hardware sources. The interrupt­source-name and interrupt enable flag are unique for each interrupt source. For a list of interrupt sources see Interrupt {Source}.
Receiving an interrupt will suspend program execution and the interrupt service routine will be executed. Then program execution will resume at the point that it was interrupted.
Interrupts are enabled (or disabled) by setting (or clearing) the associated interrupt enable flag. Interrupts are disabled until explicitly enabled. After an interrupt is triggered it is automatically disabled until it is enabled again in your program.
Main
DRV.TIME = 0 INTR.DIN1LO = 1 'enables interrupt
while 1
pause(0.5)
DOUT1.STATEU=0 : Pause(0.005):DOUT1.STATEU=1
wend
end main
'the following interrupt defines what occurs for interrupt DIN1LO
Interrupt DIN1LO
print "I'm awake" If DRV.TIME > 10 then
print "OK. That's it."
else
INTR.DIN1LO = 1 're-enables interrupt
end if
End Interrupt
25 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
The interrupt is re-enabled by the statement INTR.DIN1LO = 1. A similar statement must be executed once before the interrupt is serviced. It is a run-time error to attempt to enable an inter­rupt for which no handler is defined.
Interrupt handlers do not return values and cannot have arguments. They declare local var­iables, constants, and aliases. Interrupt handlers are invoked when the AKD hardware detects that the designated interrupt condition is satisfied (provided that the interrupt is enabled).
Interrupts are triggered by pre-defined events or external hardware sources. The interrupt­source-name and interrupt enable flag are unique for each interrupt source.
Receiving an interrupt will suspend program execution and the interrupt service routine will be executed. Then program execution will resume at the point that it was interrupted.
Interrupts are enabled (or disabled) by setting (or clearing) the associated interrupt enable flag. Interrupts are disabled until explicitly enabled. After an interrupt is triggered it is automatically disabled until it is enabled again in your program.

3.4 Language Definition

3.4.1 Lexical Conventions

AKD BASIC is case-insensitive. String literals are not modified, but all other text is treated as if it were entered in upper case. This means that the identifiers spin, Spin, and SPIN all refer to the same entity.

3.4.2 Identifiers

Identifiers are alphanumeric and must start with an alphabetic character or underscore. In addi­tion, they may include the underscore character (‘_’) and dollar sign (‘$’). Identifiers denote var­iables, functions, subroutines, and statement labels, symbolic constants, and aliases. Identifiers are a maximum of 40 characters. User-defined identifiers may not include the period (‘.’). Use of a longer identifier is a compile-time error.
Although both forms are accepted for compatibility, the latter form is preferred. Although AKD BASIC is case-insensitive, we recommend that you adopt a consistent naming convention, such as Move.Acc, and avoid having Move.acc, move.acc, and move.Acc in the same pro­gram.

3.4.3 Data Types

The pre-defined types are INTEGER, FLOAT, and STRING. LONG is used for INTEGER. INTEGER variables are 32-bit signed integers. FLOAT variables are IEEE single-precision floating point numbers. STRING variables are represented internally as a maximum length, a current length, and an array of ASCII characters (can contain null characters).
When a FLOAT result is assigned to an INTEGER variable, or when a FLOAT argument is used where an INTEGER is expected, the value is coerced to an integer before use. Coercion from FLOAT to INT always rounds to the nearest integer. For example:
1.2 rounds to 1
1.7 rounds to 2
-1.2 rounds to –1
-1.7 rounds to -2
Scalar INTEGER and FLOAT coercion is automatically provided for function arguments. When passing ARRAYS as arguments, the types must match exactly because coercion is pro­hibitively expensive at run-time.
Kollmorgen™ | March 30, 2012 26
AKD BASIC User Guide | 3 AKDBASICLanguage
String assignment is checked at run-time. An attempt to copy a string to a destination too small results in a run-time error. String indexing is 1-origin. For example, mid$(“abc”,1,1) returns the string, a.
STRING variables have a firmware-imposed maximum length of 230 characters and a default maximum length of 32 characters. They may be assigned a different maximum length by declaring them to be of type STRING*n where n is a positive integer between 1 and 230 (inclu­sive).
Declare arrays of the pre-defined types. Arrays have a maximum rank of four dimensions. The upper-bound of each dimension has no compiler-defined limit. However, because of the limited data space of the controller, there is a logical upper-bound that depends on the controller model.
Array indexing is 1-origin. The indices in each dimension range from 1 to the upper-bound of the dimension. Every reference to an array element is checked at run-time. Any attempt to ref­erence beyond the bounds of the array causes a run-time error. New types cannot be defined.

3.4.4 Literal Constants

String constants begin and end with the double-quotes (‘"’). They cannot extend past the end of the input line. Any printable ASCII character appears in a string constant. An attempt to gen­erate a string literal with non-ASCII characters causes a compile-time error. No check is made to verify that non-ASCII strings are not created at run-time, so avoid doing so.

3.4.5 Decimal Integer Constants

Decimal integer constants are a string of decimal digits with no decimal point. A leading ‘-’ sign is optional and is parsed as a unary minus. For example:
1
-1
314159
are all valid decimal constants.

3.4.6 Hexadecimal Constants

Hexadecimal constants are denoted by a leading &H or &h, and cannot have a sign or decimal point. Hexadecimal constants are composed from the set [0-9A-Fa-f]. Upper- and lower-case may be mixed.
For example:
&h00ff
&HFF00
&H1234abcd
are all valid hexadecimal constants. Octal and binary constants are not supported.

3.4.7 Floating-Point Constants

Floating-point constants are specified in fixed-point or mantissa-exponent notation. A floating­point constant consists of one of the following.
digit [0-9] optsign ‘+’ | ‘-’ | /* nothing */ fixed optsign {digit}+ ‘.’ {digit}*optsign ‘.’ {digit}+ exp fixed ‘e’ optsign {digit}+ float fixed | exp
For example:
27 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
0.1 .1
-.1
-0.1
3.14159E-6
-1.0E6
are all valid floating point constants. By design, “.” is not a legal floating-point constant.

3.5 Statements

Statements are separated by a new line (CR-LF) or a colon (‘:’). The statements of the language are:

3.5.1 Alias

Create an alias for an identifier (not just any identifier). Alias is either a parameter or another alias. ID must be a legal variable name. You cannot create an alias for an array element.
Like Const definitions, Alias definitions can be made to identifiers not yet defined. Circular def­initions are not allowed.
Any duplicate definition of an identifier in the same scope is illegal. However, a local definition can shadow a definition from the global scope. Using a single identifier to denote two different objects is NOT allowed (i.e., you cannot have both a label and a variable named all_done).
Like constant, variable, and function declarations, Alias declarations made in the global scope are imported into all functions (including the main function).
Example:
Alias speed = MOTOR.SPEED ‘save some key-
strokes

3.5.2 Call

Call sub[(arg1, arg2, ...)]
sub is the name of a subroutine. The current program counter is saved and sub is invoked. When sub finishes (by reaching either an exit sub or end sub statement, control is returned to the statement logically following Call.
A subroutine is essentially a function with no return value. The parameter passing conventions followed by subroutines are the same as those followed by functions.

3.5.3 Cls

This statement transmits 40 line-feed characters (ASCII code = 10) to the serial port. Cls clears the display of the console.

3.5.4 Const

const name = x
Declares symbolic constants to be used instead of numeric values. Forward references are allowed, but circular references are not supported.
'supported
const x = y + 2
Kollmorgen™ | March 30, 2012 28
AKD BASIC User Guide | 3 AKDBASICLanguage
const y = 17
'unsupported
const x = y + 2 const y = x - 2
Like alias, variable, and function declarations, Const declarations made in the global scope are imported into all functions (including the main function).

3.5.5 Dim

Dim var1 [, var2 [...]] as type [NV]
All variables must be declared. Local variables must be declared in the function before use.
The NV specifier is used on a Dim statement in the global scope.
Variables in the global scope are automatically imported into functions and subroutines. Var­iables in function scope (including inside the main function) are not accessible in other func­tions.
Arrays cannot be assigned directly.
'This is not allowed
dim x(5), y(5) as integer
x = y
'Instead, a loop is needed:
dim x(5), y(5), i as integer for i = 1 to 5
next i

3.5.6 Exit

Exit {{Sub|Function|Interrupt|For|While}]
Exits the closest enclosing context of the specified type. It is a compile-time error to EXIT a construct not currently in scope.

3.5.7 For…Next

For loop_counter = Start_Value To End_Value [Step increment]
...statements...
Next
If step increment is not specified, uses 1 as the step increment. If step increment is positive, continues to the value of End_Value. If step increment is negative, continues to the value of var = limit.
The loop index variable must be a simple identifier, not an array element or a parameter and must be a numeric variable (integer or float).
x(i) = y(i)
for var = init to limit step delta
stlist
next var
Substantially more efficient code is generated if delta is a constant (i.e., the default value of 1 is used, or specified as an expression that is evaluated at compile-time).
29 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage

3.5.8 Function

Function function-name [(argument-list)] as function-type
...statements...
End Function
On function entry, all local variable strings are “” and all numeric locals are zero (including all ele­ments of local arrays). If the function takes no arguments, omit the argument-list. An empty argument-list is illegal. The value returned from the function is specified by assigning an iden­tifier with the name of the function.
Example:
function cube(x as float) as float
cube = x * x * x
end function
Arguments are passed by value. Arrays can not be returned by a function. Arrays passed to a function are passed by value.
If the return value is not set, a runtime error condition is generated (caught with ON ERROR).
Array actuals must conform with formals to the extent that they have the same number of dimensions, and EXACTLY the same type. The size of each dimension is available to the func­tion through the use of local constants that are bound on function entry.
Example:
function sum(x(n) as integer) as integer
dim i, total as integer
sum = 0
for i = 1 to n
next
sum = total
end function
This function exploits the fact that the variable N is automatically assigned a value when the function is called and the value is the extent of the array passed on invocation. N is a read-only variable in this context. Attempts to write to N cause compile-time errors.
The local variable, total is automatically initialized to 0 upon function entry.

3.5.9 GoTo

GoTo label
A program can only GoTo a label in the same scope. A GoTo may jump out of a For or While loop, but not INTO one.

3.5.10 If…Then…Else

if condition1 then
...statement block1...
elseif condition2 then
...statement block2...
else
...statement block3...
end if
total = total + x(i)
Kollmorgen™ | March 30, 2012 30
AKD BASIC User Guide | 3 AKDBASICLanguage
IF...THEN...ELSE statements control program execution based on the evaluation of numeric expressions. The IF...THEN...ELSE decision structure permits the execution of program state­ments or allows branching to other parts of the program based on the evaluation of the expres­sion.
There are two structures of IF... THEN...ELSE statements, single line and block formats.

3.5.11 $Include

$include inclfile $include include-file-name
Textually include inclfile at this point in the compilation. There can be no space between $ and include. The $include directive must start at the beginning of the line.

3.5.12 Input

input [prompt-string][,|;]input-variable
Input reads a character string received by the console tab in the program view, terminated by a carriage return.
As an option, the prompt message is transmitted when the Input statement is encountered. If the prompt string is followed by a semicolon, a question mark is printed at the end of the prompt string. If a comma follows the prompt string, no question mark is printed. This input statement is typically used for debugging purposes.

3.5.13 Interrupt … End Interrupt

interrupt {Interrupt-Source-Name}
...program statements...
end interrupt
Interrupt handlers can be located anywhere in the program text (e.g., before main).

3.5.14 MOVE.ABORT

MOVE.ABORT stops motor motion and allows continued program execution. Deceleration is determined by the controlled stop deceleration rate (CS.DEC).

3.5.15 MOVE.GOABS

MOVE.GOABS (Go Absolute) moves the motor to the position specified by MOVE.TA­RGETPOS. This position is based on a zero position at electrical home.
The motor speed follows a velocity profile as specified by MOVE.ACC, MOVE.RUNSPEED, and MOVE.DEC . Direction of travel depends on current position and target position only (MOVE.DIR has no effect). After the program initiates MOVE.GOABS, it immediately goes to the next instruction.
Change MOVE.ACC, MOVE.RUNSPEED, and MOVE.DEC during a move using MOVE.GOUPDATE.

3.5.16 MOVE.GOHOME

MOVE.GOHOME moves the motor shaft to the electrical home position (PL.FB = 0).
31 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
The motor speed follows a trapezoidal velocity profile as specified by MOVE.ACC, MOVE.RU­NSPEED, and MOVE.DEC. After the program initiates MOVE.GOHOME, it immediately goes to the next instruction.
MOVE.GOHOME performs the same action as setting MOVE.TARGETPOS to zero and executing a MOVE.GOABS function. Change MOVE.ACC, MOVE.DEC and MOVE.RU­NSPEED during a move using MOVE.GOUPDATE

3.5.17 MOVE.GOREL

MOVE.GOREL (Go Relative) moves the motor shaft a relative distance from the current posi­tion.
Distance, as specified in MOVE.RELATIVEDIST, is either positive or negative. The motor speed follows a trapezoidal velocity profile as specified by MOVE.ACC, MOVE.RUNSPEED, and MOVE.DEC.
The program does not wait for motion completion. After the program initiates this move it imme­diately goes to the next instruction.
Change MOVE.ACC, MOVE.RUNSPEED, and MOVE.DEC during a move using MOVE.GOUPDATE.

3.5.18 MOVE.GOUPDATE

MOVE.GOUPDATE (Update Move) updates a move in process with new variables. This allows you to change motion “on the fly” without having to stop and restart the motion function with new variables.

3.5.19 MOVE.GOVEL

MOVE.GOVEL (Go Velocity) moves the motor shaft at a constant speed.
The motor accelerates and reaches maximum speed as specified by MOVE.ACC and MOVE.RUNSPEED, with direction determined by MOVE.DIR. Stop motion by:
l Programming MOVE.ABORT for maximum deceleration allowed by current limits. l Programming MOVE.RUNSPEED = 0 for deceleration at rate set by MOVE.DEC.
After the program initiates MOVE.GOVEL, it immediately goes to the ne xt instruction.
Change variables during a move using MOVE.GOUPDATE.

3.5.20 On Error GoTo

On Error Goto Error-Handler-Name
or
On Error Goto 0
When a firmware runtime error condition occurs, Error-Handler-Name is called, the error handler is de-installed, and an internal flag (in-error-handler) is set. Any subsequent runtime error (includ­ing attempting to set the error handler, or return from the On Error handler) causes an immediate Stop.
On Error Goto 0 disables the current On Error handler. If an error occurs when no error handler is installed, Stop is invoked.
Kollmorgen™ | March 30, 2012 32
AKD BASIC User Guide | 3 AKDBASICLanguage

3.5.21 Pause( )

Pause(Pause_Time) causes the program to pause the amount of time specified by the Pause_ Time argument. The motion of the motor is not affected.

3.5.22 Print

print expression1 [ [,;] expression2 ] [;]
Print a list of expressions, separated by delimiters to the console. Any number of delimiters (including zero) can appear before or after the list of expressions. At least one delimiter must appear between each pair of expressions in the print list. The print statement is primarily used for debugging purposes.

3.5.23 Example

print ‘ print a newline print , ‘ advance a single tab stop print a,b ‘ print a and b, tab between print a,b, ‘ print a and b, tab between and at
end
print ,,,x,,, ‘ tab tab tab x tab tab tab

3.5.24 VM.RESTART

VM.RESTART clears the run time error variables and causes program execution to start again from the beginning of the program. Any Interrupts, Subroutines, WHEN statements or loops in process are aborted. This statement is used to continue program execution after a Run Time Error Handler or to abort from WHEN statements without satisfying the condition.
VM.RESTART does not clear the data area or change any program or motion variables.

3.5.25 Select Case

Select Case test-expression
Case expression-list1
Case expression-list2
Case expression-list3
Case Else
End Select
test-expression must evaluate to an INTEGER or FLOAT value.
expression-list1 is a non-empty list of case-defn, separated by commas.
There can be only one Case Else and, if present, it must appear as the last case. It is selected only if all other tests fail.
case-defn can be any of the following:
...statement block1...
...statement block1...
...statement block1...
...else block...
expr expr to expr (tests inclusive (closed range))
33 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
is relop expr (<, =, =, =, > ) is expr (equiv to “is = expr”)
Select-case statements where the case-defn expressions are composed solely of integer con­stants are evaluated much quicker at run-time. (Cases involving variables must be transformed to logically equivalent if-then-else statements.)

3.5.26 Static

Static var1 [, var2[...]] as type
where type is:
INTEGER 32 bit integer
FLOAT IEEE single precision float
STRING default length is 32 characters
Static is used for declaring variables before use. All variables (except parameters) must be declared before they can be used. The Static statement is used in a Function, Sub or Interrupt to specify that the specified variable's value be remembered even when the Function or Sub is finished. The next time that the Function, Sub or Interrupt is executed, the value will be avail­able.
Example:
Main
while 1
wend
End Main
'-------------- Subroutines and Functions -----
-------
sub MySub
dim x as integer 'value is forgotten static y as integer 'value is remembered
x= x + 1 y = y + 1
print x,y
end sub

3.5.27 Stop

Stops the execution of the program.

3.5.28 Sub…End Sub

Sub [argument-list]
...body of the sub-procedure...
End Sub
call MySub pause(1)
Declare a subroutine. Invoked via Call. Optionally takes arguments. As with Function, it is ille­gal to provide an empty parameter list (‘()’) if the subroutine takes no parameters.
Kollmorgen™ | March 30, 2012 34
AKD BASIC User Guide | 3 AKDBASICLanguage

3.5.29 Swap

Swap x, y
Swaps the values of the variables. The variable types must be the same. Does not work on arrays or strings.

3.5.30 When

When when-condition , when-action
When is used for very fast output response to certain input conditions. You specify the con­dition and action. Upon encountering When, program execution waits until the defined condition is satisfied. The program immediately executes the action and continues with the next line of the program.
The When statement provides latching of several variables when the When condition is sat­isfied. These variables are:
WHEN.DRVHANDWHEEL WHEN.FB1MECHPOS WHEN.PLCMD WHEN.DRVTIME WHEN.PLFB
The software checks for the defined condition at the 4Khz rate. The when action is queued up and executed immediately. The when action will be executed within 25 microseconds of the when condition being met.

3.5.31 While…Wend

While condition
...statement block...
Wend
While...Wend tells the program to execute a series of statements as long as an expression after the While statement is true.
If the expression is true, the loop statements between While and Wend are executed. The expression is evaluated again and if the expression is still true, the loop statements are executed again. This continues until the expression is no longer true. If the expression is not true, the statement immediately following the Wend statement is executed.

3.6 Built-in Functions

A function that takes a numeric argument (either FLOAT or INTEGER) returns the same type. Coercion between INTEGER and FLOAT is not performed unless necessary. (notation - the arguments n and m refer to INTEGER types, as in the definition of the MID$ function, whose signature is MID$(string, integer, integer).
Name Args Return Semantics
ABS numeric numeric absolute value ATAN float float arc tangent (radians) CINT numeric int truncate (round to nearest int) COS float float cosine
35 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
Name Args Return Semantics
EXP float float e ^ arg, arg 88.02969 (o/w overflow) FIX numeric int truncate (round toward zero) INT numeric int truncate (round towards -INFINITY) LOG float float natural log LOG10 float float log base 10 SGN numeric integer sign of argument: -1, 0, 1 SIN float float sine (radians) SQR float float square root of arg TAN float float tangent (radians)
String function Description
ASC string int ASCII code for 1st char
CHR$ int string
HEX$ int string
INKEY$ string
INSTR [pos],str1,str2 int
LCASE$ str str Returns lower-case copy of arg. LEFT$ str,n str Returns n leftmost chars of str. LEN str int Returns length of str in bytes. LTRIM$ str str Trim leading spaces.
MID$ str,n[,m] str
OCT$ n str Octal string representation of arg. RIGHT$ str,n str Rightmost n chars of str. RTRIM$ str str Trim trailing spaces. SPACE$ n str Returns a string of n spaces. STR$ n str Decimal string representation of str. STRING$ n,str str Return n copies of first char of str. TRIM$ str str Trim leading AND trailing spaces. UCASE$ str str Returns upper-case copy of arg. VAL str numeric Returns numeric value of str.
One-character string containing the character with the ASCII code of arg. If arg 255, returns CHR$(arg % 256).
Printable hexadecimal rep of arg (without lead­ing &H).
One-character string, read from serial port.R­eturns “” if no char available.
Index of str2 in str1, or 0 if not found. Optional first arg specifies where to start search (defaults to position 1).
Returns substring starting at position n [for up to to m bytes].

3.6.1 Parameters and Commands

The AKD BASIC language is augmented by a set of parameters, input\output parameters, and pre-defined commands., The parameters set motor-specific control parameters, and the pre­defined commands control the motor.
For example, MOVE.ACC, MOVE.DEC, and MOVE.RUNSPEED are used to set the accel­eration rate, deceleration rate, and commanded motor speed for the next commanded move:
Kollmorgen™ | March 30, 2012 36
AKD BASIC User Guide | 3 AKDBASICLanguage
MOVE.ACC = 1000.0 MOVE.DEC = 1000.0 MOVE.RUNSPEED = 500.0 MOVE.GOVEL
The program fragment above sets up the relevant motion parameters, and commands the motor to move at the specified velocity.
You cannot create variables (or function names, etc.) that shadow pre-defined ones. For a com­plete list of Parameters and commands, refer to the Parameter Guide section in this manual.

3.7 Expressions

3.7.1 Arithmetic Expressions

Arithmetic expressions (expressions involving INTEGER and FLOAT values) use the following operators.

3.7.2 Numeric Operators

Operators higher in the table have greater precedence than those below.
Operator Assoc Name
^ right exponentiation
- right unary minus * left multiply / left divide MOD left modulo + left add
- left subtract

3.7.3 Logical Operators

Operator Assoc Explanation
=, < >, ≥, ≤, <, > left the usual NOT, BITNOT right not, boolean not AND, BITAND left and, boolean and OR, BITOR, XOR, BITXOR left or, boolean or, xor, boolean xor
Logical expressions (as, for example, in the condition of an ‘if’ statement) also use these operators. Strings are concatenated with the ‘+’ operator. Logical expressions are formed from strings, using the comparison operators, NOT, AND, OR, and XOR, with the meaning of an empty string being FALSE, and a non-empty string being TRUE.
Integer values are coerced to floating point values as needed. Floating-point values are rounded when coerced to integer values.
Logical operators are NOT short-circuiting (i.e., when executing the code).
if a(x) or b(y) or c(z) then ...
if a(x) is true, b(y) and c(z) are still invoked.
BITxxx boolean operators are provided to support bitwise operations on integer values. They operate quite differently from their logical equivalents. For example:
2 and 1 has the value –1 (TRUE, since each operand is ‘true’), but 2 bitand 1 has the value 0 since no matching bits are 1).
37 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
Similarly, 3 or 4 has the value –1(TRUE since at least one operand is not FALSE), while 3 bitor 4 has the value 7 (the three lsb’s are set).
Remember that relational and logical operators return numeric values - 0 for FALSE and -1 for TRUE. Any value not equal to FALSE is considered to be logically equivalent to TRUE for pur­poses of the logical operators.
It is syntactically incorrect to code:
dim a, b, c, x as integer
x = a < b < c

3.7.4 String Operators

Operator Assoc Name
<, >, ≤, ≥ nonassoc string comparisons =, <> nonassoc string comparisons
left string concatenation
There is no implicit coercion between strings and numeric types. String comparison is case-sen­sitive. Relative comparisons are made using ASCII lexical ordering. The empty string sorts before all other strings. String comparison operators are non-associative because they evaluate to a numeric value.

3.7.5 Example

It makes no sense to say a$ = b$ = c$.
It is sensible to say x = a$ = b$
x is assigned the value TRUE if a$ is the same as b$, and FALSE otherwise.

3.8 Function Invocation

A function invocation is denoted as:
var = func(arg1, arg2, ..., argn)
The arguments are passed by value (i.e., modifications made to the formal parameters inside a function are not reflected in the actuals). Arrays are also passed by value to functions. Arrays cannot be returned by a function. A function of no arguments is invoked by using the function name alone. For example, if func_none takes no arguments, then func_none is correct and func_none() is invalid.
The return value of a function may not be ignored by the caller. If the return value of a function is regularly ignored, the function should be rewritten as a subroutine (a function with no return value).

3.8.1 $INCLUDE

Use $INCLUDE to textually include one file in another. The $INCLUDE facility is a simple, powerful way to create a consistent family of applications. By including source files containing commonly used functions, subroutines, constant definitions, aliases, etc., you have control over the source for each application. When you change the source, you update each appli­cation simply by recompiling (see Optimizations).
A file cannot include itself, either directly or indirectly. Include file nesting is allowed, but lim­ited to a pre-defined maximum depth (currently 16).
The path of an include file is relative to the directory of the included file, not the current working directory of the compiler. Suppose, for example, the source program is in directory C:\WORK,
Kollmorgen™ | March 30, 2012 38
AKD BASIC User Guide | 3 AKDBASICLanguage
and includes the file .C\H\HEADER, and the file HEADER includes COMMON. The compiler looks for COMMON in C:\H, not in C:\WORK.
C:\WORK A.BAS $INCLUDE “..\H\HEADER” C:\H HEADER $INCLUDE “COMMON”
Compilation errors occur when a file is included multiple times. For example, if B.BAS includes files MATH and INCL, and INCL also includes MATH, MATH is included twice, causing a com­pile-time error.
B.BAS $INCLUDE “MATH” $INCLUDE “INCL” INCL $INCLUDE “MATH”

3.9 Arrays and Function Parameter Lists

When an array parameter (formal) of a function or subroutine is declared, the number of dimen­sions is specified, but the extent of (number of elements in) each dimension is not specified. This allows the programmer some freedom when invoking such a function. For example, a func­tion may be defined to take a one-dimensional array and compute the sum of the elements in the array. A single function can be written to take a one-dimensional array of any size and cor­rectly compute the sum. (Because AKD BASIC checks array bounds at run time on each access, there is no risk that a function will read or write outside the bounds of the array.)
When a formal parameter to a function is an array, instead of specifying the extent of each dimension, a list of variables is used to both implicitly specify the number of dimensions and to hold the extent of each dimension. These variables are read-only and cannot be modified within the function.
Adopt a convention for assigning names to placeholders. One such convention is to use the name of the array with a numerical suffix. For example,
function f(a(a1,a2,a3) as integer) as integer
where a1, a2, and a3 are the variables that get the extents of the array, a.
The function f above would be called as follows:
dim x_array(3,4,5) as integer dim y_array(1,2,10) as integer print f(x_array()) + f(y_array())
In both invocations of f, the function correctly determines the extent of each dimension of the passed array.
Remember that when passing an array to a function, the type of the array must match EXACTLY with the type expected by the function. Unlike scalar arguments (implicitly coerced from float to int or int to float), arrays are NOT coerced. An attempt to pass an integer array to a function that expects a float array results in a compile-time error.

3.9.1 Optimizations

As mentioned in an earlier section, constant definitions are completely ‘folded’ at the point of definition. This is efficient code. Constant expressions inside AKD BASIC statements are also
39 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
folded under certain conditions. For example, in the statement:
const PI = 3.1415926535 Main
Print PI^2
End Main
The value of PI^2 is not computed at run-time. It is detected as a constant value and pre-com­puted by the compiler as a single literal constant to be printed.
Similarly, the literal constant 3*4*PI in
x = 3 * 4 * PI * x
is folded at compile-time, leaving only one multiplication to be performed at run-time.
However, certain constant expressions are not folded. For example:
x = 3 * PI * x * 4
is computed at run-time, involving 3 multiplications because the analysis of constant expres­sions does not attempt to exploit algebraic commutativity laws. Since the basic arithmetic oper­ators are ‘left associative’, you can ensure the best performance by grouping constant factors together towards the left (or using a new constant definition).
If a function is not referenced (transitively from MAIN, plus any interrupt handlers), the compiler does not generate code for it. So, you can freely $include libraries with unused code (e.g., a comprehensive library containing functions supporting several possible axis configurations). Although the compiler parses and type-checks all the included source, it does not generate code into the downloaded program.
If select-case cases are all constants, more efficient code is generated. If a case is a variable, the generated code is equivalent to a string of if-then-else statements for all cases.
If any of the cases is an open-ended range (e.g., is 10), or covers a large range (e.g., 1 to 1000), a fast table-lookup is generated.
If all of the cases are constant, and can be grouped into locally dense subsets, the fastest pos­sible code is generated — a binary search of dispatch tables, followed by an indirect jump through the table. If speed is a consideration, keep your cases constant and close together. (values form a reasonably dense set.)
The compiler performs limited dead-code elimination based on simple constant analysis. For example:
const DEBUGGING = FALSE Main
dim i, sum as integer for i = 1 to 10
sum = sum + i
if DEBUGGING then print “partial sum is
;sum
next i
End Main
Since the value of DEBUGGING is FALSE, the compiler recognizes that the printing of the par­tial sum never happens and does not generate the print statement. This allows you to place debugging code in strategic locations in your programs and effectively disable it when shipping a production version (shrinks the size of the generated code).
Kollmorgen™ | March 30, 2012 40
AKD BASIC User Guide | 3 AKDBASICLanguage
This dead-code elimination also applies to functions whose only point of reference lies in elim­inated code. The functions themselves become dead-code and no code is generated for their definitions.
The compiler does not eliminate the print statement from the following program:
dim DEBUGGING as integer Main
dim i, sum as integer
DEBUGGING = FALSE
for i = 1 to 10
sum = sum + i
if DEBUGGING print “partial sum is ”;sum
next i
End Main
In this case, the print statement never executes, but the code to implement is generated because the value of the integer DEBUGGING could be changed by the AKD’s Integrated Development Environment Debugger at runtime, causing the print statement to be executed!

3.10 ModBus TCP/IP

Modbus TCP/IP, or Modbus TCP, is a Modbus variant used for communications over TCP/IP networks, connecting over port 502. A max of 3 masters can be connected to one drive at any time. Modbus standard limits one master to 256 slaves. Modbus and Workbench (telnet) can be connected to the same drive at the same time. Because Modbus and Telnet are processed in the AKD’s background task, 5~10mS delay between messages will prevent over running the back ground task stack limits.

3.10.1 ModBus Parameter Table

For a list of parameters and their Modbus addresses, visit the Modbus Parameter Table.
For 64 bit to 32 bit mapping, visit Modbus 64-bit Parameters to 32-bit Mapping.

3.10.2 ModBus Register and Data Types

All predefined AKD parameters are Modbus 32 bit or 64 bit (some with and some without sign).
Because most HMI products don’t support 64 bit numbers, the AKD also has a series of match­ing 32 bit parameters. Ex: PL.FB is a signed 64 bit integer with address number 588. There is also PL.FB_32 as a signed 32 bit integer with address number 2072. PL.FB_32 is the lower two 16 bit registers of PL.FB.
Typical HMI tag addressing will need the additional “40000” be added to the Modbus address number. Ex: To create a tag in an HMI to read PL.FB_32, the address number 42072 should be used.
All AKD command parameter will require writing a “1” to trigger the command. Ex: DRV.EN is used to enable the drive. To trigger the command, send “1” as a 32 bit integer to address 254.

3.10.3 User Created Variables with Assigned Modbus Address Numbers

User variables can be assigned an Modbus address number. The range of available numbers is from 5000 to 5999. An example program:
Dim int2 as integer Dimflt1 as float Dim long1 as long
41 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
MBInfo
$MBMap32(5001, int2) $MBMap64(5003, long1) $MBMapfloat(5007, flt1)
End
'-------------- Main Program ------------------
-------
Main
'setup some data to be read
int2 = 262144
flt1 = 1.234
Long1 = 17179869184
End Main
Notice that address numbers have to be skipped for mapped varables larger than 16 bit. Ex: In the program above, 5001 was assigned for a 32 bit integer and then next number available would be 5003.

3.10.4 Drive Fault Table

The parameter MODBUS.FAULT1 to MODBUS.FAULT10 is used to read any drive fault con­dition. The fault parameters are loaded with the AKD fault code, starting with parameter MODO­BUS.FAULT1. DRV.CLRFAULT will reset the drive and clear out any data in MODBUS.FAULT1 to MODBUS.FAULT10.
HMI fault tables only need to monitor MODBUS.FAULT1, but report faults, if present, in 1 to
10.

3.10.5 Drive Parameter Scaling Over Modbus

The predefined AKD velocity, position, acceleration, and deceleration parameters use the Mod­bus scaling and do not use the “user units” configured in Workbench.
MODBUS.PSCALE
MODBUS.PIN
MODBUS.POUT
The default is 2^20 counts/ rev, 2^20 counts/sec, and 2^20 counts/sec^2
User defined variables, which have assigned Modbus address numbers, are not effected by this scaling.

3.10.6 Special Modbus AKD Parameters

MODBUS.DIO
Bit 0 to 6 DIN.STATES Bit 16 and 17 DOUT.STATES
MODBUS.DRVSTAT
Bit 0 Drive Active Bit 1 STO Status Bit 2 Pos Hw Limit Bit 3 Neg Hw Limit Bit 4 Pos Sw Limit Bit 5 Neg Sw Limit
Kollmorgen™ | March 30, 2012 42
AKD BASIC User Guide | 3 AKDBASICLanguage
MODBUS.DRV
Bit 0 Stop Bit 1 Enable
MODBUS.MOTOR
Bit 0 Has Brake Bit 1 Brake Release
MODBUS.HOME
Bit 0 Start Homing Bit 1 Set (current position as home position)
MODBUS.MT
Bit 0 Clear (clears motion task MT.NUM) Bit 1 Continue Bit 2 Load (load motion task MT.NUM) Bit 3 Set Bit 4 Move (start move of MT.NUM)
MODBUS.SM
Bit 0 One Direction (sets SM.MODE to either 0 or 1)
Start Move:
Edge triggered
Bit 1
0 → 1 : Start motion (execution of SM.MOVE)
1 → 0 : Stop motion (execution of DRV.STOP)

3.10.7 ModBus Dynamic Mapping

For information on Modbus Dynamic Mapping visit Modbus Dynamic Mapping under Fieldbus Manuals.

3.11 Cam Profiling

In the AKD, a cam is a cyclic, generally non-linear relationship between master encoder posi­tion and slave (motor) position. The relationship between slave and master counts is no longer a constant ratio, but changes as a function of master counts. As in electronic gearing, once a cam is active, the program no longer needs to do anything special to maintain it - the motion pro­file is repeated indefinitely until the cam is deactivated.
In camming terminology, a master is typically an external encoder. The encoder is wired into the AKD BASIC encoder input port on X9. It is also possible to use the AKD BASIC’s virtual (internal) encoder.

3.11.1 Procedure

To use a cam profile on the AKD BASIC, you must:
1. Create the cam profile (CAM.CREATE).
2. Activate the cam profile (CAM.ACTIVATE).

3.11.2 Related Variables

CAM.MASTER: Specifies the source of the input to the cam table for cam profiling.
43 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
Knife
r
M2 M3
M5
CAM.CORRECTDIR: Specifies the direction of the correction move that is done when a new cam table is activated (by setting CAM.ACTIVATE = n).
CAM.ADDPOINT: Adds the specified “point” (master position and corresponding slave posi­tion) to the cam table being created.

3.11.3 Cam Wizard

The Cam Wizard is designed to solve cut to length applications. The picture below shows a typ­ical setup:
In this application, material is being fed beneath a rotary knife. The master encoder measures forward movement of the material under the knife. The slave motor controls rotation of the knife. In order for this to work properly, the slave motor must be controlled (as a function of master encoder counts) so the blade of the rotary knife:
1.
Stays out of the way until the proper amount of material has passed
2. Accelerates so the speed of the knife matches the speed of the material during the cut
3.
Decelerates back to the original speed until the material is almost in position for the next cut
The rotary knife either accelerates or decelerates to match the speed of the material in the cut phase, depending on whether or not the circumference of the rotary knife is less than or greater than the length of the piece to be cut. You may need to inter­change the terms ‘accelerate’ and ‘decelerate’, or simply think of them as signed quan­tities.
AKD BASIC’s CAM.ADDPOINT statement specifies a cam profile as a mapping from master position to slave position. The problem refers to relative velocities and accelerations. It is not always clear how to get from velocity and acceleration to position.
The Cam Wizard was designed to make such applications easy to implement. You provide:
1.
The master positions corresponding to the length of material to be cut
2.
The slave positions corresponding to one complete rotation of the knife with respect to the master positions
Once you have provided these three pieces of information, the Cam Wizard automatically:
1.
Generates a subroutine to create the cam table
2.
Generates a subroutine to activate the cam
Kollmorgen™ | March 30, 2012 44
AKD BASIC User Guide | 3 AKDBASICLanguage
0
500
1000
1500
2000
-500
-1000
-1500
-2000
2000
4000
6000
8000
10000
12000
Master Encoder Counts
Slave Position

3.11.4 Example

You can create a cam to approximate any continuous function, but the Cam Wizard cannot help you with it. The basic technique is to develop an AKD BASIC expression (or function)defining the slave position as a function of master position and use it to generate a series of CAM.AD­DPOINT statements at appropriate master position intervals, such as the one shown in the next figure.

3.11.5 Program

'-------------- Device Params -----------------
------
Params End Params
'-------------- Define (dim) Global Variables -
-------
const MC = 10000 'master counts in total cycle const NPOINTS = 501 'number of points in cam
profile
const pi = 3.1415926535 const k = 0.69314718 / 100 const w = 1 / (7.5 * pi)
'-------------- Main Program ------------------
-------
Main
sinusoidal
since we are computing
onds will elapse
45 Kollmorgen™ | March 30, 2012
CAM.ACTIVATE = 0 'Turn off any active cams CAM.MASTER = 1 'Master = virtual encoder only CAMVM.DIR = 0 'set direction of virtual master
CAMVM.FREQ = 1000 'set virtual master speed
'Generate a cam that does exponentially-damped
'motion and activate it. Please note that
'500 points of slave profile here several sec-
'during the calculation of the cam table.
call CamCreate_2
AKD BASIC User Guide | 3 AKDBASICLanguage
call ActivateCam_2
CAMVM.GOVEL 'virtual master to run at
CAMVM.FREQ
While 1 : Wend
End Main
'-------------- Subroutines and Functions -----
-------
Sub CamCreate_2'This code creates a cam whose
profile is an exponentially damped sine wave.
dim m, s as float dim i as integer
CAM.CREATE (2,501)
for i = 0 to NPOINTS-1
w * i)'computed slave position
Next i
End CAM.CREATE
End Sub
m = i * (MC / (NPOINTS-1))'master position s = (1 / exp (1.5 * k * i)) * sin (2 * pi *
CAM.ADDPOINT(m, 65536 * s)
Sub ActivateCam_2
DRV.SWENABLE = 0 'Need to disable the drive
before changing positions
MOVE.POSCOMMAND = 0 'Zero out slave position EXTENCODER.POSITION = 0 'Zero out real master
encoder position
CAMVM.POSITION = 0 'Zero out virtual master
encoder position
EXTENCODER.POSMODULO = MC 'Set master modulo
value
PL.MODPEN = 1 'Enable slave modulo PL.MODP2 = 65536 'Set slave modulo value DRV.SWENABLE = 1 'Enable drive CAM.ACTIVATE = 2 'Start the cam
End Sub

3.11.6 Virtual encoder (virtual master)

The virtual encoder is an internal count generator that is used as the input to the cam. It is con­trolled much like the profile generator used to control the motion of the motor. The Parameters and statements associated with the virtual encoder are listed below:
CAMVM.DIR
CAMVM.FREQ
CAMVM.GOREL
CAMVM.GOUPDATE
CAMVM.GOVEL
CAMVM.MOVING
CAMVM.POSITION
Kollmorgen™ | March 30, 2012 46
AKD BASIC User Guide | 3 AKDBASICLanguage
CAMVM.RELATIVEDIST
CAMVM.STOP

3.11.7 Move Parameters

CAMVM.DIR specifies direction for CAMVM.GOVEL
CAMVM.RELATIVEDIST specifies distance for CAMVM.GOREL
CAMVM.FREQ specifies speed (frequency) for CAMVM.GOREL and CAMVM.GOVEL

3.11.8 Move Statements

CAMVM.GOREL executes incremental move
CAMVM.GOVEL executes velocity move
CAMVM.GOUPDATE updates move parameters on move in progress
CAMVM.STOP stops motion

3.11.9 Other Variables

CAMVM.POSITION gives the value of the internal counter
CAMVM.MOVING indicates whether a move is in progress
The virtual encoder is used as the input to the cam, either alone (as a virtual master) or in com­bination with the actual encoder (EXTENCODER.POSITION), to add an offset to the master position. This functionality is controlled by the variable, CAM.MASTER.
47 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
4 Quick Reference: Parameters, Functions, Oper­ators
This section contains the functions, parameters, statements and variables available for AKD BASIC.The tables below list all the parameters that can be called in the program view.

4.1 AKD Parameters and Commands

This table lists the parameters and commands from the AKD Base Drive documentation that are available in AKD BASIC. For detailed descriptions of each parameter click the links below or visit Appendix A of the AKD User Manual.
Parameter or Command Type Description Analog Input (AIN)
AIN.CUTOFF NV Sets the analog input low-pass filter cutoff frequency. AIN.DEADBAND NV Sets the analog input signal deadband. AIN.DEADBANDMODE NV Sets the analog input deadband mode. AIN.ISCALE NV Sets the analog current scale factor. AIN.MODE NV Analog input mode AIN.OFFSET NV Sets the analog input offset. AIN.PSCALE NV Sets the analog position scale factor. AIN.VALUE R/O Reads the value of the analog input signal. AIN.VSCALE NV Sets analog velocity scale factor. AIN.ZERO Command Zeroes the analog input signal.
Analog Output (AOUT)
AOUT.CUTOFF NV Sets the analog output low-pass filter cutoff frequency.
AOUT.ISCALE NV Sets the analog current scale factor. AOUT.MODE NV Sets the analog output mode. AOUT.OFFSET NV Sets the analog input offset. AOUT.PSCALE NV Sets the analog position scale factor. AOUT.VALUE NV Reads the analog output value. AOUT.VALUEU R/W Sets the analog output value. AOUT.VSCALE NV Sets the velocity scale factor for analog output.
Capture (CAP)
CAP0.EDGE, CAP1.EDGE
CAP0.EN, CAP1.EN NV Enables or disables the related capture engine. CAP0.EVENT,
CAP1.EVENT CAP0.FILTER,
CAP1.FILTER CAP0.MODE,
CAP1.MODE CAP0.PLFB,
CAP1.PLFB CAP0.PREEDGE,
CAP1.PREEDGE
NV Selects the capture edge.
NV Controls the precondition logic.
R/W Controls the precondition logic.
NV Selects the captured value.
R/O Reads captured position value.
NV Selects the capture precondition edge.
Kollmorgen™ | March 30, 2012 48
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter or Command Type Description
CAP0.PREFILTER,
NV Sets the filter for the precondition input source.
CAP1.PREFILTER CAP0.PRESELECT,
NV Sets the precondition trigger.
CAP1.PRESELECT CAP0.STATE,
R/O Indicates whether or not trigger source was captured.
CAP1.STATE CAP0.T, CAP1.T R/O Reads time capture (if time capture was configured). CAP0.TRIGGER,
NV Specifies the trigger source for the position capture.
CAP1.TRIGGER
Controlled Stop (CS)
CS.DEC NV Sets the deceleration value for the controlled stop process. CS.STATE NV Returns the internal status of the controlled stop process. CS.TO NV Sets the time value for the drive velocity to be within CS.VTHRESH . CS.VTHRESH NV Sets the velocity threshold for the controlled stop.
Digital Input (DIN)
DIN.ROTARY R/O Reads the rotary knob value. DIN.STATES R/O Reads the digital input states. DIN1.FILTER TO
R/W Filter mode for digital inputs 1 to 7.
DIN7.FILTER DIO9.INV to DIO11.INV R/W DIO9.INV to DIO11.INV DIN1.MODE to
NV Sets the digital input modes.
DIN19.MODE DIN1.STATE TO
R/O Reads a specific digital input state.
DIN7.STATE
DIN9.STATE to
NV Shows on selected pin if signal is high or low.
DIN11.STATE
DIO
DIO9.INV to DIO11.INV NV Inverting the output voltage of the IO, when in the output direction. DIO9.DIR to DIO11.DIR NV Changing direction of the IOs from the X9 connector.
Digital Output (DOUT)
DOUT.RELAYMODE R/W Indicates faults relay mode. DOUT.STATES R/O Reads the state of the two digital outputs. DOUT8.MODE to
NV Sets the digital output mode.
DOUT11.MODE DOUT1.PARAM AND
NV Sets extra parameters for the digital outputs.
DOUT2.PARAM DOUT1.STATE AND
R/O Reads the digital output state.
DOUT2.STATE DOUT1.STATEU AND
R/W Sets the state of the digital output node.
DOUT2.STATEU
DOUT9.STATE to
NV Shows on selected pin if signal is high or low.
DOUT11.STATE DOUT9.STATEU to
NV Allows user to set level of selected pin to high or low.
DOUT11.STATEU
Drive (DRV)
DRV.ACC NV Describes the acceleration ramp for the velocity loop.
49 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter or Command Type Description
DRV.ACTIVE R/O Reads the enable status of an axis.
DRV.BLINKDISPLAY Command Causes the display to blink for 10 seconds. DRV.CLRFAULTHIST Command Clears the fault history log in the NV. DRV.CLRFAULTS Command Tries to clear all active faults in the drive. DRV.CMDSOURCE NV Sets the command source (service, fieldbus, analog input, gearing,
digital, or Bode).
DRV.DBILIMIT NV Sets the maximum amplitude of the current for dynamic braking.
DRV.DEC NV Sets the deceleration value for the velocity loop.
DRV.DIR R/W Changes drive direction. DRV.DIS Command Disables the axis (software). DRV.DISSOURCES R/O Returns the possible reason for a drive disable.
DRV.DISTO R/W Sets the emergency timeout.
DRV.EMUEDIR R/W Sets the direction of the emulated encoder output (EEO) signal. DRV.EMUEMODE R/W Sets the mode of the emulated encoder output (EEO) connector. DRV.EMUEMTURN R/W Defines the location of the index pulse on the EEO (emulated
encoder output) when DRV.EMUEMODE=2. DRV.EMUERES R/W Sets the resolution of the EEO (emulated encoder output). DRV.EMUEZOFFSET R/W Sets the location of the EEO (emulated encoder output) index pulse
(when DRV.EMUEMODE=1). DRV.EN Command Enables the axis (software).
DRV.FAULT1 to
R/O Location of fault codes for any active fault conditions.
DRV.FAULT10
DRV.HANDWHEEL R/O Reads the EEO input value.
DRV.HANDWHEELSRC NV Selects the feedback for handwheel operation. DRV.HWENABLE R/O Status of the hardware enable .
DRV.ICONT R/O Reads the continuous rated current value. DRV.IPEAK R/O Reads the peak rated current value. DRV.NAME NV Sets and reads the name of the drive. DRV.NVLOAD W/O Loads all data from the NV memory of the drive into the RAM param-
eters. DRV.NVSAVE Command Saves the drive parameters from the RAM to the NV memory. DRV.OPMODE NV Sets the drive operation mode (current, velocity, or position). DRV.RSTVAR Command Sets default values in the drive without re-booting the drive and with-
out resetting the NV memory. DRV.SETUPREQBITS R/O Reads the bitwise set status of parameters that must be set before
the drive can be enabled DRV.STOP Command This command stops all drive motion.
DRV.TIME R/W A continuous time counter in the drive. DRV.WARNING1 to
R/O Location of fault codes for any active warning conditions.
DRV.WARNING10
Fault (FAULT)
FAULTx.ACTION R/W Gets/Sets the Fault Action for Fault 130, 131, 132, 134, 139, 451, and
702.
Feedback 1 (FB1)
FB1.BISSBITS NV Specifies the number of Biss Sensor (Position) Bits for the BiSS
Mode C encoder in use.
Kollmorgen™ | March 30, 2012 50
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter or Command Type Description
FB1.ENCRES NV Sets the resolution of the motor encoder. FB1.HALLSTATE R/O Reads the Hall switch values (encoder feedback FB1.HALLSTATEU R/O Reads the state of Hall switch U. FB1.HALLSTATEV R/O Reads the state of Hall switch V. FB1.HALLSTATEW R/O Reads the state of Hall switch W. FB1.IDENTIFIED R/O Reads the type of feedback device used by the drive/motor. FB1.INITSIGNED NV Sets initial feedback value as signed or unsigned. FB1.MECHPOS R/O Reads the mechanical position. FB1.MEMVER R/O Returns the memory feedback version.
FB1.ORIGIN NV Adds to the initial feedback position. FB1.P R/O Reads position from the primary feedback. FB1.PDIR NV Sets the counting direction for feedback channel 1.
FB1.POFFSET NV FB1.POFFSET FB1.POLES R/O Reads the number of feedback poles.
FB1.PSCALE R/W Sets position scaling value for fieldbus transferred position objects. FB1.PUNIT NV Sets the unit for FB1.P.
FB1.SELECT NV Sets user entered type or identified type (–1).
Feedback 2 (FB2)
FB2P.DIR R/W FB2P.DIR FB2.ENCRES NV Sets the secondary feedback (FB2) resolution.
FB2.MODE R/W Sets the mode for the second feedback inputs, EEO connector (X9)
and high speed opto inputs (pins 9 and 10 on X7).
FB2.P R/O Reads position from the secondary feedback. FB2P.DIR NV Sets the counting direction for feedback channel 2. FB2.POFFSET NV Sets the offset for secondary feedback. FB2.PUNIT NV Sets the unit for FB2.P.
FB2.SOURCE R/W Sets the source for the second feedback input. Choices are the EEO
connectors (X9) which are RS485 inputs, or the X7 connector’s high
speed opto inputs (pins 9 and 10).
Feedback 3 (FB3)
FB3.MODE NV Selects the type of feedback connected to X9. FB3.POFFSET NV Sets the offset for tertiary feedback. FB3.PUNIT NV Sets the unit for FB3.P.
Hardware Limit Switch (HWLS)
HWLS.NEGSTATE R/O Reads the status of the negative hardware limit switch. HWLS.POSSTATE R/O Reads the status of the positive hardware limit switch.
Current Loop (IL)
IL.BUSFF R/O Displays the current feedforward value injected by the fieldbus.
IL.CMD R/O Reads the value of the q-component current command. IL.CMDU R/W Sets the user current command. IL.DIFOLD R/O Reads the drive foldback current limit. IL.FB R/O Reads the actual value of the d-component current.
IL.FF R/O Displays the current loop overall feedforward value.
IL.FOLDFTHRESH NV Reads the foldback fault level.
51 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter or Command Type Description
IL.FOLDWTHRESH NV Sets the foldback warning level. IL.IFOLD R/O Reads the overall foldback current limit. IL.IUFB R/O Reads the sigma-delta measured current in the u-winding of the
motor. IL.IVFB R/W Sets the sigma-delta measured current in the u-winding of the motor. IL.KP NV Sets the proportional gain of the q-component of the PI regulator. IL.KPDRATIO NV Sets the proportional gain of the d-component current PI-regulator as
a percentage of IL.KP IL.LIMITN NV Sets the negative user (application-specific) current limit. IL.LIMITP NV Sets the positive user (application-specific) current limit. IL.MFOLDD NV Sets the motor foldback maximum time at motor peak current. IL.MFOLDR R/O Sets the motor foldback recovery time. IL.MFOLDT NV Sets the motor foldback time constant of the exponential current drop
(foldback). IL.MIFOLD R/O Sets the motor foldback current limit. IL.VCMD R/O Sets the output of the q-component PI regulator. IL.VUFB R/O Reads the measured voltage on the u-winding of the motor. IL.VVFB R/O Reads the measured voltage on the v-winding of the motor.
LOAD Parameters
LOAD.INERTIA NV Sets the load inertia.
Motor Parameters
MOTOR.BRAKE NV Sets the presence or absence of a motor brake.
MOTOR.BRAKERLS Command Allows a user to release the motor brake.
MOTOR.ICONT NV Sets the motor continuous current. MOTOR.INERTIA NV Sets the motor inertia. MOTOR.IPEAK NV Sets the motor peak current. MOTOR.KE NV Sets the motor back EMF constant. MOTOR.KT NV Sets the torque constant of the motor. MOTOR.LQLL NV Sets the line-to-line motor Lq. MOTOR.NAME NV Sets the motor name. MOTOR.PHASE NV Sets the motor phase. MOTOR.PITCH NV Sets the motor pitch. MOTOR.POLES NV Sets the number of motor poles. MOTOR.R NV Sets the stator winding resistance phase-phase in ohms. MOTOR.TBRAKEAPP NV The delay time used for applying the motor brake. MOTOR.TBRAKERLS NV The delay time used for releasing the motor brake. MOTOR.TEMP R/O Reads the motor temperature represented as the resistance of the
motor PTC. MOTOR.TEMPFAULT NV Sets the motor temperature fault level. MOTOR.TEMPWARN NV Sets the motor temperature warning level. MOTOR.TYPE NV Sets the motor type. MOTOR.VOLTMAX NV Sets the motor maximum voltage.
Position Loop (PL)
PL.CMD NV Reads the position command directly from the entry to the position
loop.
Kollmorgen™ | March 30, 2012 52
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
PL.ERR NV Reads the position error present when the drive is controlling the posi-
tion loop. PL.ERRFTHRESH NV Sets the maximum position error.
PL.ERRMODE R/W Sets the type of following error warning and fault usage.
PL.ERRWTHRESH NV Sets the position error warning level. PL.FB R/O Reads the position feedback value. PL.FBSOURCE NV Sets the feedback source for the position loop. PL.INTINMAX NV Limits the input of the position loop integrator by setting the input sat-
uration. PL.INTOUTMAX NV Limits the output of the position loop integrator by setting the output
saturation. PL.KI NV Sets the integral gain of the position loop. PL.KP NV Sets the proportional gain of the position regulator PID loop.
PL.MODP1 R/W Sets modulo range parameter. PL.MODP2 R/W Sets the beginning or end modulo range parameter.
Programmable Limit Switch (PLS)
PLS.EN R/W Enables programmable limit switch (PLS). PLS.MODE NV Selects programmable limit switch mode. PLS.P1 TO PLS.P8 NV Sets the trigger point for programmable limit switches.
PLS.RESET W/O Resets programmable limit switch.
PLS.STATE R/O Reads the programmable limit switch state.
PLS.T1 TO PLS.T8 R/W Sets programmable limit switch time. PLS.UNITS R/W Sets programmable limit switch (PLS) units. PLS.WIDTH1 TO
R/W Programmable Limit Switch Width
PLS.WIDTH8
Recorder (REC)
REC.ACTIVE R/O Indicates if data recording is in progress (active). REC.DONE R/O Checks whether or not the recorder has finished recording. REC.OFF R/W Turns the recorder OFF. REC.TRIG Command Triggers the recorder.
Regen Resistor (REGEN)
REGEN.POWER R/O READS REGEN RESISTOR'S CALCULATED POWER. REGEN.REXT N/V SETS THE EXTERNAL, USER-DEFINED REGEN RESISTOR
RESISTANCE. REGEN.TEXT R/W Sets the external regen resistor thermal protection time constant. REGEN.TYPE N/V SETS THE REGEN RESISTOR TYPE. REGEN.WATTEXT R/W SETS THE REGEN RESISTOR'S POWER FAULT LEVEL FOR AN
EXTERNAL REGEN RESISTOR.
STO
STO.STATE R/O Returns the status of the safe torque off.
SWLS
SWLS.EN NV Enables and disables software travel limit switches. SWLS.LIMIT0 NV Sets the position of the software travel limit switch 0. SWLS.LIMIT1 NV Sets the position of the software travel limit switch 0.
53 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
SWLS.STATE R/O Reads the actual status of software limit switches.
Units (UNIT)
UNIT.ACCLINEAR NV Sets the linear acceleration/deceleration units. UNIT.ACCROTARY NV Sets the rotary acceleration/deceleration units. UNIT.LABEL NV Sets user-defined name for user-defined position units. UNIT.PIN NV Sets gear IN for the unit conversion. UNIT.PLINEAR NV Sets the linear position units. UNIT.POUT NV Sets gear out for the unit conversion. UNIT.PROTARY NV Sets the position units when the motor type (MOTOR.TYPE ) is rotary. UNIT.VLINEAR NV Sets the linear velocity units. UNIT.VROTARY NV Sets the velocity units when the motor type (MOTOR.TYPE ) is rotary.
Bus Voltage (VBUS)
VBUS.OVFTHRESH R/O Reads the over voltage fault level. VBUS.OVWTHRESH NV Sets voltage level for over voltage warning. VBUS.RMSLIMIT R/O Reads the limit for the bus capacitors load. VBUS.UVFTHRESH R/W Sets the under voltage fault level. VBUS.UVMODE NV Indicates undervoltage (UV) mode. VBUS.UVWTHRESH NV Sets voltage level for undervoltage warning. VBUS.VALUE R/O Reads DC bus voltage.
Velocity Loop (VL)
VL.ARPF1 TO VL.ARPF4
R/W Sets the natural frequency of the pole (denominator) of anti-resonance
(AR) filters 1, 2, 3, and 4; active in opmodes 1 (velocity) and 2 (posi-
tion) only. VL.ARPQ1 TO
VL.ARPQ4 VL.ARTYPE1 TO VL.A-
RTYPE4 VL.ARZF1 TO
VL.ARZF4 VL.ARZQ1 TO
VL.ARZQ4
R/W Sets the Q of the pole (denominator) of anti-resonance (AR) filter 1;
active in opmodes 1 (velocity) and 2 (position) only.
NV Indicates the method used to calculate BiQuad coefficients; active in
opmodes 1 (velocity) and 2 (position) only.
R/W Sets the natural frequency of the zero (numerator) of anti-resonance
(AR)filter 1; active in opmodes 1 (velocity) and 2 (position) only.
R/W Sets the Q of the zero (numerator) of anti-resonance filter #1; active in
opmodes 1 (velocity) and 2 (position) only. VL.BUSFF R/O Displays the velocity loop feedforward value injected by the field-bus;
active in opmodes 1 (velocity) and 2 (position) only. VL.CMD R/O Reads the actual velocity command; active in opmodes 1 (velocity)
and 2 (position) only. VL.CMDU R/W Sets the user velocity command; active in opmodes 1 (velocity) and 2
(position) only. VL.ERR R/O Sets the velocity error; active in opmodes 1 (velocity) and 2 (position)
only. VL.FB R/O Reads the velocity feedback; active in opmodes 1 (velocity) and 2
(position) only. VL.FBFILTER R/O Filters VL.FB value; active in opmodes 1 (velocity) and 2 (position)
only. VL.FBSOURCE NV Sets feedback source for the velocity loop; active in opmodes 1 (veloc-
ity) and 2 (position) only. VL.FBUNFILTERED R/O Reads the velocity feedback.
Kollmorgen™ | March 30, 2012 54
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
VL.FF R/O Displays the velocity loop overall feedforward value; active in
opmodes 1 (velocity) and 2 (position) only. VL.GENMODE NV Selects mode of velocity generation (Observer, d/dt); active in
opmodes 1 (velocity) and 2 (position) only. VL.KBUSFF R/W Sets the velocity loop acceleration feedforward gain value; active in
opmodes 1 (velocity) and 2 (position) only. VL.KI NV Sets the velocity loop integral gain for the PI controller; active in
opmodes 1 (velocity) and 2 (position) only. VL.KP NV Sets velocity loop proportional gain for the PI controller; active in
opmodes 1 (velocity) and 2 (position) only. VL.KVFF R/W Sets the velocity loop velocity feedforward gain value; active in
opmodes 1 (velocity) and 2 (position) only. VL.LIMITN NV Sets the velocity lower limit; active in opmodes 1 (velocity) and 2 (posi-
tion) only. VL.LIMITP NV Sets the velocity high limit; active in opmodes 1 (velocity) and 2 (posi-
tion) only. VL.LMJR R/W Sets the ratio of the estimated load moment of inertia relative to the
motor moment of inertia; active in opmodes 1 (velocity) and 2 (posi-
tion) only. VL.THRESH NV Sets the over speed fault value; active in opmodes 1 (velocity) and 2
(position) only.
Wake and Shake (WS)
WS.ARM Command Sets wake and shake to start at the next drive enable.
WS.DISARM Command Cancels ARM requests and resets wake and shake to the IDLE state. WS.DISTMAX R/W Sets maximum movement allowed for wake and shake.
WS.DISTMIN R/W Sets the minimum movement required for wake and shake. WS.IMAX R/W Sets maximum current used for wake and shake. WS.MODE R/W Sets the method used for wake and shake. WS.NUMLOOPS R/W Sets the number of repetitions for wake and shake. WS.STATE R/O Reads wake and shake status WS.T R/W Sets wake and shake current-vector appliance time WS.TDELAY1 NV Delay for wake and shake timing WS.TDELAY2 NV Sets the delay for wake and shake timing. WS.TDELAY3 NV Sets the delay for wake and shake between loops in mode 0. WS.VTHRESH NV Defines the maximum allowed velocity for Wake & Shake
4.2 AKDBASICParameters and Commands
The following table lists parameters, commands, functions, and operators unique to AKD BASIC. For detailed descriptions of each parameter click the links below or visit the AKD BASIC Parameters chapter of the AKD BASIC User Manual.
Parameter Type Description Additional Statements
$Include Statement The $Include statement allows you to textually include mul-
Alias Statement Allows you to define your own names for system
55 Kollmorgen™ | March 30, 2012
tiple separate files in a single source file.
resources, such as Input or Output pins.
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter Type Description
Call Statement Transfer program control to a subroutine. When the sub-
routine is finished then control is transferred to the line fol­lowing the CALL.
Cls Statement This statement transmits 40 line feed characters (ASCII
code = 10) to the serial port. Cls clears the display of a ter­minal.
Const Statement Declares symbolic constants to be used instead of numeric
values.
Dim Statement Used for declaring variables before use. All variables
(except predefined variables) must be declared before they can be used.
Exit Statement The Exit statement is used to exit from a subroutine, a func-
tion, an interrupt, a For...Next or a While...Wend.
For...Next Statement Allows a series of lines to be executed in a loop a specified
number of times.
Function Statement The Function statement is used to declare and define the
name, arguments and type of a user defined function.
GoTo Statement GOTO causes the software to jump to the specified label
and continue executing from there.
If...Then...Else Statement If...Then...Else statements controls program execution
based on the evaluation of numeric or string expressions.
Input Statement The Input statement reads a character string received from
the console tab screen below the program editor window, terminated by a carriage-return.
On Error GoTo Statement On Error Goto allows you to define a run-time error handler
to prevent run-time errors from halting program execution.
Pause() Statement Causes the program execution to pause for a specified
amount of time. The motion of the motor is not affected.
Print Statement Displays formatted output through the console while the
program is running.
Restart Statement Causes program execution to begin again from the begin-
ning of the program.
Select Case Statement Select Case executes one of several statement blocks
depending upon the value of an expression. Static Statement Static Stop Statement Stops execution of the user program. Sub...End Sub Statement The Sub statement declares a sub procedure and defines
the sub procedures format. Swap Statement Exchanges the value of two variables. While...Wend Statement Executes a series of lines for as long as the condition after
the WHILE is True.
BASICOperators
MOD Operator This is the modulus or "remainder" operator. It divides one
number by another and returns the remainder.
BASICFunctions
ABS() Function ABS(x) converts the associated value (x) to an absolute
value. If the value is negative, it is converted to a positive
value. If the value is positive, it is not changed.
Kollmorgen™ | March 30, 2012 56
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter Type Description
ASC() Function ASC(string expression)returns a decimal numeric value
that is the ASCII code for the first character of the string
expression(x$). ATAN() Function ATAN() (arc tangent) returns the arctangent of its argument
in radians. CHR$() Function Returns a one character string whose ASCII value is the
argument. CINT() Function Converts a numeric expression to the closest integer
number. COS() Function COS(x) returns the cosine of x, where x is in radians. EXP() Function Returns e (the base of natural logarithms) raised to a
power. FIX() Function Fix() returns the truncated integer part of x. HEX$() Function HEX$() converts an integer number to its equivalent hex-
adecimal ASCII string. INKEY$() Function Returns a 1 character string corresponding to the character
in the serial port receive buffer. If there is no character wait-
ing the INKEY$ will be the Null string (""). If several char-
acters are pending only the first one is returned. INSTR() Function Returns the starting location of a substring within a string. INT() Function INT() (convert to largest integer) truncates an expression to
a whole number. LCASE$() Function Converts a string expression to lowercase characters. LEFT$() Function Returns a string of the n leftmost characters in a string
expression. LEN() Function Returns the number of characters in a string expression. LOG() Function Returns the natural logarithm of a numeric expression. LOG10() Function Returns the base 10 logarithm of a numeric expression. LTRIM$() Function Returns a copy of the original string with leading blanks
removed. MID$ Function Returns a substring of the original string that begins at the
specified offset location and is of the specified (optional)
length. OCT$() Function OCT$() converts an integer number to its equivalent octal
ASCII string. RIGHT$() Function Returns a string of the n rightmost characters in a string
expression. RTRIM$() Function Returns a copy of the original string with trailing blanks
removed. SGN() Function Returns the sign of a numeric expression. SIN() Function SIN(x) returns the sine of x, where x is in radians. SPACE$() Function Returns a string of n spaces. SQR() Function Returns the square root of a numeric expression. STR$() Function Returns a string representing the value of a numeric expres-
sion. STRING$() Function Returns a string containing the specified number of occur-
rences of the specified character.
57 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter Type Description
TAN() Function TAN(x) returns the tangent of x, where x is in radians. TRIM$() Function Returns a copy of the original string with leading and trailing
blanks removed. UCASE$() Function Converts a string expression to uppercase characters. VAL() Function Returns the numerical value of a string.
Camming (CAM)
CAM.ACTIVATE Statement Activates the specified cam table. CAM.ADDPOINT Statement CAM.ADDPOINT(Master Position, Slave Position) Adds
the specified "point" to the cam table being created. CAM.CORRECTDIR R/W Specifies the direction of the correction move when a new
cam table is activated (set CAM.ACTIVATE = n) or when
speed synchronization is achieved. CAM.CREATE Statement CAM.CREATE (x, y) Initiates the creation of a cam table. CAM.MASTER R/W Specifies the source of the input to the cam table for cam
profiling. CAM.MASTERPOS R/O Gives the value of the master position presently being used
as the input to the cam table. CAM.SLAVEOFFSET R/O CAM.SLAVEOFFSET indicates the offset (or difference)
between MOVE.POSCOMMAND and the position com-
mand that is calculated from the active cam table based
upon the present value of EXTENCODER.POSITION
and/or CAMVM.POSITION. CAMVM.DIR R/W Specifies the direction the virtual encoder goes when
CAMVM.GOVEL is executed. CAMVM.FREQ R/W CAMVM.FREQ sets the maximum frequency allowed dur-
ing a relative (CAMVM.GOREL) move, and sets the com-
manded speed during a velocity move (CAMVM.GOVEL) CAMVM.GOREL Statement Makes the virtual master move the distance specified by
CAMVM.RELATIVEDIST. CAMVM.GOUPDATE Statement Updates a move in progress with new move parameters. CAMVM.GOVEL Statement CAMVM.GOVEL (Go at Velocity) causes the virtual
master to move continuously at the frequency specified by
CAMVM.FREQ in the direction (positive or negative) spec-
ified by CAMVM.DIR. The frequency or direction is mod-
ified during the move using CAMVM.GOUPDATE. CAMVM.MOVING R/O Indicates if the virtual encoder is moving. CAMVM.POSITION R/W Contains the current value of the virtual encoder counter. CAMVM.RELATIVEDIST R/W Specifies the number or counts that the virtual encoder (vir-
tual master) will put out during an incremental move
(CAMVM.GOREL). CAMVM.STOP Statement CAMVM.STOP stops the virtual encoder
Drive (DRV)
DRV.SWENABLE R/W Controls whether power can flow to the motor.
Electronic Gearing (EGEAR)
EGEAR.ACCLIMIT R/W EGEAR.ACCLIMIT sets the maximum acceleration.
Kollmorgen™ | March 30, 2012 58
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter Type Description
EGEAR.DECLIMIT R/W EGEAR.DECLIMIT sets the maximum deceleration that
will be commanded on the follower when EGEAR.ON is
turned OFF or the electronic gearing ratio (EGEAR.RATIO
or EGEAR.PULSESOUT / EGEAR.PUSLESIN ) is
decreased. EGEAR.ERROR R/W Indicates the amount of position deviation that has accumu-
lated on the slave axis (in an electronic gearing application)
as a result of the slave axis limiting its acceleration or decel-
eration while achieving velocity synchronization. EGEAR.LOCK R/O EGEAR.LOCK indicates when the slave axis (follower
axis) in an electronic gearing application has achieved
velocity synchronization with the electronic gearing
master. EGEAR.ON Command Starts the electronic gearing; active in opmode 2 (position)
only. EGEAR.PULSESIN R/W Specifies the number of encoder counts used when spec-
ifying an exact electronic gearing ratio. EGEAR.PULSEOUT R/W Specifies the number of position counts used in an exact
electronic gearing ratio. EGEAR.RATIO R/W Sets the electronic gearing ratio (rev to rev) between the
encoder shaft (master) and the motor shaft (slave). EGEAR.TYPE R/W Sets the allowed direction of motion for electronic gearing.
External Encoder (EXTEN­CODER)
EXTENCODER.FREQ R/O Gets the external encoder (EEO) velocity. EXTENCODER.POSITION R/O Gets the external encoder (EEO) position. EXTENCODER.POSMODULO R/W Sets/gets the external encoder (EEO) modulo position.
Interrupt (INTR)
Interrupt...End Interrupt Statement The interrupt feature permits execution of a user-defined
subroutine upon receipt of a hardware interrupt signal or a
pre-defined interrupt event. INTR.DIN1HI Enables interrupt for when DIN1.STATE to DIN7.STATE
goes from 0 to 1, respectively. INTR.DIN1LO Enables interrupt for when DIN1.STATE to DIN7.STATE
goes from 1 to 0, respectively. INTR.DISABLE Enables interrupt for when the drive gets disabled. INTR.DRV.FAULTS Enables interrupt for when the drive faults. INTR.DRV.HWENABLE Enables interrupt for when DRV.HWENABLE goes from 0
to 1. INTR.DRV.WARNINGS Enables interrupt for when the drive produces a warning. INTR.HWLS.NEGSTATE Enables interrupt for when HWLS.NEGSTATE goes from 0
to 1. INTR.HWLS.POSSTATE Enables interrupt for when HWLS.POSSTATE goes from 0
to 1. INTR.MODBUS Enables interrupt for when a Modbus User Parameter
changes. INTR.PL.ERR Enables interrupt for when PL.ERR= PL.ERRFTHRESH.
59 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter Type Description
INTR.PLS.P1 to INTR.PLS.P8 Enables interrupt for when PLS1 to PLS8 is enabled and
goes high, respectively. INTR.SWLS.LIMIT0 Enables interrupt for when PL.FB > SWLS.LIMIT0 (if
SWLS.LIMIT0 is the upper limit) INTR.SWLS.LIMIT1 Enables interrupt for when PL.FB < SWLS.LIMIT1 (if
SWLS.LIMIT1 is the lower limit) INTR.TIMER Executes interrupt after a number of milliseconds specified
by VM.INTRTIMER.
MODBUS Parameters
MODBUS.READFLOAT R/W This function reads a floating-point value from the specified
ModBus slave and returns the value read. MODBUS.WRITEFLOAT R/W This statement writes a floating-point value to the specified
ModBus slave.
Move Parameters (MOVE)
MOVE.ABORT Command MOVE.ABORT stops motor motion and allows continued
program execution. MOVE.ACC R/W Sets the maximum commanded acceleration rate when the
speed is increased. MOVE.DEC R/W Sets the maximum commanded deceleration rate when the
speed is decreased. MOVE.DIR R/W MOVE.DIR specifies the direction the motor turns when a
MOVE.GOVEL statement is executed. MOVE.GOABS Command MOVE.GOABS moves the motor to the position specified
by MOVE.TARGETPOS. MOVE.GOHOME Command MOVE.GOHOME causes the motor to move to the position
specified where PL.FB = 0. MOVE.GOREL Command MOVE.GOREL moves the motor a distance specified by
MOVE.RELATIVEDIST. MOVE.GOUPDATE Command MOVE.GOUPDATE updates a move in progress with new
move parameters. MOVE.GOVEL Command MOVE.GOVEL moves the motor at a constant speed spec-
ified by MOVE.RUNSPEED and direction specified by
MOVE.DIR. MOVE.INPOSITION R/O Indicates whether or not the motor has achieved command
position. MOVE.INPOSLIMIT R/W Specifies the tolerance of Position Error (PL.ERR) within
which the MOVE.INPOSITION flag will be set to 1 (True). MOVE.MOVING R/O Indicates whether or not the commanded motion profile is
complete. MOVE.POSCOMMAND R/W Current Position Command from Trajectory Generator. MOVE.RELATIVEDIST R/W Specifies the distance the motor turns during a relative
move (MOVE.GOREL). MOVE.RUNSPEED R/W Sets the maximum speed allowed during a relative
(MOVE.GOREL) or absolute (MOVE.GOABS) move, and
sets the commanded speed during a velocity move
(MOVE.GOVEL). MOVE.SCURVETIME R/W Sets the amount of S-curve smoothing applied to all veloc-
ity profiles.
Kollmorgen™ | March 30, 2012 60
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter Type Description
MOVE.TARGETPOS R/W MOVE.TARGETPOS specifies the target position for an
absolute (MOVE.GOABS) move.
Virtual Machine (VM)
VM.AUTOSTART R/W VM.AUTOSTART specifies whether or not the program in
the AKD BASIC starts executing automatically when AC
power is applied. VM.ERR R/W Indicates what caused the most recent Runtime Error. VM.INTRTIMER R/W Sets a number of milliseconds before
INTR.TIMERexecutes after it is called. VM.RESTART Command Restart AKDBASIC virtual machine.
WHEN
When Statement The WHEN statement is used for very fast response to cer-
tain input conditions.
When Conditons
PL.FB < value PL.FB> value PL.CMD < value PL.CMD> value DRV.HANDWHEEL < value DRV.HANDWHEEL > value DRV.TIME > value DINx.STATE = 0 or 1 FB3.P < value FB3.P > value MOVE.MOVING = 0 or 1 MOVE.INPOSITION = 0 or 1
When Actions
Continue DOUT1.STATEU = 0 or 1 DOUT2.STATEU = 0 or 1 EGEAR.RATIO = value MOVE.ABORT MOVE.GOABS MOVE.GOREL MOVE.GOVEL MOVE.GOABSREG MOVE.GOHOME MOVE.GORELREG MOVE.GOUPDATE
WHEN.DRVHANDWHEEL R/O Records the value of DRV.HANDWHEEL when the when-
WHEN.DRVTIME R/O Records the value of Time when the when-condition is sat-
61 Kollmorgen™ | March 30, 2012
condition is satisfied.
isfied.
AKD BASIC User Guide | 4 Quick Reference: Parameters, Functions, Operators
Parameter Type Description
WHEN.FB1MECHPOS R/O Records the value of FB1.MECHPOS when the when-con-
dition is satisfied. WHEN.PLCMD R/O Records the value of PL.CMD when the when-condition is
satisfied. WHEN.PLFB R/O Records the value of Position when the when-condition is
satisfied.
Kollmorgen™ | March 30, 2012 62
AKD BASIC User Guide | 5 AKD BASIC Functions

5 AKD BASIC Functions

This section describes the functions available in AKD BASIC.
63 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.1 ABS()

General Information
Type Function
Description
Instructions
Enter the argument (the value) in parentheses immediately following the term ABS.
Example
For x = -10 To 10
Next
ABS(x) converts the associated value (x) to an absolute value. If the value is neg­ative, it is converted to a positive value. If the value is positive, it is not changed.
Print ABS(x)
Kollmorgen™ | March 30, 2012 64
AKD BASIC User Guide | 5 AKD BASIC Functions

5.2 ASC()

General Information
Type Function
Description
Syntax
x = ASC(s$)
Instructions
If the string begins with an uppercase letter, the value of ASC() will be between 65 and 90.
If the string begins with a lowercase letter, the value of ASC() will be between 97 and 122.
Values "0" to "9" return 48 to 57.
ASC(string expression)returns a decimal numeric value that is the ASCII code for the first character of the string expression(x$).
65 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.3 ATAN()

General Information
Type Function Description ATAN() (arc tangent) returns the arctangent of its argument in radians.
Instructions
The result is always between -pi/2 and pi/2.
The value of x may be any numeric type.
To convert from degrees to radians, multiply by 0.01745329
Kollmorgen™ | March 30, 2012 66
AKD BASIC User Guide | 5 AKD BASIC Functions

5.4 CHR$()

General Information
Type Function Description Returns a one character string whose ASCII value is the argument.
Syntax
s$ = CHR$(x)
Instructions
The argument to Chr$() must be a numeric value in the range 0 to 255.
Example
'this example will print an uppercase B
Dim a$ as string
a$ = CHR$(66)
Print a$
67 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.5 CINT()

General Information
Type Function Description Converts a numeric expression to the closest integer number.
Instructions
X = CINT( numeric-expression )
Related Topics
INT() | FIX()
Kollmorgen™ | March 30, 2012 68
AKD BASIC User Guide | 5 AKD BASIC Functions

5.6 COS()

General Information
Type Function Description COS(x) returns the cosine of x, where x is in radians.
Instructions
X must be in radians. To convert from degrees to radians, multiply by 0.017453.
69 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.7 EXP()

General Information
Type Function Description Returns e (the base of natural logarithms) raised to a power.
Instructions
The Exp() function complements the action of the Log() function. For those of you keeping score, the value of e is 2.71828182.
Related Topics
LOG() | LOG10()
Kollmorgen™ | March 30, 2012 70
AKD BASIC User Guide | 5 AKD BASIC Functions

5.8 FIX()

General Information
Type Function Description Fix() returns the truncated integer part of x.
Instructions
Fix() does not round off numbers, it simply eliminates the decimal pint and all digits to the right of the decimal point.
Related Topics
ABS() | CINT() | INT()
71 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.9 HEX$()

General Information
Type Function Description HEX$() converts an integer number to its equivalent hexadecimal ASCII string.
Syntax
result$ = HEX$(x)
Instructions
Hexadecimal numbers are numbers to the base 16 (rather than base 10).
The argument to HEX$() is rounded to an integer before HEX$(x) is evaluated.
Example
Dim x,y as integer Dim result1$, result2$ as string
x = 20 y = $H6A result1$ = HEX$(x) result2$ = HEX$(y)
Print result1$, result2$
'prints 14 6A
Related Topics
OCT$() | STR$()
Kollmorgen™ | March 30, 2012 72
AKD BASIC User Guide | 5 AKD BASIC Functions

5.10 INKEY$()

General Information
Type Function
Returns a 1 character string corresponding to the character in the serial port
Description
Syntax
x$ = INKEY$
Instructions
Assigning a string from INKEY$ removes the character from the serial port's receive buffer.
Example
' remove all characters from the receive buffer and put them into A$. '--------------------------------------
new$ = INKEY$
While new$ <> ""
Wend
receive buffer. If there is no character waiting the INKEY$ will be the Null string (""). If several characters are pending only the first one is returned.
A$ = A$ + new$ new$ = INKEY$
73 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.11 INSTR()

General Information
Type Function Description Returns the starting location of a substring within a string.
Syntax
result = INSTR( [n], x$, y$ )
x$ is the string
y$ is the substring
n optionally sets the start of the search
Instructions
n must be in the range 1 to 255
INSTR() returns 0 if:
n > LEN(x$)
y$ cannot be found in x$
If y$ iis null (empty, ""), INSTR() returns n
Related Topics
LEN()
Kollmorgen™ | March 30, 2012 74
AKD BASIC User Guide | 5 AKD BASIC Functions

5.12 INT()

General Information
Type Function Description INT() (convert to largest integer) truncates an expression to a whole number.
Instructions
INT() behaves the same as FIX() for positive numbers. They behave differently for negative numbers.
Example
Print INT(12.34) 'prints the value 12 Print INT(-12.34) 'prints the value -13
Related Topics
CINT() | FIX()
75 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.13 LCASE$()

General Information
Type Function Description Converts a string expression to lowercase characters.
Syntax
result$ = LCASE$(string-expression)
Instructions
LCASE$() affects only letters in the string expression. Other characters (such as numbers) are not changed.
Example
Dim x$ as string
x$ = "U.S.A"
Print LCASE$(x$) 'prints: u.s.a
Related Topics
UCASE$()
Kollmorgen™ | March 30, 2012 76
AKD BASIC User Guide | 5 AKD BASIC Functions

5.14 LEFT$()

General Information
Type Function Description Returns a string of the n leftmost characters in a string expression.
Syntax
result$ = LEFT$(x$, n)
Instructions
If n is greater than LEN( x$ ) then the entire string will be returned.
Example
a$ = "Mississippi"
Print LEFT$(a$, 5) 'prints: Missi
Related Topics
LEN() | MID$ | RIGHT$()
77 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.15 LEN()

General Information
Type Function Description Returns the number of characters in a string expression.
Syntax
result = Len( x$ )
Instructions
Non-printing characters and blanks are included.
Example
x$ = "New York, New York"
Print LEN(x$) 'prints 18
Kollmorgen™ | March 30, 2012 78
AKD BASIC User Guide | 5 AKD BASIC Functions

5.16 LOG()

General Information
Type Function Description Returns the natural logarithm of a numeric expression.
Instructions
X must be greater than 0.
Example
Print LOG (45.0 / 7.0) 'prints 1.860752
Print LOG(1) 'prints 0
Related Topics
EXP() | LOG10()
79 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.17 LOG10()

General Information
Type Function Description Returns the base 10 logarithm of a numeric expression.
Instructions
X must be greater than 0.
Example
Print LOG10(100) 'prints 2 Print LOG10(1) 'prints 0
Related Topics
EXP() | LOG()
Kollmorgen™ | March 30, 2012 80
AKD BASIC User Guide | 5 AKD BASIC Functions

5.18 LTRIM$()

General Information
Type Function Description Returns a copy of the original string with leading blanks removed.
Syntax
result$ = LTRIM$(x$)
Instructions
x$ can be any string-expression
Example
x$ = " Hello "
Print "(" + LTRIM$(x$) + ")"
'prints: (Hello )
Related Topics
RTRIM$() | TRIM$()
81 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.19 MID$

General Information
Type Function
Description
Syntax
result = MID$(x$, start, [length])
Instructions
Start and Length must both be numeric expressions.
If Length is omitted then MID$() returns a substring that starts at start and goes to the end of x$.
Example
Returns a substring of the original string that begins at the specified offset loca­tion and is of the specified (optional) length.
x$ = "abcdefghi"
Print MID$ (x$, 1, 5) 'prints: abcde Print MID$ (x$, 6) 'prints: fghi
Related Topics
INSTR() | LEFT$() | LEN() | RIGHT$()
Kollmorgen™ | March 30, 2012 82
AKD BASIC User Guide | 5 AKD BASIC Functions

5.20 OCT$()

General Information
Type Function Description OCT$() converts an integer number to its equivalent octal ASCII string.
Syntax
result$ = OCT$(x)
Instructions
Octal numbers are numbers to the base 8 (rather than base 10).
The argument to HEX$() is rounded to an integer before OCT$(x) is evaluated.
Example
Dim x, y as integer Dim result1$, result2$ as string
x = 20 y = &H6A result1$ = OCT$(x) result2$ = OCT$(y)
print result1$, result2$ 'prints: 24 152
Related Topics
HEX$() | STR$()
83 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.21 RIGHT$()

General Information
Type Function Description Returns a string of the n rightmost characters in a string expression.
Syntax
result$ = RIGHT$(x$, n)
Instructions
If n is greater than Len( x$ ) then the entire string will be returned.
Example
a$ = "Mississippi"
Print RIGHT$(a$, 5) 'prints: sippi
Related Topics
LEN() | MID$ | LEFT$()
Kollmorgen™ | March 30, 2012 84
AKD BASIC User Guide | 5 AKD BASIC Functions

5.22 RTRIM$()

General Information
Type Function Description Returns a copy of the original string with trailing blanks removed.
Syntax
result$ = RTRIM$( x$ )
Instructions
x$ can be any string-expression.
Example
x$ = " Hello "
Print "(" + RTRIM$(x$) + ")"
'prints: ( Hello)
Related Topics
LTRIM$() | TRIM$()
85 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.23 SGN()

General Information
Type Function Description Returns the sign of a numeric expression.
Instructions
X is any numeric expression
Example
Print SGN(-33) 'prints -1 Print SGN(0) 'prints 0 Print SGN(45.77) 'prints 1
Kollmorgen™ | March 30, 2012 86
AKD BASIC User Guide | 5 AKD BASIC Functions

5.24 SIN()

General Information
Type Function Description SIN(x) returns the sine of x, where x is in radians.
Instructions
X must be in radians. To convert from degrees to radians, multiply by 0.017453.
87 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.25 SPACE$()

General Information
Type Function Description Returns a string of n spaces.
Syntax
result$ = SPACE$(n)
n is 0 to 255
Instructions
N is rounded to an integer before SPACE$() is evaluated.
Example
x$ = "(" + SPACE$(1) + "hello" + SPACE$(4) +
")"
Print x$ 'prints: ( hello )
Related Topics
STRING$()
Kollmorgen™ | March 30, 2012 88
AKD BASIC User Guide | 5 AKD BASIC Functions

5.26 SQR()

General Information
Type Function Description Returns the square root of a numeric expression.
Instructions
X must be greater than or equal to zero.
Example
x = 10
print SQR(x) 'prints 3.162278
89 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.27 STR$()

General Information
Type Function Description Returns a string representing the value of a numeric expression.
Syntax
result$ = STR$(x)
Instructions
Enter a numeric expression as x and STR$ will return its result as a string.
Example
x = 45.2 / 7
Print STR$(x) 'prints: 6.457
Related Topics
HEX$() | OCT$()
Kollmorgen™ | March 30, 2012 90
AKD BASIC User Guide | 5 AKD BASIC Functions

5.28 STRING$()

General Information
Type Function
Description
Syntax
1) x$ = STRING$(n, a$)
or
2) x$ = STRING$(n, m)
Instructions
n is the number of occurrences of the desired character (the length of the returned string).
In 1), the returned string will consist of the first character in a$
In 2), the returned string will consist of the ASCII value of m.
Returns a string containing the specified number of occurrences of the specified character.
Example
Print String$(5, 45) 'prints: ----- Print String$(5, "A") 'prints: AAAAA
Related Topics
SPACE$()
91 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.29 TAN()

General Information
Type Function Description TAN(x) returns the tangent of x, where x is in radians.
Instructions
X must be in radians. To convert from degrees to radians, multiply by 0.017453.
Kollmorgen™ | March 30, 2012 92
AKD BASIC User Guide | 5 AKD BASIC Functions

5.30 TRIM$()

General Information
Type Function Description Returns a copy of the original string with leading and trailing blanks removed.
Syntax
result$ = TRIM$(x$)
Instructions
x$ can be any string-expression
Example
x$ = " Hello "
Print "(" + TRIM$(x$) + ")"
'prints: (Hello)
Related Topics
LTRIM$() | RTRIM$()
93 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 5 AKD BASIC Functions

5.31 UCASE$()

General Information
Type Function Description Converts a string expression to uppercase characters.
Syntax
result$ = UCASE$(string-expression)
Instructions
UCASE$() affects only letters in the string expression. Other characters (such as numbers) are not changed.
Example
Dim x$ as string
x$ = "u.s.a"
Print UCASE$( x$) 'prints: U.S.A
Related Topics
LCASE$()
Kollmorgen™ | March 30, 2012 94
AKD BASIC User Guide | 5 AKD BASIC Functions

5.32 VAL()

General Information
Type Function Description Returns the numerical value of a string.
Syntax
result = VAL(a$)
Instructions
If the first character of a$ is not numeric then Val() will return 0.
Related Topics
STR$()
95 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 6 AKD BASIC Parameters, Operators, Statements

6 AKD BASIC Parameters, Operators, Statements

This section is an alphabetical reference to AKD BASIC parameters.
General information for each parameter is listed at the top of each page. The parameter is then described, and in some cases examples are given along with references to related parameters.
Kollmorgen™ | March 30, 2012 96
AKD BASIC User Guide | 6 AKD BASIC Parameters, Operators, Statements

6.1 Additional Statements

This section describes statements not directly related to a parameter set.
97 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 6 AKD BASIC Parameters, Operators, Statements

6.1.1 $Include

General Information
Type Statement
Description
Units N/A Range N/A Default
Value Data Type N/A Start Ver-
sion
Description
The $Include statement allows you to textually include multiple separate files in a single source file. A file cannot include itself, either directly or indirectly. Include file nesting is allowed to a depth of 16. Relative paths in a nested include file are relative to the directory location of the include file, not the current working directory of the compiler.
The $Include statement allows you to textually include multiple separate files in a single source file.
N/A
TBD
Example
This example shows two file, myinc.inc and myfile.bas. The file myinc.inc has a sub-procedure for doing and incremental move that is used by the main program in myfile.bas.
MyInc.Inc:
Sub DoIndexMove( Distance as integer)
MOVE.RELATIVEDIST = Distance MOVE.GOREL
while MOVE.MOVING : wend
End Sub
MyFile.Bas"
$Include "myinc.inc" Main
while 1
call DoIndexMove(4096) Pause(0.5)
wend
End Main
Related Topics
Statement Table(1)
Kollmorgen™ | March 30, 2012 98
AKD BASIC User Guide | 6 AKD BASIC Parameters, Operators, Statements

6.1.2 Alias

General Information
Type Statement
Description
Units N/A Range N/A Default
Value Data Type N/A Start Ver-
sion
Description
Allows you to define your own names for system resources, such as Input or Output pins. ALIAS is much more powerful than CONST. Constant expressions are computable at compile­time, whereas an alias has a value that may only be known at the time that it is being used. For this reason aliases should be used with care – over-use of aliases can make it very difficult to read a program.
Allows you to define your own names for sys­tem resources, such as Input or Output pins.
N/A
tbd
Example
Alias CONVEYOR_IS_RUNNING = (DIN1.STATE = 0) if CONVEYOR_IS_RUNNING then
print "The conveyor is running"
end if
Related Topics
Const
99 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 6 AKD BASIC Parameters, Operators, Statements

6.1.3 Call

General Information
Type Statement
Description
Units N/A Range N/A Default
Value Data Type N/A Start Ver-
sion
Description
Transfer program control to a subroutine. When the subroutine is finished then control is trans­ferred to the line following the CALL. A subroutine is essentially a function with no return value. Arguments to subroutines are passed "by value". This means that the subroutine receives a copy of these arguments. Any assignments to these arguments made by the subroutine will have no effect on these variables in the calling function or subroutine.
Transfer program control to a subroutine. When the subroutine is finished then control is transferred to the line following the CALL.
N/A
tbd
Example
Call PrintSum(3,4)
'-------------- Subroutines and Functions -----
-------
Sub PrintSum(i,j,as integer)
print i+j
End Sub
Related Topics
Sub...End Sub
Kollmorgen™ | March 30, 2012 100
Loading...