Title: BRAIN Training
1BRAIN Training
Presented by
Matt Lapolla matt_at_mattandsuz.com
Gini Sue Crofford Virginia.Crofford_at_ student.oc.e
du
2Introductions
- Bill Ryan Bill.Ryan_at_oc.edu
- OC Contact, Parts, Facilities
- John Robertson madrob100_at_yahoo.com
- BEST ambasator
- Matt Lapolla matt_at_mattandsuz.com
- Rules, BRAIN, Tech Help
- Gini Sue Crofford -Virginia.Crofford_at_student.oc.ed
u - BRAIN, Tech Help, Parts
- Kenny Ham kenny.ham_at_student.oc.edu
- Parts, Tech Help
3About You
- How many have participated in BEST?
- What year?
- How many have programmed before?
- What languages?
- How many have used the BRAIN before?
- What have you accomplished with it?
4BEST Robotics Advanced Instruction Node (BRAIN)
- Dual 16-bit microcontroller architecture (TI
MSP430) - Easy program download via USB interface
- Electronics protected by removable cover
- Replaceable connectors
5Components Replaced
6How it works
7The Receiver gets a signal from the transmitter
8The BRAIN gets the signal from the receiver and
switches.
9The BRAIN processes these signals based on its
program.
10The BRAIN controls the motors and servos based on
the program
11The parts of the BRAIN
Switch 1
Switch 8
Ground
Battery
12How to wire up the switches
- Switches have 3 terminals
- C for Common (one of the wires will always be on
this terminal) - NO Normally Open (No connection until the switch
is pressed) - NC Normally Closed (Connection is made until
switch is pressed) - Choose what configuration of the switch you want
- One wire will go to the switch input on the BRAIN
- The other to the ground connection
13How to wire up the switches
- NEVER HOOK A SWITCH TO THE BATTERY CONNECTION ON
THE BRAIN AND A SWITCH INPUT - NEVER HOOK A SWITCH TO THE BATTERY CONNECTION ON
THE BRAIN AND A SWITCH INPUT - NEVER HOOK A SWITCH TO THE BATTERY CONNECTION ON
THE BRAIN AND A SWITCH INPUT
14Ways to use the BRAIN
- Use it out of the box with the default program
- Easiest to use
- Program the BRAIN with the wizard
- Little more flexible, little more effort
- Program the BRAIN with your own custom program.
- Extremely flexible!! Lot more effort
15The Default Program
- Channel 1 (Right Stick Left and Right)
- Controls Servo 1 and Motor 1
- Motor 1 uses limit switch 1 and 2
- Channel 2 (Right Stick Up and Down)
- Controls Servo 2 and Motor 2
- Motor 2 uses limit switch 3 and 4
- Channel 3 (Left Stick Up and Down)
- Controls Servo 3 and 5, and Motor 3
- Motor 3 uses limit switch 5 and 6
- Channel 4 (Left Stick Left and Right)
- Controls Servo 4 and 6, and Motor 4
- Motor 4 uses limit switch 7 and 8
16What is coming up next
- Gini Sue will present
- How to install software to program the BRAIN
- How to use the Wizard Software
- Matt will present
- How the receiver works with the BRAIN
- How to reorientate the joy stick so forward is
really forward - Walk through a basic program
17And now for the talented..
Applause
18Demonstration of the RC receiver and the BRAIN
- This demonstration will show how the joysticks on
the transmitter are interpreted by the BRAIN - It will also demonstrate a display of data back
to the PC.
19Demonstration of the RC receiver and the BRAIN
- This demonstration will show how the joysticks on
the transmitter are interpreted by the BRAIN - It will also demonstrate a display of data back
to the PC. - This can be a great debugging tool!!
20Set up of RealTerm
- Realterm was the program used to receive data
from the BRAIN and display it on the screen - Port Tab
- BAUD is 9600
- Port is 7 (at least on my computer)
- OPEN button is pressed in
- Pins Tab
- DTR Press Clear Button
- RTS Press Clear Button
21Lets Talk Code
- Analyzing the default C program
22/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
23/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
The characters / open a comment area where you
can write notes to yourself. And the characters
/ close the area.
24/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
25/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
You will always include these lines. They
reference prewritten commands stored in a
Library.
26/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
27/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
Your program always starts with the main
section. It always starts with int
main(void) A matching will signify the end
the main section The term void tells the
compiler there is no outside information for this
function.
28/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
29/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
Declaring variables chan and inval. chan and
inval will be used to hold numbers. Much like X
and Y are used in algebra. The term short
refers to the size and type of number they will
be able to hold.
30/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
Declaring variables chan and inval. chan and
inval will be used to hold numbers. Much like X
and Y are used in algebra. The term short
refers to the size and type of number they will
be able to hold.
short -32,768 to 32,767 unsigned
short 0 to 65,535 unsigned int
0 to 4,294,967,295 int
-2,147,483,648 to 2,147,483,647 long int
-2,147,483,648 to 2,147,483,647 signed char
-128 to 127 unsigned char 0
to 255 Float NEED TO ADD Double
NEED TO ADD
31/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
Declaring variables chan and inval. chan and
inval will be used to hold numbers. Much like X
and Y are used in algebra. The term short
refers to the size and type of number they will
be able to hold.
short -32,768 to 32,767 unsigned
short 0 to 65,535 signed char
-128 to 127 unsigned char 0
to 255
These are the recommended variable types for the
BRAIN. Using other types may slow the processor
down.
32/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
Declaring variables chan and inval. chan and
inval will be used to hold numbers. Much like X
and Y are used in algebra. The term short
refers to the size and type of number they will
be able to hold.
short -32,768 to 32,767 unsigned
short 0 to 65,535 signed char
-128 to 127 unsigned char 0
to 255
If you go over the allotted range of the variable
your program may not function correctly!
33/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
34/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
InitBrain() sets up the speed controllers,
servos, receiver inputs. Remember the line
above include ltbestapi.hgt InitBrain is part
of that library.
35/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
Remember / opens the comment and / closes it.
InitBrain() sets up the speed controllers,
servos, receiver inputs. Remember the line
above include ltbestapi.hgt InitBrain is part
of that library.
36/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
37/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
// is another way to make a comment. It is used
to add a single line comment after the // There
is no closing marker.
38/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
// is another way to make a comment. It is used
to add a single line comment after the // There
is no closing marker.
39/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
40/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
The while loop The program will continue to loop
as long as the condition between the () is true.
In this case 1 is always true, therefore this
loop will never end.
41/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
The while loop The program will continue to loop
as long as the condition between the () is true.
In this case 1 is always true, therefore this
loop will never end.
The loop is defined by and .
42/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan0chan!4chan
) invalgetRcValue(chan,8,100) //
no gain, reasonable deadband // insert
other processing with the input values
// once you're done manipulating the input,
send it out to // the servo and/or speed
controller - of course, you may // want to
combine multiple channels of input to form your
output // so, you'd need to change the loop
structure to do that setServo(chan,inval)
setMotor(chan,inval)
43/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The for loop The for loop is a short hand for a
common type of while loop.
44/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The for loop The for loop is a short hand for a
common type of while loop.
The for loop is also defined by the and .
45/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The for loop The for loop is a short hand for a
common type of while loop.
The for loop above can be rewritten like
this chan0 while(chan ! 4) . .
chan
46/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The for loop The for loop is a short hand for a
common type of while loop. In this type of loop
we will repeat it a set amount of times. A
variable will be used to keep track of how many
times we have been through the loop.
The for loop above can be rewritten like
this chan0 while(chan ! 4) . .
chan
47/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The for loop has 3 parts to it. The first is the
initialization. The initialization is done one
time just before the loop is started. In our
example the variable chan is set to the value of
0.
The for loop above can be rewritten like
this chan0 while(chan ! 4) . .
chan
48/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The for loop has 3 parts to it. The first is the
initialization. The initialization is done one
time just before the loop is started. In our
example the variable chan is set to the value of
0. The second part is the loop condition. It is
evaluated to determine if the loop needs to
continue. A True condition the loop is still
executed. A False condition the loop is
terminated In our example the loop will be
repeated while chan does not equal 4
The for loop above can be rewritten like
this chan0 while(chan ! 4) . .
chan
49/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The for loop has 3 parts to it. The first is the
initialization. The initialization is done one
time just before the loop is started. In our
example the variable chan is set to the value of
0. The second part is the loop condition. It is
evaluated to determine if the loop needs to
continue. A True condition the loop is still
executed. A False condition the loop is
terminated In our example the loop will be
repeated while chan does not equal 4. The last
part is the increment. This section is executed
at the end of the loop. In our case chan is
incremented by 1.
The for loop above can be rewritten like
this chan0 while(chan ! 4) . .
chan
50/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Assignment Operators A5 A is assigned the value
5 A4 A is assigned the value A4 A/7 A is
assigned the value A/7 A9 A is assigned the
value the remainder of A/9 A87 A is assigned
the value A87 A-8 A is assigned the value A-8
chan0 while(chan ! 4) . . chan
51/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Evaluation Operators ! not equal equal
NOTE Do not use to evaluate a
condition. gt greater than lt less than gt greater
than or equal to lt less than or equal to
chan0 while(chan ! 4) . . chan
52/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Increment and Decrement Operators A Increment
A, Same as A1, or A A 1 A Increment A.
Same as A1, or A A 1 A-- Decrement A.
Same as A-1, or A A - 1 --A Decrement A,
Same as A-1, or A A -1
chan0 while(chan ! 4) . . chan
53/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Increment and Decrement Operators A Increment
A, Same as A1, or A A 1 A Increment A.
Same as A1, or A A 1 A-- Decrement A.
Same as A-1, or A A - 1 --A Decrement A,
Same as A-1, or A A -1 There is one distinct
difference. A is incremented after the
operation. A is incremented before the
operation. Example A 5 B A then B is
5 or B A then B is 6
chan0 while(chan ! 4) . . chan
54/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
55/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
getRcValue is a prewritten function that lives in
one of the libraries that we referenced
earlier. getRcValue will return a number to the
variable inval. The number represents the
position of the joystick. The number will be
between 0 and 1023. 0 represents the joystick
all the way in one direction, and 1023 represents
the joystick all the way in the other direction.
512 represents the joystick in the center.
56/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
getRcValue needs 3 arguments. The first is the
channel. The transmitter we use has 4
channels. The number we pass to getRcVal can be 0
to 3. Channel Action 0 Right stick moved
left and right 1 Right stick moved up and
down 2 Left stick moved up and down 3 Left
stick moved left and right
57/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The second is the deadband. The deadband is
the area in the center of the Joystick that
causes no motion on the robot. 8 is a good
average value. Making the value larger,
increases the dead area. Decreasing it may make
the robot jittery.
58/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The third value that getRcValue requires is the
gain. By increasing the gain (grater than 100)
you can get more speed for the same movement of
the joystick. By decreasing the gain (less than
100) you can have more sensitive control over the
robot.
59/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The third value that getRcValue requires is the
gain. By increasing the gain (grater than 100)
you can get more speed for the same movement of
the joystick. By decreasing the gain (less than
100) you can have more sensitive control over the
robot. Because the transmitters trim setting
can limit the full range of the joystick it is
recommended that the gain be around 125.
60/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
setServo is another prewritten function that is
in our library. It will set the position of the
servo. It requires two arguments channel a
number between 0 and 5 indicating witch servo to
control. value a number between 0 and 1023
indicating the position of the servo. 0 is all
the way to the left (or right) 1023 is all the
way to the right (or left) 512 is in the
center. In our case chan will be the channel
and inval will be the value.
61/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
setMotor is also a prewritten function that is in
our libarary. It will set the position of the
speed of the motors. It requires two
arguments channel a number between 0 and 3
indicating witch motor to control. value a
number between 0 and 1023 indicating the position
of the motor. 0 is reverse (or forward) 1023 is
forward (or reverse) 512 is stop In our case
chan will be the channel and inval will be the
value.
62Now let us trace the program. We are going to
act as the computer and simulate what the BRAIN
is doing.
/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
63First we will ignore all the comments.
/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
64We will assume that all the include statements
are correct.
/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
65Remember that the program always starts with main.
/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
66The first command is to declare the variable chan.
/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Variable Tracking Chan
67The next command is to declare the variable inval.
/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Variable Tracking chan inval
68The next command initializes the BRAIN.
/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Variable Tracking chan inval
69/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
Variable Tracking chan inval
70/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The next command is the while loop. This is an
endless loop and the program will never leave it.
Variable Tracking chan inval
71/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the
input, send it out to // the servo and/or
speed controller - of course, you may //
want to combine multiple channels of input to
form your output // so, you'd need to
change the loop structure to do that
setServo(chan,inval) setMotor(chan,inval)
The next command is the for loop. First it sets
the value of chan to 0.
Variable Tracking chan inval 0
72/ This is a simple demonstration of the BRAIN
unit. Each input channel is mapped to a servo and
and speed control output / include
ltmsp430x14x.hgt include ltbestapi.hgt int main(
void ) short chan short inval
InitBrain() / initialize the system /
// do this forever while(1) // iterate
over all the channels for(chan 0chan !
4chan) invalgetRcValue(chan,8,100)
// no gain, reasonable deadband //
insert other processing with the input values
// once you're done manipulating the