HOME News Events D.O.R.C. Links Contact Us
Products Robotics Projects Rook's Pawn Downloads Videos

 | P1 | P2 | RN-1 Hardware Help |

    It has been asked by several people that they could use some help getting started using RoboBASIC®. I believe that being able to program your Robonova-1 is where this little guy shines the most. So, here is a little example of code that helps explain how each line is executed (ran). This code segment can be found on your Hitec® CD in the "Template Program for RoboBASIC®" folder.  This is just the beginning... RBC-101 we'll say, for those of you who don't have much experience in the way of programming. There is a "Command Instruction Manual" in .pdf included on your CD. This can help elaborate on some of the specifics.

    I'm not going to get too involved in the beginning sections as of yet. The main thing I'm sure you'll all want to start off doing involves making your Robonova®  move the way you want it to. This all occurs after the "MAIN" procedure.

    The code in RoboBASIC® runs sequentially for the most part. Meaning, it starts at the top, and works it's way down as codes are executed. The only time it deviates from this pattern is when you command it to do so... like with a "GOSUB" or "RETURN" command. (I will avoid using the "GOTO" line in any of these examples. It's not good practice and can cause a big headache if  you ever edit or change your code. Plus, it's one of those things that's just about obsolete). Alright, lets begin...

RoboBASIC® HELP 1 - PROGRAMMING STRUCTURES AND TERMS

' action_24
'== right attack ==============================
     'Declaring Variables - By declaring a variable, you're telling the program to set aside a location in memory that can be written to and retrieved later. Here you will first dimension (declare) it; then name it; and finally explain what type of information you plan to store. The two types of values are a BYTE (1 byte in size; numbers 0-255) and an INTEGER (two bytes in size; numbers 0-65535). I'll be going into detail about these at another time.


DIM A AS BYTE    'Declare the variable "A16" (it's newly created name) and associate it as a "BYTE"
DIM A16 AS BYTE    'Names must start with a letter.
 

    'Declaring a Constant - A constant is in some ways like a variable. However, once a Constant has been assigned a value, it can never be changed. Unlike a variable, the Constant doesn't need to have it's type defined. It's done automatically.
'EXAMPLE: CONST Center = 100    'In this example, whenever "Center" is used in your code, it would be the same as typing "100".

    'Point to point (PTP)- With this turned on, the motion of all servos start and stop at the same time when called to move from one point to another.
PTP SETON     'Turns on Point to Point function in servo groups
PTP ALLON   
 'Turns on Point to point function for all servos   


'== motor direction setting =======================
DIR G6A,1,0,0,1,0,0     'The "DIR" command sets the motor direction for the servo group "G6A" (right leg or #'s 0-5)
DIR G6B,1,1,1,1,1,1     'While looking at the servo horn/disk, 0 indicates clockwise, and 1 indicates counter-clockwise
DIR G6C,0,0,0,0,0,0
DIR G6D,0,1,1,0,1,0

'== motor start position read ======================
GETMOTORSET G6A,1,1,1,1,1,0    '"1" = find servo position right now, and keep its set position
GETMOTORSET G6B,1,1,1,0,0,0    '"0" = move servo to it's default centered location (100)
GETMOTORSET G6C,1,1,1,0,0,0    'the servos indicated by the "0"'s are not used, so don't need to be set
GETMOTORSET G6D,1,1,1,1,1,0

SPEED 5    ' sets the travel time it takes for the servo to travel from one value to another. Speeds can be set with values between 1 and 15. 15 being the fastest.


'== motor power on =============================
MOTOR G24    'power on all 24 servos 

GOSUB
standard_pose    'find the "standard_pose" function and execute its code.

'"GOSUB" will be a good friend when writing your sequences. It's what causes the downward travel of your code to shift away, into a new segment of the program.

'================================================
MAIN:     'this is the name of the root or "Main Procedure". The buck starts and stops here. All code before this point is all for adjusting initial settings, and start-up procedures.

A = REMOCON(1)     'when you press a button on the remote, it stores it's value in "A"
IF A <> 20 THEN GOTO main    'if that value is any number greater, or less than "20" then, go back to the beginning of "MAIN:" and wait until it is. Once A is "20", then continue on to the next line of code. (a loop)

GOSUB right_attack     'find "right_attack:" and execute the code
GOSUB standard_pose   ' after returning from "right_attack:", find "standard_pose:" and execute the code
GOTO MAIN    'after returning from "standard_pose:", find "MAIN:", and execute the code... essentially starting over... waiting for the value "20" to come from the remote.

'================================================
standard_pose:    'this is the name of the "sub". When you type "GOSUB standard_pose", it travels here
MOVE G6A,100, 76, 145, 93, 100, 100    'Reposition all Right Leg servos to equal these values
MOVE G6D,100, 76, 145, 93, 100, 100    'Reposition all Left Leg servos to equal these values
MOVE G6B,100, 30, 80, 100, 100, 100    'Reposition all Right Arm servos to equal these values
MOVE G6C,100, 30, 80, 100, 100, 100    'Reposition all Left Arm  servos to equal these values
WAIT    'do not continue until the previous code has been executed. All code between "standard_pose:" and a "WAIT" happens almost exactly at the same time
RETURN   
'go back to where this "sub" was  first called, and execute the next line under it (GOTO MAIN: in this case)
'================================================
right_attack:
SPEED 7
GOSUB
right_attack1    'find "right_attack1:", and execute the code. (when "right_attack1:" has finished being executed, it will be returned to the line below this one ("SPEED 12") and continue on down until it hits another "GOSUB" or "RETURN".
SPEED 12    'sets the servo speed to 12
HIGHSPEED SETON    'Turns on the "HIGHSPEED" function (servos are about 3x faster than in normal speed)
MOVE G6D
, 98, 157, 20, 134, 110, 100
MOVE G6A, 57, 115, 77, 125, 134, 100
MOVE G6B,112, 92, 99, 100, 100, 100
MOVE G6C,107, 135, 108, 100, 100, 100
WAIT     'waits for all code before this command to finish executing
DELAY
1000    'pauses the execution of any code after this command for 1000ms (1 second)
HIGHSPEED SETOFF     'Turns the "HIGHSPEED" function off, and returns servos to normal speed
SPEED
15
GOSUB sit_pose    'find "sit_pose:", and execute the code.
RETURN    'go back to where this "sub" was  first called, and execute the next line under it (GOSUB standard_pose: in this case)
'================================================
right_attack1:
MOVE G6D, 85, 71, 152, 91, 107, 60
MOVE G6A, 108, 76, 145, 93, 100, 60
MOVE G6C, 100, 40, 80, , , ,
MOVE G6B, 100, 40, 80, , , ,
WAIT
RETURN    
'go back to where this "sub" was  first called, and execute the next line under it (SPEED 12 in this case)
'================================================
sit_pose:
SPEED 10
MOVE G6A
,100, 151, 23, 140, 101, 100,
MOVE G6D,100, 151, 23, 140, 101, 100
MOVE G6B,100, 30, 80, 100, 100, 100
MOVE G6C,100, 30, 80, 100, 100, 100
WAIT
RETURN    
'go back to where this "sub" was  first called, and execute the next line under it (RETURN in this case)
'================================================
 

    There, lesson one. I hope this helps explain things a little better (at least how the structure of a program operates). I'll get more detailed and add more advanced procedures as time permits. If you have any questions, or notice any errors, please contact me and let me know.

 | P1 | P2 | RN-1 Hardware Help |