990 likes | 1.01k Views
BRAIN Training. Presented by:. Matt Lapolla matt@mattandsuz.com. Gini Sue Crofford Virginia.Crofford@ student.oc.edu. Bill Ryan – Bill.Ryan@oc.edu OC Contact, Parts, Facilities John Robertson – madrob100@yahoo.com BEST ambasator Matt Lapolla – matt@mattandsuz.com
E N D
BRAIN Training Presented by: Matt Lapolla matt@mattandsuz.com Gini Sue Crofford Virginia.Crofford@ student.oc.edu
Bill Ryan – Bill.Ryan@oc.edu • OC Contact, Parts, Facilities • John Robertson – madrob100@yahoo.com • BEST ambasator • Matt Lapolla – matt@mattandsuz.com • Rules, BRAIN, Tech Help • Gini Sue Crofford -Virginia.Crofford@student.oc.edu • BRAIN, Tech Help, Parts • Kenny Ham – kenny.ham@student.oc.edu • Parts, Tech Help Introductions
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? About You
Dual 16-bit microcontroller architecture (TI MSP430) • Easy program download via USB interface • Electronics protected by removable cover • Replaceable connectors BEST Robotics Advanced Instruction Node (BRAIN)
The BRAIN controls the motors and servos based on the program
The parts of the BRAIN Switch 1 Switch 8 Ground Battery
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 How 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 How to wire up the switches
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 Ways to use the BRAIN
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 The Default Program
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 What is coming up next
Applause And now for the talented.. Gini Sue Crofford
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. Demonstration 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!! Demonstration of the RC receiver and the BRAIN
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 Set up of RealTerm
Let’s Talk Code Analyzing the default C program
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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”.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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!
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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 <bestapi.h> InitBrain is part of that library.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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 <bestapi.h> InitBrain is part of that library.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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 }.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan=0;chan!=4;chan++) { inval=getRcValue(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); } } }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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 }.
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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: chan=0; while(chan != 4) { …. …. chan++; }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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: chan=0; while(chan != 4) { …. …. chan++; }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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: chan=0; while(chan != 4) { …. …. chan++; }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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: chan=0; while(chan != 4) { …. …. chan++; }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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: chan=0; while(chan != 4) { …. …. chan++; }
/* This is a simple demonstration of the BRAIN unit. Each input channel is mapped to a servo and and speed control output */ #include <msp430x14x.h> #include <bestapi.h> int main( void ) { short chan; short inval; InitBrain(); /* initialize the system */ // do this forever while(1) { // iterate over all the channels for(chan = 0;chan != 4;chan++) { inval=getRcValue(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: A=5 A is assigned the value 5 A*=4 A is assigned the value A*4 A/=7 A is assigned the value A/7 A%=9 A is assigned the value the remainder of A/9 A+=87 A is assigned the value A+87 A-=8 A is assigned the value A-8 chan=0; while(chan != 4) { …. …. chan++; }