Presentation is loading. Please wait.

Presentation is loading. Please wait.

Code – Mplab – IFI loader Nick and Kyle. Background Original C oriented Designed to be lightweight yet robust Very small subset of C.

Similar presentations


Presentation on theme: "Code – Mplab – IFI loader Nick and Kyle. Background Original C oriented Designed to be lightweight yet robust Very small subset of C."— 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 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 Default installation, everything you need (we hope) (we hope)

4 Screenshots

5

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

7 Two other code places Autonomous code Code that words only when the autonomous code is enabled. No user input. 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 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

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

9 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 } case 1: { do this } default: { do this } default: { do this }

10 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

11 How to make this int turn that wheel At the top, in the constants, you define what all your pwms do. RightMotor pwm07; RightMotor pwm07; LeftMotor pwm08; 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.

12 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_in0 5)) / 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.

13 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 If, else, case ints, floats ints, floats And that’s it And that’s it You can write your own functions, for reusability. You can write your own functions, for reusability.

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

15 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++; }

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

17 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

18 Now for some quirks Robot power != constant. A robot at full charge, will read certain values A robot at full charge, will read certain values A robot at half charge, will read those same things as different values A robot at half charge, will read those same things as different values Solution fresh charge on all cases. 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. 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.

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

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

21 IFI - Loader

22 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 Whenever moving a motor too a new position, slamming the motor full throttle can damage it Example: Wrist = 127; (default) Wrist = 255; 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

23 Questions? guide pdf


Download ppt "Code – Mplab – IFI loader Nick and Kyle. Background Original C oriented Designed to be lightweight yet robust Very small subset of C."

Similar presentations


Ads by Google