Personal tools
You are here: Home ServoCenter™ ServoCenter™ 4.1 SC-BASIC Built-in Sequencer
Document Actions

ServoCenter™ 4.1 SC-BASIC Built-in Sequencer

The ServoCenter 4.1 controller provides a built-in Sequencer / BASIC Interpreter called SC-BASIC that allows the ServoCenter board to be programmed to perform various tasks via the use of a simple tokenized BASIC-like scripting language. This feature can be used to implement customer specific logic, I/O, and servo control tasks without the need for a PC or other external command device.

Sequencer Overview

ServoCenter 4,1 Board

servocenter 4,1 board

servocenter 4,1 board The ServoCenter 4.1 controller provides a built-in Sequencer / BASIC Interpreter called SC-BASIC that allows the ServoCenter board to be programmed to perform various tasks via the use of a simple tokenized BASIC-like scripting language. This feature can be used to implement customer specific logic, I/O, and servo control tasks without the need for a PC or other external command device.

The use of a fully functional scripting language allows the sequencer to perform complex logical and control tasks that can run independently on the SC4.1 board itself. The sequencer programs are stored on the SC4.1 board in a non-volatile EEPROM memory that retains the program even when the unit it reset or powered off. The loaded sequencer program can be started remotely via the “Start Sequencer” command and supports the passing of a parameter byte when a sequence is started. The sequencer also implements a “Sequencer Startup” feature that allows a loaded script to be executed when the SC4.1 board is reset or powered up thus allowing the SC4.1 board to be used as a stand-alone controller. 

Sequencer Features

The SC-BASIC language was designed for the ServoCenter 4.1 Servo Controller as a simple, easy to learn language that is specifically suited to the architecture and problem domain of the controller board. SC-BASIC supports a syntax that will be familiar to users of other flavors of BASIC (such as QBASIC and Visual Basic) as well as some instructions and built-in functions that are specifically suited to the SC4.1 controller board.

 SC-BASIC supports the following features:

  • Compact tokenized program format.

  • 4096 bytes of non-volatile program space.

  • Familiar structured BASIC-like language syntax.

  • Dynamic variable allocation.

  • Support for up to 64 simultaneously allocated global and local integer variables.

  • Support for up to 16 user-defined subroutines / functions.

  • Scripts can be passed a parameter byte when started via the “Start Sequencer” command.

  • Scripts can be started upon board reset / power up via the “Sequencer Startup” feature.

  • Sequencer status and sequencer error reporting.

  • Built-in servo control and digital I/O functions.

  • Additional built-in functions for commonly needed programming tasks.

  • Sequencer communication support allows the sequencer to print/receive messages.

  • Sequencer Start / Stop / Reset control functions.

Summary of Manual Contents

The Language Reference and Programming Guide is a full guide to using the Sequencer application, including both the Control Panel sequence editor and the programming methods.

General Sections include:

  • Language Reference
    • comments
    • variables
    • arithmetic operations and expressions
    • relational and logical operations
    • language statements
    • built-in functions
  • ServoCenter Sequencer Control Commands
    • protocol command summary
    • protocol command details
  • Using the ServoCenter Control Panel Sequence Editor
    • sequencer programming tab
    • basic use tutorial
    • more advanced examples
  • SC-BASIC Programming Examples
    • hello world
    • hello world sub
    • servo exercise
    • servo exercise with sub
    • digital I/O exercise
    • show all ADC values
    • move all servos to a random position
    • demo of global variable retaining value
    • demo of CmdArg
  • Appendix
    • hexadecimal/decimal/binary nibble conversion chart
    • hexadecimal/decimal ASCII chart
    • token specification
    • error codes

SC-BASIC Programming Examples

Hello World

' Simple Hello World Program

Print "Hello World"

Hello World with Subroutine

' Hello World Program using a Sub Procedure.

Sub Hello()   
    Print "Hello World"
End Sub

Call Hello()

Servo Exercise

' This program exercises all 16 servo channels by
'  moving them from min to max to min to center
'  with a 1 second delay between each movement.

' move all servos to Min positions
for SvNum = 0 to 15   
    QuickMoveServoScaled(SvNum,0)
next SvNum

' wait for a second
Call DelaySec(1)

' move all servos to Max positions
for SvNum = 0 to 15   
    QuickMoveServoScaled(SvNum,16383)
next SvNum

' wait for a second
Call DelaySec(1)

' move all servos to Min positions
for SvNum = 0 to 15   
    QuickMoveServoScaled(SvNum,0)
next SvNum

' wait for a second
Call DelaySec(1)

' move all servos to center positions
for SvNum = 0 to 15   
    QuickMoveServoScaled(SvNum,8191)
next SvNum

Servo Exercise with Subroutine

' This program exercises all 16 servo channels by
'  moving them from min to max to min to center
'  with a 1 second delay between each movement.

Sub MoveAllServos(Pos)
    'move all servos to position Pos
    for SvNum = 0 to 15   
      QuickMoveServoScaled(SvNum,Pos)
    next SvNum
End Sub

'move all servos to Min positions
Call MoveAllServos(0)
'wait for a second
Call DelaySec(1)

'move all servos to Max positions
Call MoveAllServos(16383)
'wait for a second
Call DelaySec(1)

'move all servos to Min positions
Call MoveAllServos(0)
'wait for a second
Call DelaySec(1)

'move all servos to Center positions
Call MoveAllServos(8191)

Digital I/O Exercise

' This program exercises all 16 Digital I/O channels by
'  setting them all as outputs and cycling through each one
'  with a 10th of a second high pulse.

' Set all Digital I/O pins as output
For DioNum = 0 To 15
    SetDIODirectionOut(DioNum)
    Call SetDIOLow(DioNum)
Next DioNum

' Cycle through all 16 digital I/O pins setting each high for 1/10th
'  of a second then low.
For DioNum = 0 To 15
    Call SetDIOHigh(DioNum)
    Call DelayMilliSec(100)
    Call SetDIOLow(DioNum)
Next DioNum

print "done"

Show all ADC Values

' This program prints the ADC values for all 8 ADC channels.

For AdNum = 0 to 7
    Print "ADC Channel ";AdNum;" reads: ";ReadAD(AdNum)
next AdNum

Move all Servos to a Random Position

' This program moves all servos to a random position.

For SvNum = 0 To 15       
    Call QuickMoveServoScaled(SvNum,RandRange(0,16383))
Next SvNum

Demo of global variable retaining value

'  The following program demonstrates the ability of SC-BASIC to retain
'    global variable values between executions.  Run the program multiple times
'    to see the behavior.   To prevent this behavior, initialize variables before
'    use, or issue the "Reset Sequencer" command before issuing the
'    "Start Sequencer" command.

 print "The variable count is:",count

count=count+1

Demo of CmdArg

' This program illustrates the use of the CmdArg function to control
'    the behavior of a program when it is started.

choice = CmdArg()

If choice=0 Then
    Print "CmdArg was 0"
Else If choice=1 Then
    Print "CmdArg was 1"
Else If choice = 2 Then
    Print "CmdArg was 2"
Else If choice = 3 Then
    Print "CmdArg was 0"
Else
    Print "CmdArg was greater than 3"
End if

Download Sequencer

ServoCenter 4.1 Sequencer / SC-BASIC Application
The ServoCenter 4.1 Sequencer is included with the ServoCenter 4.1 Control Panel Utility. The sequencer is designed as a simple, easy to learn language specifically suited to the architecture and problem domain of ServoCenter 4.1.