Programming and Controls Workshop – The Basics - PowerPoint PPT Presentation

programming and controls workshop the basics n.
Skip this Video
Loading SlideShow in 5 Seconds..
Programming and Controls Workshop – The Basics PowerPoint Presentation
Download Presentation
Programming and Controls Workshop – The Basics

play fullscreen
1 / 61
Programming and Controls Workshop – The Basics
Download Presentation
Download Presentation

Programming and Controls Workshop – The Basics

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

  1. Programming and Controls Workshop – The Basics Tom Barch

  2. Agenda • System Overview • How the systems works – Controls Block Diagram • Robot Controller • Operator Interface • Controls • Overview of the controls used and how they work • Programming • Default Code Reference Guide – How an why to use • MPLAB and IFI Loader – How to install and use • Default Code – An overview • Downloading the Code to the Robot Controller • Pneumatic Controls • Overview of the pneumatics system – Block Diagram • Controlling the pneumatics – Understanding the controls • Hands On Demonstration • How to download and test using a real system

  3. Robot Controller or RC

  4. Operator Interface or OI

  5. Tether Communications

  6. Radio vs. Tether communication • If the controllers ‘see’ a tether cable connection, then they will communicate via the tether port. • If no tether connection exists, then they will attempt to use the radio signal. • Note: Connecting via radio at the competition other than during a match is not allowed and can be dangerous if another teams operator interface controls your robot.

  7. Controls • Understanding the controls will help to understand the software variables and how the software is modifying and outputting them to get the Robot to move. • The joystick is read by the Operator Interface and is transmitted to the Robot Controller. It usually drives a pwm output which controls a Victor 883 or 884 speed controller. The speed controller maybe wired to a drill motor. • By pressing the joystick, we hope to control the speed and direction of the motor to get the Robot to move. • Lets start with the Joystick.

  8. Joystick • The joystick consists of two potentiometers mounted to a stick that vary as the stick is moved along its axis. • One potentiometer is mounted in the x axis or left – right direction and the other is mounted in the y axis or forward – backward direction. • As the potentiometer moves from one extreme to the other, the operator interface reads the voltage from 0 to 5 volts. • This voltage is broken into an 8 byte variable that ranges from 0 (0 volts) to 254 (5 volts). • The variables in the software for the input ports on the OI are pX_axis where x is port 1 to 4 and the axis is x, y, or wheel. (example p1_y is port one, y axis or forward/backward)

  9. Joystick - continued • Full forward in the y axis will result in p1_y = 254. • When the joystick is in the center, p1_y = 127. • Full backward p1_y = 0.

  10. Victor Speed Controller • The input to the speed controller is a pulse width modulated (pwm) signal that varies from a value of 0 to 254. • In the software, these variables are labeled pwm01 – pwm16 corresponding to the pwm input on the RC. • Battery and ground is supplied to two input terminals and the two output terminals can be wired to an electrical load like a drill motor. • At an input of 127, the two outputs which we will call m+ and m- are at 0 volt difference • As the pwm increases from 127 toward 254, the voltage varies from a positive difference of 0 to 12 volts. • As the pwm decreases from 127 towards 0, the voltage varies from a negative difference of 0 to 12 volts.

  11. Victor 883 or 884 speed controller

  12. Joystick to Motor • The joystick variable is the same as the variable outputted to the pwm output to drive the motors forward and reverse. • In the default software, port one y axis is output directly to pwm01 port: pwm01 = p1_y; • In the default software, port two y axis is output directly to pwm02 port: pwm02 = p2_y; • The two of these make up the tank drive (two joystick). • The software also outputs joystick one x and y axis to pwm ports 13 and 15 to get one joystick drive.

  13. Joystick Switches • Located on the joysticks are four switches that are read by the computer as 0 or a 1. When the switch is closed, then the variable is read as a one. • These switch inputs for each one of the four input ports on the OI are: p1_sw_trig p1_sw_top p1_sw_aux1 p1_sw_aux2

  14. Spike Controller • The spike controller is a relay or electronic switch that will drive two outputs based on the inputs. • The reason for two input and two outputs are to enable the output to be driven positively or negatively to drive a small motor forward or reverse. • When the inputs to the relay are driven both as 0, then the outputs are both at 0 volts. One input is called Fwd and one is called Rev. One output is m+ the other is m-. • If the Fwd input is a 1 and the Rev input is a zero, then the m+ output will be 12volts and the m- output will be 0 volts. • The spike can be used to drive small motors, lights, air compressor, or any other 12 volt electrical load. The concern is the current draw which is much lower then the speed controllers.

  15. Spike Blue Controller

  16. Spike Truth Table • The truth table for the input to output is as follows:

  17. Spike alternative circuit • The spike can also be used to drive two different outputs in a on/off sequence. • An example would be two solenoid valves.

  18. Programming the Robot Controller

  19. Robot Controller Code • MPLAB IDE v7.20 is the C programming editor and complier from Microchips used to edit and compile the code. • IFI Loader is a program that will download the complied code into the robot. • None of this is necessary if the default code is used. • If modifications are necessary (custom functions are needed/variables need to change slightly), the code will only need modifications instead of a complete re-write.

  20. Default Code Reference Guide • Available from Innovation First website (in the Robot Controller section at the bottom) • Shows OI wiring/variables to RC variables/output for the default code functions. • Contains the variable listing for modification of default code. FRC 2004 Default Code Reference Guide.pdf

  21. Table of Contents

  22. Joystick Function RC PWM1 is the port that the left side victor should be plugged into to make port 1 the left joystick for tank style drive Joystick plugged into port 1 Y-Axis is forward – backwards (tank drive) P1_y is the variable used in the software to read this function

  23. Single Joystick Drive • Missing from default guide – It is on the front cover but hard to read. • Connect the right drive motors to PWM13 and/or PWM14 on the RC. • Connect the left drive motors to PWM15 and/or PWM16 on the RC.

  24. MPLAB Install • Adobe PDF document exists on CD • Has the defaults and instructions for installing MPLAB as well as the IFI loader. • C-BOT_Install_1-29-2004.pdf

  25. MPLAB and Default code • After downloading the default code, place the unzipped files in a directory, preferable in c:\code\frccode. • MPLAB and First recommends a simple directory. My Documents is a complex directory in Windows 2000 and Windows XP. • Saving an old revision and creating a new one is done by copying the folder and pasting to new director (i.e. copy c:\code\frccode into a new directory c:\code\frccode1 and so on).

  26. Opening the default workspace • Do not use the file open command. Use the open workspace command.

  27. User_routine.c • Most of the code changes will be made in the user_routine.c file • Custom code should be placed in Process_Data_From_Master_uP function at /* Add your own code here */. • The specific functions for most of the inputs/outputs are in the Default_Routine which is at the bottom of User_routine.c • The variables can be modified in the default routine, but make sure to use new revision (directory) here so that changes can be reversed.

  28. C Programming • C is a popular powerful language that requires conciseness with a wealth of operators. • Teaching C in a one hour workshop would be impossible. • The next few slides are intended to help understand some of the C language basics in order to make minor modifications to the default program.

  29. C Language Basics • C is a compiled language. • The C compiler is a program that reads source code, which is the C code written by a programmer, and produces an executable or binary file that in a format that can be read and executed (run) by a computer. • The source file’s are a plain text file containing the text version of the code written in correct syntax for the C complier. • The executable file consists of machine code, 1's and 0's that are not meant to be understood or read by people, but only by computers. This is the file that gets downloaded into the RC. • The compiler will make the executable file from the source code and check for syntax errors. The complier does not check for logic errors. • The best way to learn anything is to jump right in, so let's start by looking a simple C program.

  30. C Program Structure

  31. Code Comments • Comments in C are done in one of two ways: • /* Comments are placed between text markers and can span multiple lines of text*/ • // Comments on one line only • Most C programmers use the comment markers /* text */ • Text should be green if the right markers are used in MPLAB.

  32. Relational Operators • You may have noticed the == sign used in the if statement. Unlike most other programming languages, the = is an assignment operator. The double == is the equality operator. == equal operator 5 == 4 FALSE or 5 == 5 TRUE != not equal 5 != 4 True or 5 != 5 FALSE > greater than 5 > 4 TRUE or 5 > 5 FALSE >= greater than or equal 5 >= 4 TRUE or 5 >= 5 TRUE < less than 5 < 4 FALSE or 5 < 5 FALSE <= less than or equal 5 <= 4 FALSE or 5 <= 5 TRUE

  33. End of line markers • Some of the code is ended with the semicolon ; pwm01 = p1_y; • Braces mark the beginning as well as the end of the body of a function. If (p1_y == 127) { p1_x = 127; }

  34. Variables in C • Valid names can consist of letters, numbers and the underscore, but may not start with a number. A variable name may not be a C keyword such as if, for, else, or while. Variable names are case sensitive. So, Age, AGE, aGE and AgE could be names for different variables, although this is not recommended since it would probably cause confusion and errors in your programs.

  35. Declaring Variables • Variables are usually declared at the top of the module or in a separate “header” file which usually ends with .h file type. • In the space before the variable or function being declared, is the data type the variable or function will return. • A variable can be assigned a value in the declaration statement. • C provides built in data types for character, float and integer data. A mechanism, using the keyword typedef, exists for creating user-defined types.

  36. Data type - Integer • Integer variables are used to store whole numbers. • There are several keywords used to declare integer variables, including int, short, long, unsigned short, unsigned long. The difference deals with the number of bytes used to store the variable in memory, long vs. short, or whether negative and positive numbers may be stored, signed vs. unsigned. • Examples: int count; int number_of_students = 30;

  37. Data types – floating decimal point • Float variables are used to store floating point numbers. • Floating point numbers may contain both a whole and fractional part, for example, 52.7 or 3.33333333. • There are several keywords used to declare floating point numbers in C including float, double and long double. The difference here is the number of bytes used to store the variable in memory. Double allows larger values than float. Long double allows even larger values. • Examples: float pwm23_new = 0.0; double pwm23_new2 = 1234567.89;

  38. Data types - Character • Character variables are used to store character values. • Character type is actually an integer value that stores the ASCII integer value • Char is often used as a 8 bit integer value. • Examples: char firstInitial = 'J'; /* stored as 74 */ char secondInitial = 'K';