code mplab ifi loader n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Code – Mplab – IFI loader PowerPoint Presentation
Download Presentation
Code – Mplab – IFI loader

Loading in 2 Seconds...

play fullscreen
1 / 23
heriberto-noboa

Code – Mplab – IFI loader - PowerPoint PPT Presentation

81 Views
Download Presentation
Code – Mplab – IFI loader
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. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Code – Mplab – IFI loader Nick and Kyle

  2. Background • Original C oriented • Designed to be lightweight yet robust • Very small subset of C

  3. Mplab • Available free from www.microchip.com • Default code editor for the TU Storm robots. • Supports all the language functions needed for both the TU Storm and Competition robots. • Default installation, everything you need (we hope)

  4. Screenshots

  5. How to code Various places to put things. Constants go at the top. • int Speed = 10; • int LftBWThreshold = 1000; Intilization • Done once only, and never again. • For the FIRST competition robots, we put the camera startup code in here.

  6. Two other code places • Autonomous code • Code that words only when the autonomous code is enabled. No user input. • Default_Routine() • The entirety of the robot code for the TUStorm robots, appears here. In competition robots, all code that’s done via the user > joystick/buttons > controller > robot and back goes here. Run once a program cycle

  7. Every program loop! • The execution of User_Routines is done once a program cycle (19 ms) All code has to complete in that cycle (difficult to make it not do so, but can be done) • Restarts at the top of user routines and executes it again, every cycle.

  8. What weapons do you have? • Remember very VERY basic version of C if ( this = that ) { do this } else { do this } switch(int) case 0: { do this } case 1: { do this } default: { do this }

  9. More weapons • printf(“some text”); • printf(“some more text\n”); • Printf(“even more text”); some textsome more text even more text • int x = 0; int y = 1; int z = 3; • printf(“data %d %d %d\n”, x, y, z) data 1 2 3

  10. How to make this int turn that wheel • At the top, in the constants, you define what all your pwms do. • RightMotor pwm07; • LeftMotor pwm08; to use in your default routines. int RightMotor = 127; (idle) int RightMotor = 150; (forward) int RightMotor = 80; (reverse) Reversed for the left motor.

  11. All defined constants • // Arm • #define Wrist pwm01 • #define Elbow pwm02 • #define Shoulder pwm03 • // Pan/Tilt • #define Pan pwm05 • #define Tilt pwm06 • // Drive • #define RightMotor pwm07 • #define LeftMotor pwm08 • // Digital Inputs • #define TopSw !rc_dig_in06 • #define MidSw !rc_dig_in07 • #define BotSw !rc_dig_in08 • #define Banner rc_dig_in09 • Adjust = (int)(Get_Analog_Value(rc_ana_in05)) / 4; Contols the Wrist, Elbow and Shoulder of the robot arm Pan and Tilt of the Camera Left and Right drive motors Three switches on the site, and the banner sensor underneath Adjust – converts the knob into an int based signal.

  12. So now that we have that? • So what cant you do? No while loops, no for loops, no do/while loops. Basically you have: • If, else, case • ints, floats • And that’s it • You can write your own functions, for reusability.

  13. if ((TopSw == ON) && (MidSw == ON) && (BotSw == ON)) { //#8 //Puts the robot back into stable position printf("Running Program #8, return robot to stable position\n" ); RightMotor = RightIdle; LeftMotor = LeftIdle; Wrist = WristIdle; Shoulder = ShoulderIdle; Elbow = ElbowIdle; Pan = PanIdle; Tilt = TiltIdle; Flag = 0; }

  14. That’s not very complicated • Really, from those basic commands you make the entire rest of the robot work. • How do I make the robot do something for so long then stop? • Declare a counter at the top. int couter = 0; • Then. If ( counter >= (somenumber) ) { do this } else { counter++; }

  15. Nesting • Nest to infinity (well the max limit of your robots controller) • if ( this ) { do this } • else if { do this } • else { do this } or even uglier • if ( this ) { if (this) { do this } else { do this! } • else { do this }

  16. What accessories do I have? • Two black/white sensors • Wall follower (distance sensors) • Banner Sensor • Right and Left Drive motors • 3 Toggle switches • 1 Adjust knob • One Arm (wrist, elbow, shoulder) • 1 Camera • Pan and Tilt on Camera • Two direction/distance counters

  17. Now for some quirks • Robot power != constant. • A robot at full charge, will read certain values • A robot at half charge, will read those same things as different values • Solution fresh charge on all cases. • His robot works differently than mine • They are all made the same, but all have slightly different constants. Your constants for your robot are not the same as they would be on another robot.

  18. Morale of the story • All hardcoded constants = bad RightMotor = 128; • A better solution (recommendation) int rightidle = 128; (at the top) RightMotor = rightidle; (in your code) That way, if it drifts, you change one constant instead of several.

  19. A sample if ((TopSw == ON) && (MidSw == OFF) && (BotSw == ON)) { printf("Running Program #6, wall following program\n" ); //if (DistL > LLeftDstThreshold) { //RightMotor = RightIdle - 20; //LeftMotor = LeftIdle - 20; //} //else if (DistF > FrontDstThreshold) { printf("DistF is Greater than Front Threashold\n" ); RightMotor = RightIdle - 15; LeftMotor = LeftIdle - 15; } else if (DistL < LLeftDstThreshold) { printf("DistL is Less than Lower Threashold\n" ); RightMotor = RightIdle + 15; LeftMotor = LeftIdle + 15; } else if (DistL > ULeftDstThreshold) { printf("DistL is Greater than Upper Threashold\n" ); RightMotor = RightIdle - 15; LeftMotor = LeftIdle - 15; } else { printf("DistL is within toleration\tDistF is below threashold\n" ); RightMotor = RightIdle + 15; LeftMotor = LeftIdle - 15; } }

  20. IFI - Loader

  21. Safety • Just a few reminders, these robots can break • Whenever moving a motor too a new position, slamming the motor full throttle can damage it • Example: Wrist = 127; (default) • Wrist = 255; A better way to do that, is to increase the wrist gradually over time. Use a counter, do it over a series of loops

  22. Questions? • http://kevin.org/frc/ • http://www.usfirst.org/robotics/C_help.htm • http://www.ifirobotics.com/docs/oi-ref-guide-11-21-05.pdf • http://www.ifirobotics.com/edu-rc.shtml