Presentation is loading. Please wait.

Presentation is loading. Please wait.

ADVANCED BRAIN Training

Similar presentations


Presentation on theme: "ADVANCED BRAIN Training"— Presentation transcript:

1 ADVANCED BRAIN Training
Presented by: Matt Lapolla

2 Topics for this class Example Why program your BRAIN? Vocabulary
Useful References: BRAIN Software Rev 3.pdf IR Communications More functionality than just 4 channels Selection Stick State Machines Readjusting the driving joystick Debugging LED’s Serial Communication Example Topics for this class

3 Make Things Simpler for the driver and designers
Automate operations Use the BRAIN to its maximum potential Have better control of your robot Why program your BRAIN?

4 Why program your BRAIN Don’t Over complicate the controls
Your drivers have understand the controls Can’t put stickers, tape, etc on transmitter Why program your BRAIN

5 String vs. Number Integer Number Real Number Proportional Vocabulary

6 Vocabulary How you see the number 13 13
How the computer sees the number 13 1101 <- this is a number How the computer displays the number 13 Character(49) and Character(51) 1 and 3 13 <-this is a string of 2 characters Vocabulary

7 Integers : 1, 54, 742, 34532 Real : 1.233, .3532, Vocabulary

8 Vocabulary Proportional is the same as variable
Think of a dimmer switch in your house Non-Proportional is On or Off Think of a normal light switch in your house Vocabulary

9 IR Communications The IR transmitter (on your robot)
Is optional – But can help the points Sends commands to the game field Uses a modified servo port You will not be able to verify until mall day or game day. ALWAYS bring your most current program with you to mall day and game day! Laptop Thumb drive CD IR Communications

