1 / 98

BRAIN Training

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

rodneym
Download Presentation

BRAIN Training

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BRAIN Training Presented by: Matt Lapolla matt@mattandsuz.com Gini Sue Crofford Virginia.Crofford@ student.oc.edu

  2. 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

  3. 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

  4. 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)

  5. Components Replaced

  6. How it works

  7. The Receiver gets a signal from the transmitter

  8. The BRAIN gets the signal from the receiver and switches.

  9. The BRAIN processes these signals based on its program.

  10. The BRAIN controls the motors and servos based on the program

  11. The parts of the BRAIN Switch 1 Switch 8 Ground Battery

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. Applause And now for the talented.. Gini Sue Crofford

  18. 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

  19. 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

  20. 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

  21. Let’s 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 <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); } } }

  23. /* 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.

  24. /* 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); } } }

  25. /* 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”.

  26. /* 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); } } }

  27. /* 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.

  28. /* 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); } } }

  29. /* 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.

  30. /* 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

  31. /* 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.

  32. /* 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!

  33. /* 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); } } }

  34. /* 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.

  35. /* 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.

  36. /* 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); } } }

  37. /* 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.

  38. /* 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.

  39. /* 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); } } }

  40. /* 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.

  41. /* 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 }.

  42. /* 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); } } }

  43. /* 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.

  44. /* 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 }.

  45. /* 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++; }

  46. /* 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++; }

  47. /* 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++; }

  48. /* 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++; }

  49. /* 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++; }

  50. /* 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++; }

More Related