10 To use the IR transmitter you need to change the way the servo port operates.
The code looks like this: Declare Variables and Initialize our port unsigned short now; ... int main( void ){ InitBrain(); // initialize the BRAIN now=getClock(0); // Give 1/5 sec while(getClock(now)<10); // delay for CP setServoRange(0,180); //if 0 is IR port IR Communications

11 IR Communications Now we need to use our IR commands
Commands are numbers sent to our IR port Read the rules on page 21 To send the command 300 to the IR port setServo(0,300); // if 0 is our IR port To send the command 900 to the IR port setServo(0,900); // if 0 is our IR port IR Communications

12 More functionality than 4
More functionality than just 4 channels? More functionality than 4

13 The Transmitter has 4 proportional channels
Selection stick

14 Channel 0 Selection stick

15 Channel 1 Selection stick

16 Channel 2 Selection stick

17 Channel 3 Selection stick

18 So you should only be able to control 4 things with our transmitter.
Is it possible to control 5 things with proportional channels? Selection stick

19 YES Instead of using channel 2 as a proportional control of a motor or servo, we use it as a selection switch. It will select what the right joystick (channel 0 and 1) control. Selection stick

20 For example: If the left joystick is up, then the right joystick controls the drive motors
Selection stick

21 For example: If the left joystick is DOWN, then the right joystick controls the robotic arm
Selection stick

22 So now we have 5 proportional controls with only 4 channels
4 on the right stick (depending on the up/down position of the left stick) And one more: left stick side to side. A total of 5! Selection stick

23 Selection stick The code for this looks something like this:
if(getRcValue(2,DEADBAND,125)<512){ // Do this if the stick is in the Upper half }else{ // Do this if the stick is in the Lower half } Left Stick Up and down Selection stick

24 Selection stick If we use the entire left stick (channels 2 and 3) …
We can easily create 9 sensitive areas. Selection stick

25 Separate the left stick in to a 3x3 grid
Selection stick

26 The vertical and horizontal limits of the joystick are 0 to 1023
1023 1023 Selection stick

27 If we integer divide the vertical and horizontal limits of the joystick by 342 we will get a range of 0, 1, and 2 1 2 2 1 Selection stick

28 Now we combine the row and column into one number
Now we combine the row and column into one number. 00, 01, 02, 10, 11, 12, 20, 21 or 22 Row*10+Column 1 2 2 1 0 (00) 1 (01) 2 (02) 10 11 12 20 21 22 Selection stick

29 The code to make 9 sensitive areas looks like this:
Selection stick

30 //Get and determine Vertical cell of Left joystick
Row = getRcValue(2,8,125)/342; //determine Horizontal cell of left Joystick. Column = getRcValue(3,8,125)/342; Cell = Row*10 + Column; // Combine the cell // Determine what to do in each cell of the left joystick switch (Cell){ case 0: // Left Joystick in the Upper Left corner // Put your code here break; case 1: // Left Joystick in the Upper Center Corner case 2: // Left Joystick in the upper Right corner case 10: // Left Joystick in the Center Left case 11: // Left Joystick in the Center Center case 12: // Left Joystick in the Center Right case 20: // Left Joystick in the Lower Left case 21: // Left Joystick in the Lower Center case 22: // Left Joystick in the Lower Center }

31 With this arrangement we could have 18 proportional channels or…..
Selection stick

32 Any combination of Proportional channels and other functions…
Selection stick

33 State Machines What other functions? Non-proportional channels*
For Example: Open the hand*, close the hand* Open Hand Close Hand State Machines

34 State Machines What other functions? State Machines Close Hand then
Lower Arm Tip Bucket Etc... State Machines

35 State machines State Machines execute a series of actions
They can be time based Turn on Motor 0, wait 3 seconds Then, Set servo 3 to 800 and wait for 4 seconds Then... Or they can use some feed back (input) Turn on motor 0 until switch 1 is pushed Then turn on motor 1 until switch 2 is pushed State machines

36 A timed state machine code looks like this:
State machines

37 //To turn on your sequence:
Seq1 = 0; //Set the first sequence number DelaySeq1 = 0; //Enable the timer . //To turn off your sequence DelaySeq1 = 65535; //This is the highest clock value //See if time for next sequence if(getClock(LastClockSeq1) > DelaySeq1){ LastClockSeq1 = getClock(0); //Reset Timer for next sequence switch(Seq1){ //Choose next sequence case 0: // Put your code here DelaySeq1 = 150; // set delay 50 = 1 second Seq1 = 1; // Set Next Sequence to execute break; case 1: Seq1 = 2; // Set Next Sequence case 2: Seq1 = 3; // Set Next Sequence case 3: DelaySeq1 = 250; // set delay 50 = 1 second Seq1 = 4; // Set Next Sequence case 4: DelaySeq1 = DelayOff; // This stops the timer Seq1 = 0; // Reset Sequence Number }

38 A feedback state machine code looks like this:
State machines

39 // To turn on the state machine then…
// Start Sequence ArmSeq = 1;// Enable Sequence Seq2 = 0; // Pick an initial condition movement // To turn off the sequence ArmSeq = 0; // Stop Sequence //Check to see if the Arm Sequence is being used. If so then.... if (ArmSeq == 1){ // Check to see if at any limit switches. If so switch direction if(getSwitch(0)==1){ Seq2 = 0; } if(getSwitch(1)==1){ Seq2 = 1; // Select the direction based on Sequence switch(Seq2){ case 0: ArmMotor = 430; break; case 1: ArmMotor = 594;

40 Readjusting the drive joystick
When is forward not forward? When you don’t use your BRAIN Readjusting the drive joystick

41 Readjusting the drive joystick
Normally to drive forward you need the left motor and right motor at full power. Readjusting the drive joystick

42 Readjusting the drive joystick
But this is not very intuitive. There is a better way! Readjusting the drive joystick

43 Readjusting the drive joystick
By creating a simple function that you call, it will adjust your steering for you. You pass it the steer value (usually channel 0) And the Speed Value (usually channel 1) It will return to you the adjusted motor values for the right and left motors Readjusting the drive joystick

44 Readjusting the drive joystick
void remapDrive(unsigned int steerValue, unsigned int speedValue, unsigned int *rightMotor, unsigned int *leftMotor) { int xInput, yInput; // declare some signed integers int rightValue,leftValue; xInput=steerValue-RCIDLEVAL; // grab the input values yInput=speedValue-RCIDLEVAL; // and make into delta leftValue=yInput+xInput; // combine the input to create rightValue=yInput-xInput; // output delta values // bound the delta values (remember RCIDLEVAL is half RCMAXVAL) if (leftValue>RCIDLEVAL) leftValue=RCIDLEVAL; // becomes RCMAXVAL if (leftValue<-RCIDLEVAL) leftValue=-RCIDLEVAL; // becomes zero if (rightValue>RCIDLEVAL) rightValue=RCIDLEVAL; if (rightValue<-RCIDLEVAL) rightValue=-RCIDLEVAL; // output the values and include the idle offset *leftMotor=leftValue+RCIDLEVAL; *rightMotor=rightValue+RCIDLEVAL; } Readjusting the drive joystick

45 What happens when my program does not operate correctly?
Debugging

46 Debugging This is called Debugging.
The BRAIN has 2 useful debugging tools. The first are 8 LEDs that you can turn on with your program. I will use this to help me determine where the program is going. Debugging

47 Debugging Here is a sample code for turning LEDs on
setSingleLED(0); // Turn on 1st LED setSingleLED(1); // Turn on 2nd LED setSingleLED(2); // Turn on 3rd LED setSingleLED(3); // Turn on 4th LED setSingleLED(4); // Turn on 5th LED setSingleLED(5); // Turn on 6th LED setSingleLED(6); // Turn on 7th LED setSingleLED(7); // Turn on 8th LED writeLED(255); // Turn on all LEDs Debugging

48 Debugging Here is a sample code for turning LEDs off
clearSingleLED(0); //Turn off 1st LED clearSingleLED(1); //Turn off 2nd LED clearSingleLED(2); //Turn off 3rd LED clearSingleLED(3); //Turn off 4th LED clearSingleLED(4); //Turn off 5th LED clearSingleLED(5); //Turn off 6th LED clearSingleLED(6); //Turn off 7th LED clearSingleLED(7); //Turn off 8th LED writeLED(0); //Turn off all LEDs Debugging

49 Debugging: USB There is also a more advance debugging tool.
The BRAIN can display information on a PC. You simply build up a “string” that you want to send to the PC then call the outHostsz procedure. Debugging: USB

50 Debugging: USB // Declare 2 strings for your USB message
//buf1 is a temporary string for converting numbers char buf1[10]; // outbuf is string to be transmitted to the host PC char outbuf[70]; // max of 70 characters, or change num // just after the main while(1) loop // Clear out the display string before each loop outbuf[0] = '\0'; // To add a message with out variables strcat(outbuf,“My Message"); // Add words to message // To add a variable Cell to the message itoa(Cell,buf1); // Convert the var Cell to text strcat(outbuf,buf1); // Add new text to buffer Debugging: USB

51 //Lastly you need to send out your completed message
strcat(outbuf,"\r\n"); // add carriage return & line feed outHostsz(outbuf); // send outbuf to the USB port You will need a program on the PC to receive your message. Have IAR workbench installed on the PC (included on DVD) Use Realterm (included on your DVD) Settings: Display Tab ansi Port Tab BAUD is 9600 Port is (that varies from computer to computer, Try the largest number you have listed) OPEN button is pressed in Pins Tab DTR Press Clear Button RTS Press Clear Button Debugging: USB

52 Example Here is an example program that I came up with.
The program in its entirety will not be helpful to you, but some of the examples used may help you get started planning your own program. Example

53 The start to every program you need to decide what you want it to do.
So let me outline what my program does. The Right Joystick controls the drive motors Note: I don’t have any drive motors hooked up The Right Joystick controls the arm. The left joystick was separated in to 9 sensitive areas Example

54 I control the drive wheels
If the left stick is in the upper 3rd Then the right stick is used for drive wheels I control the drive wheels Example

55 Example If the left joystick is in the Center 3rd
Then the right joystick up and down, controls the arm I control the arm Example

56 I control the arm with parabolic_scale
If the left stick is in the Bottom 3rd Then the right up and down controls the arm with parabolic_scale I control the arm with parabolic_scale Example

57 Example If the stick is in the top right then…
Raise Red, Yellow, Green and Blue Flags Example of a switch Example

58 Example If the stick is in the top left then…
Lower Red, Yellow, Green and Blue Flags Example of a Switch Example

59 Example If the stick is in the center left then…
Start a timed state machine First raise the Red flag then wait 3 seconds Then raise the Yellow flag then wait 3 seconds Then raise the Green flag then wait 3 seconds Then raise the Blue flag then wait 5 seconds Then lower all flags Example of a timed state machine Example

60 Example If the stick is in the Lower Left then…
Slowly rotate arm until limit switch Change direction until limit switch Repeat Example of a State Machine with feedback Example

61 Example If the stick is in the Lower Right then…
Stop the arm State Machine Example

62 Look at the code Look at the code

63 QUESTIONS? What did we miss?


Download ppt "ADVANCED BRAIN Training"

Similar presentations


Ads by Google